Repository navigation
fix(codex): read the CLI update job ledger again when a concurrent write replaced it - #8712
Conversation
…ite replaced it The POSIX job ledger is replaced atomically (private temp file renamed over jobs.json) and readers take no lock. A rename landing after a reader opened the file unlinks the file it holds (nlink 0) and makes the path name a newer inode, and both were refused as unsafe_store. The management status route then answered 503 job_state_unavailable for a healthy job, which is how dev batch 43496185962 failed test 1/5: a restarted management server read an old owner's job while the owner recorded it as running. A read now starts over when the file it opened was replaced, up to five attempts; every attempt applies all checks, a hard-linked or symlinked store is still refused at once, and a store still being replaced at the last attempt is refused as before. Two processes on macOS: 2,575 of 28,104 reads failed under ~10k replacements/s before, 0 of 27,125 after. The new regression test failed with 45-75 refusals per second before and passed 20 of 20 runs after.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
✅ Deterministic PR hygiene checks passed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 29c37c0b40
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| const bytes = Buffer.alloc(CODEX_CLI_JOB_STORE_MAX_BYTES + 1); | ||
| const length = readSync(fd, bytes, 0, bytes.length, 0); |
There was a problem hiding this comment.
Update the owning architecture document for ledger read retries
This changes the POSIX ledger's acceptance behavior for replaced files, but the commit does not update structure/codex-cli-update.md, which structure/INDEX.md explicitly identifies as the owner of src/codex/cli-update-job.ts. src/AGENTS.md requires the owning documentation to be updated in the same change. Document the lock-free reader's five-attempt replacement retry, immediate refusal of unsafe files, and refusal on exhaustion so the maintained ledger contract includes this new distinction.
AGENTS.md reference: src/AGENTS.md:L11-L11
Useful? React with 👍 / 👎.
… a racing writer Review of #8712: the regression test raced a writer process against reads, so it could pass without a collision and fail on the bounded refusal the fix keeps. readStore now calls a test hook after the open and after the descriptor checks, and the test replaces the ledger at exactly those points: once (read again and succeed, two attempts), on every attempt (refused after five), and a hard-linked ledger (refused after one). With the attempt bound set back to one, which is the previous behaviour, the first three fail and the hard-link case still passes.
|
Maintainer judgment: integrating into Exact head b2401d2:
Store-safety change reviewed with the security lens in both rounds: symlink, hard-link, mode, uid and size checks unchanged and immediate; retries bounded. No outstanding maintainer change requests. |
Summary
test 1/5 of dev batch 43496185962 (Linux, self-hosted) failed
tests/codex-integration/codex-cli-update-apply.test.ts"published Node launcher -> isolated management plan, lost-response apply retry, and CLI status" with "management API treated an unowned running record as stopped". The case starts an old owner's job in the test process without awaiting it and immediately asks the separate management server for its status; the expected answer isownerState: unknown. The message also covers a non-OK response, and that is what happened here.The POSIX job ledger (
src/codex/cli-update-job.ts) is rewritten atomically (a private temp file renamed overjobs.json) while readers take no lock.readStoreopens the file, checks it, then checks that the path still names that file. A rename landing in between unlinks the file the reader holds (nlink0) and makes the path name a newer inode; both were refused asunsafe_store, soGET /api/codex/cli-update/jobs/:idanswered 503job_state_unavailablefor a healthy job. In this test the owner's ownrunningtransition is the concurrent write. The same race reaches the dashboard andocx system codex-cli-update statuswhenever they read during a job transition.A read now starts over when the file it opened was replaced, for at most five attempts. Each attempt applies every existing check; a hard-linked (
nlink > 1) or symlinked store is still refused immediately, and a store still being replaced at the last attempt is refused as before. The Windows ledger is a separate store and is unchanged.Verdict on the batch failure: a product race, timing-dependent but not a test flake. No commit between the last batch where this case passed and this one touched the job ledger.
Verification
jobs.jsonin a loop, a reader callingreadCodexCliUpdateJob): with no writer, 13,463 of 13,463 reads succeeded. With ~10k replacements/s, 2,575 of 28,104 reads failed withunsafe_storebefore the fix and 0 of 27,125 failed after it.tests/codex-integration/codex-cli-update-job-read-race.test.ts(POSIX store only) uses a test hook thatreadStorecalls after the open and after the descriptor checks, and replaces the ledger at exactly those points: replaced once at either point, the read starts over and returns the job (two attempts); replaced during every attempt, it is refused after five; a hard-linked ledger is refused after one. With the attempt bound set back to one (the previous behaviour) the first three cases fail and the hard-link case still passes. (A first version raced a writer process; review pointed out it could pass without a collision, so it was replaced.)bun run typecheck: exit 0. Layout guards: 29 pass / 0 fail.bun run privacy:scanandbun run structure:check: passed.codex-cli-update-apply.test.tsand threecodex-cli-update-plan.test.tscases fail on this machine on unchangedorigin/devas well (they need a real Node/npm toolchain that this host's node shim does not provide). Their result here comes from this PR's Ubuntu CI.Checklist
Summary by CodeRabbit