You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Verify auth-store write atomicity under per-request room grant reload (Low) #538
Since #536, every room-session use re-reads and parses the auth state: validate_session_authority → RoomSessionAuthorization::validate → load_active_session_grant (room_service.rs / auth.rs). Grant mutation goes through store_session_grant / renew_session_grant / revoke_session_grant.
If grant writes are not atomic (temp file + rename), a poll racing a concurrent grant write can read a partial state. The fail-closed mapping then rejects the request and logs the person out spuriously.
Not yet verified whether the auth.rs grant writes are atomic.
Fix
Confirm (or make) grant writes atomic.
If needed, add a short-TTL read cache keyed by session_id that is invalidated on revoke; a cache must not delay revocation beyond a bounded, seconds-scale window.
Done means
A test asserts a read during a concurrent grant write never yields an unparseable state.
If a cache is added, revocation still takes effect within a bounded window (seconds, not minutes).
Verified on develop 30b166b (Cursor lane, Grok 4.7; report /private/tmp/cursor-runs/check-538.report.md). No product fault reproduced.
Every grant writer (store, renew, revoke) goes through mutate_auth_state (process mutex plus auth-state.json.lock) and save_auth_state → write_secret_bytes_atomic: new temp file (create_new, 0600), full write, fsync, same-directory rename, parent directory fsync (auth.rs:4669-4690, 4641-4644). The destination is never truncated in place.
The per-request reader (RoomSessionAuthorization::validate → load_active_session_grant) reads whole files only, detects an inode change during the read and retries (auth.rs:441-467, 4703-4713), and its cache is keyed by the content hash and dropped before and after each save (auth.rs:527-540, 4858, 4865). A missing file is "session not found"; a revoked session is "not active"; both grant no room access.
A concurrent test (4 reader threads on load_active_session_grant, a writer renewing, revoking and storing again, 100 loads inside each published phase) finished 14,222 loads: 204 stable loads saw the active grant, 100 saw the revoked session, zero parse errors, zero foreign session ids, zero active grants after revoke. Full cargo test -p elastos-server --tests, behaviour suite and source gate pass with it.
The test (branch fix/538-auth-store-atomicity, 4d3de4234, local) fails if a write becomes in-place, if the cache stops checking content, or if a reload returns a grant after revoke. It goes to a cross-family review before the queue; if the review finds it timing-sensitive it will be dropped and this issue closed on the evidence above.
Closing on the evidence in my previous comment: writes are atomic (temp, fsync, rename), the reader detects a concurrent change and its cache is keyed by content, and a revoked or missing grant gives no room access. The 240-line concurrent test is dropped: a cross-family review (Codex, GPT) found a scheduling flaw that can fail correct code (readers can finish their quota before the writer runs), unbounded waits, and that the existing room_session_bound_checks_all_use_paths (room_service.rs) already proves the user-visible behaviour, revocation through room reads, writes and attachments. No product change.
Activity
andersalm commentedon Nov 8, 2026
Verified on develop 30b166b (Cursor lane, Grok 4.7; report /private/tmp/cursor-runs/check-538.report.md). No product fault reproduced.
mutate_auth_state(process mutex plusauth-state.json.lock) andsave_auth_state→write_secret_bytes_atomic: new temp file (create_new, 0600), full write, fsync, same-directory rename, parent directory fsync (auth.rs:4669-4690,4641-4644). The destination is never truncated in place.RoomSessionAuthorization::validate→load_active_session_grant) reads whole files only, detects an inode change during the read and retries (auth.rs:441-467,4703-4713), and its cache is keyed by the content hash and dropped before and after each save (auth.rs:527-540,4858,4865). A missing file is "session not found"; a revoked session is "not active"; both grant no room access.load_active_session_grant, a writer renewing, revoking and storing again, 100 loads inside each published phase) finished 14,222 loads: 204 stable loads saw the active grant, 100 saw the revoked session, zero parse errors, zero foreign session ids, zero active grants after revoke. Fullcargo test -p elastos-server --tests, behaviour suite and source gate pass with it.The test (branch fix/538-auth-store-atomicity, 4d3de4234, local) fails if a write becomes in-place, if the cache stops checking content, or if a reload returns a grant after revoke. It goes to a cross-family review before the queue; if the review finds it timing-sensitive it will be dropped and this issue closed on the evidence above.
andersalm commentedon Nov 8, 2026
Closing on the evidence in my previous comment: writes are atomic (temp, fsync, rename), the reader detects a concurrent change and its cache is keyed by content, and a revoked or missing grant gives no room access. The 240-line concurrent test is dropped: a cross-family review (Codex, GPT) found a scheduling flaw that can fail correct code (readers can finish their quota before the writer runs), unbounded waits, and that the existing
room_session_bound_checks_all_use_paths(room_service.rs) already proves the user-visible behaviour, revocation through room reads, writes and attachments. No product change.