Repository navigation
fix(session-tracking): lock shared sessions.json read-modify-write - #506
Open
codeaholicguy wants to merge 2 commits into
Open
codeaholicguy wants to merge 2 commits into
codeaholicguy wants to merge 2 commits into
Conversation
…ocesses Serialize Pi and Codex writers with an O_EXCL lockfile (stale reclaim), use temp+rename for Codex, and skip writes when JSON parse fails so concurrent hooks cannot clobber live pid entries.
…timeout Quarantine unreadable registry files under the lock, warn, and continue from an empty map. On lock wait timeout, log, skip one update, and never throw (Codex exits 0). Keep cli Codex asset identical to hooks/codex. Co-authored-by: Hoang Nguyen <codeaholicguy@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #494
Root cause
TLC on
feature-tla-analysisviolatedInv_NoLostSessionsJsonEntryat depth 7. The Pi extension and the Codex SessionStart hook both did unlocked read-modify-write on onesessions.json. Two processes in the same window could drop each other's pid row. Codex was worse: in-placewriteFileSyncplus treating parse errors as{}could wipe every other live pid when another hook was mid-write.Fix
Pi logic lives in
packages/pi-session-tracker/extensions/session-registry.tsand drives the extension handlers. Codex uses the same rules inlined inhooks/codex/codex-session-mapping.cjs.packages/cli/assets/codex/codex-session-mapping.cjsis kept byte-identical to that hooks file (copy on change; we can add a CI diff later if we want).Both paths now:
O_EXCLlockfile (sessions.json.lock, 30s stale reclaim, same idea as devkitd autostart).sessions.json.corrupt-<timestamp>,console.warn, continue from{}.No overlap with open PR #489 (
rust/crates/devkitd/src/durable.rs) or #481 (server.rsagent lookup / unregister).Test plan
Regression: concurrent Pi workers and parallel Codex hook subprocesses; corrupt JSON quarantine plus fresh write; lock held so timeout skips without writing (
AI_DEVKIT_SESSION_REGISTRY_LOCK_WAIT_MS=100in tests).Risks
Under heavy contention a single start or shutdown may wait up to 10s before giving up that one update. A crashed lock holder is reclaimed after 30s. Quarantine drops unreadable bytes on disk (backed up as
sessions.json.corrupt-*).Behavior changes
sessions.json.sessions.jsonis quarantined and replaced with a fresh map that includes the current pid, instead of staying broken forever.Skills / friction
Skills: AGENTS.md test layout, TDD (concurrent and corrupt regressions), humanizer on this description.
Friction: pre-commit
oxfmt; hook subprocess tests need the correct relative path to the CLI asset; first draft forgotmkdirbefore lock create on empty registry dirs; cloud VMgit pushover https failed with no credentials.