Skip to content

test(codex-process-lock-store): wait for the lock holder's whole reply lines - #3901

Merged
devswha merged 1 commit into
mainfrom
test/codex-process-lock-store-ready-after-lock
Nov 15, 2026
Merged

devswha merged 1 commit into
mainfrom
test/codex-process-lock-store-ready-after-lock

Conversation

@devswha

@devswha devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Summary

server/codex-process-lock-store.test.ts failed in Fast checks on a GitHub-hosted runner: run 43717080636, job 132820955312 (PR #3738 at 81d4d3f). The failing test was "resolves a resumed project rollout with its exclusive writer lock and no database", at line 89. It expects null after the child released its lock but got the project store, and the test took 33 ms. Nothing else in the file failed.

The lock holder is python3 -u. With unbuffered stdout, print('ready', flush=True) is two writes: write(1, "ready"), then write(1, "\n") (seen with strace). The test waited with reader.read(), which resolves with whatever one pipe read returns, not one line. When a read ended between "ready" and its newline, the read meant to wait for the reply to unlock returned the stale newline at once. The lookup then ran while the child still held its exclusive lock. The child already locks before it says ready, so the fixture's order was right. The test was reading partial replies. The product is not at fault: flock(LOCK_UN) drops the lock: line from /proc/<pid>/fdinfo before it returns.

The test now reads each reply as a whole line and checks it is the word the child sends (ready, done). It reads the same way firstLine in codex-processes.test.ts does, and an early exit fails with what the child wrote. What the test proves is unchanged, with no sleeps; the test's own timeout bounds the wait.

Validation

Forcing (scratch, not committed): in the child script, print('ready', flush=True) is replaced with its two writes and a 0.3 s pause between and after them (sys.stdout.write('ready'); time.sleep(0.3); sys.stdout.write('\\n'); time.sleep(0.3)). That holds open the gap a slow runner leaves between the two writes.

  • On unmodified main (139759a), the test fails the same way as the hosted run: codex-process-lock-store.test.ts:89, expect(received).toBeNull(), received the project .codex store.
  • Splitting every reply that way (ready and both dones, 0.3 s between word and newline), main fails at line 94, the mirror case: after lock, the lookup ran on the stale done before the child relocked and got null.
  • With this change, the file passes under both forcings: 10 pass, 0 fail each.
  • A real fault still fails: with openProcessCodexHome counting an open writer-lock file as held (scratch mutation, reverted), the test fails at line 89 and the unlocked and shared cases fail at line 82.

Unforced:

  • bun test --rerun-each 20 ./server/codex-process-lock-store.test.ts: 200 pass, 0 fail.
  • bun run check fast passes.

Skipped: Integration and browser, Native Windows install, macOS (no product code or other test changed). No changelog fragment, because the change is test-only.

…y lines

The lock holder is python3 -u, whose print writes a word and its newline as two
writes. The test took any pipe chunk as the next reply, so a read that ended
between "ready" and its newline let the following read return the stale newline
before the child had handled "unlock": the lookup then still saw the exclusive
lock (hosted Fast checks, run 43717080636, line 89). Each reply is now read as a
whole line and checked to be the word the child sends from the state it promises.
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Automated checks now wait for complete process responses before validating lock and unlock behavior, improving the reliability of these checks when responses arrive in multiple parts. This change affects internal validation only; no end-user-visible behavior is reported.

The lock-store test now reads complete newline-delimited replies from the child process. A buffered line reader retains data after the first newline and throws if the process exits before completing a line.

Changes: Lock-store reply handling

Layer / File(s) Summary
Buffer and read complete replies
server/codex-process-lock-store.test.ts
The test adds a buffered line reader and uses it to read the complete ready and done replies during the lock and unlock checks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: rocking5566

Merge Risk: Minimal · up to 9c28d

This change only makes a lock-store test more reliable by waiting for complete replies from the child process. It has no production impact, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the test file and the specific change: the test now waits for the lock holder's whole reply lines. It matches the summary, which describes a buffered lineReader that reads complete new…
Description check Passed The description follows the template's two sections. The Change section explains the problem: the test read partial pipe replies, and a stale newline let a lookup run while the child still held its lo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the test file and the specific change: the test now waits for the lock holder's whole reply lines. It matches the summary, which describes a buffered lineReader that reads complete newline-delimited replies. The title is specific and accurate.

Full details: Description check

Explanation

The description follows the template's two sections. The Change section explains the problem: the test read partial pipe replies, and a stale newline let a lookup run while the child still held its lock. It also states the resulting behavior. The Validation section lists the commands run (bun test --rerun-each 20, bun run check fast), the forced partial-write scenarios, and the skipped checks. It does not link an issue, but the template only asks for one for features, and this change is a test-only fix. The description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 139759a and 9c28d10.

Files selected for processing: 1

  • server/codex-process-lock-store.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@devswha
devswha merged commit 95154c2 into main Nov 15, 2026
24 checks passed
@devswha
devswha deleted the test/codex-process-lock-store-ready-after-lock branch November 15, 2026 14:08
@devswha

devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 9c28d103e203 as 95154c2e4238 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR

One reviewer: test-only.

Test-only, one file. The failure it fixes was reproduced before merging: with the child's word and its newline forced 0.3 s apart, main's test fails 8 of 8 at the relock check (and 3 of 3 at the post-unlock check under a second forcing); this head passes both. Unforced, the file passed 30 of 30 in one loop. The test still fails on a real fault (ignoring a held lock, dropping lock discovery).

Left open, not blocking (LOW): when the child dies early the error does not include its stderr.

Review reports: ~/.cache/ovis-tmp/reports/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant