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
test(codex): wait for the late-failure read instead of one event-loop turn - #4803
Fixes the flaky server/core/codex-status-hub.test.ts test "still finds a late failure after the
rollout tail contains no turn markers (#3760)" that failed the 0.5.10 Release run's
"Fast checks (GitHub-hosted)" job (run 45782602477: Expected number of calls: 3, Received: 2).
The product is fine: the snapshot that follows the late error does start the third rollout read,
but codexRest begins that read only after stat() of the rollout returns from the thread pool.
The test counted reads after settled(), which waits for one setImmediate; on a slow 2-core
runner the stat has often not returned by then. The test now awaits the read itself
(h.looked()) before counting, with a bounded 2 s timeout like its neighbours. h.looked() itself now fails after 1.5 s, before
the test's own timeout, so a missing read fails the test with its finally run and the file's spies restored.
Test-only change: no changelog fragment.
Validation
Reproduced on this PC with the test pinned to 2 CPUs (taskset -c 2,3) under 4 busy loops on
the same CPUs: 20 of 30 runs failed with Received number of calls: 2 on origin/main.
Same conditions with this change: 50 of 50 runs of the whole file passed (0 failures).
bun run check fast: green at 950c2bc (28807 unit pass, 0 fail). Re-run green at 3efac03 (28807 pass, 0 fail). A first run under the lane's long TMPDIR failed only server/ssh-account-add.test.ts because its forwarded socket path exceeded the Unix socket limit; with a short TMPDIR it passes 3 of 3, unrelated to this change.
Reviews: Codex (gpt-6.2-sol, xhigh) confirmed the root cause and that the test still guards fix(codex): read a turn's late error after herdr reports the pane at rest #4791; 2 LOW notes (a timeout leaves the spies installed until the file ends; three nearby negative read counts could pass before stat() returns, which can hide a regression but never fails a run). omo gate: confirmed the root cause and no product change; 1 MEDIUM (a missing read hit only the runner's timeout, so finally never restored the spies), fixed in 3efac03. Re-checked: with status.ts from before fix(codex): read a turn's late error after herdr reports the pane at rest #4791 the test now fails at 1.5 s with no rollout read finished; 50 of 50 runs pass again under the 2-CPU load.
… turn
The third snapshot's rollout read starts only after stat() returns from the thread pool, but the test counted reads after a single setImmediate. On a 2-core GitHub-hosted runner the stat often had not returned yet (2 of 3 reads), which failed the 0.5.10 Release fast checks. Await the read itself, with a bounded timeout.
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
Issue 3760: The test waits for the rollout read that detects a late error, but this PR does not change status handling itself.
Merge Risk: Minimal · previous review 950c2
This change only makes a flaky status-hub test wait for the rollout read directly, with a bounded timeout. It does not affect production behavior, and the remaining merge risk is minimal.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a test change in the codex area that waits for the late-failure read instead of one event-loop turn. It matches the changeset, which replaces the settled() wait with h…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description follows the repository template. It has a Change section that names the flaky test, the failing CI run, the root cause (reads counted after settled(), before stat() returns), and the f…
Full details: Title check
Explanation
The title names the main change: a test change in the codex area that waits for the late-failure read instead of one event-loop turn. It matches the changeset, which replaces the settled() wait with h.looked() in the late-failure test. It uses the conventional commit form and is specific enough for history scanning.
Full details: Description check
Explanation
The description follows the repository template. It has a Change section that names the flaky test, the failing CI run, the root cause (reads counted after settled(), before stat() returns), and the fix (await h.looked() with a bounded timeout). It also has a Validation section with reproduction steps, before/after run counts, the commands run (bun run check fast) with their results, and the unrelated ssh-account-add failure. It does not mention contract-test coverage, but the change is test-only and does not touch HTTP/WS behavior, so that omission is not critical. The description is specific and consistent with the objectives.
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.
Reviewing files that changed from the base of the PR and between dcada8f and 950c2bc.
Files selected for processing: 1
server/core/codex-status-hub.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
A wait that outlives the test's timeout leaves the file's spies installed, because the test's finally never runs. Race the read against a deadline below the test timeout.
Three nearby negative counts (codex-status-hub.test.ts replacement session, vanished rollout, stale working snapshot) can be checked before a delayed stat() returns, so they could miss an erroneous extra read or lookup. This can hide a regression but never fails a run, so it does not cause flakes; left out of this release-blocking fix.
Merged through pr-merge at head b5b85cd35. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit finished, with no review that names this head.
main had moved since the checks of 3efac03eb: pr-merge --update merged it in (250cded2e), and every required check was green at this head.
Test-only fix for the codex-status-hub flake that failed the first 0.5.10 Release attempt; merged after the Release run succeeded, on the lead's (Dori) instruction. CodeRabbit reviewed 950c2bc with no comments; the later commit is test-only.
…ks instead (#4853)
## What
Locks one-tick waits in tests and browser scripts, and takes them out of
the Codex status hub test, where they let a read that must not happen go
unseen.
- `scripts/fixed-sleeps.ts` gains `turnWaits()`: a test or browser
script (`*.test.*`, `scripts/**/*-regression.ts`, `*-qa.ts`) that waits
one turn of the event loop for work to finish (`new Promise((r) =>
setImmediate(r))`, `setTimeout(r, 0)`, `new Promise(setImmediate)`, a
helper that only returns one, `setImmediate()` or `setTimeout(0)` from
`node:timers/promises`, named or through a namespace import). Not
counted: a turn inside a loop that polls a condition (`turn < 50 &&
!seen()`, `while (!done())`, a body of its own that breaks or throws; a
`return` in a callback inside it does not count) and one inside a
`Promise.race(...)`. `Bun.sleep` stays with the fixed-sleep count.
- `scripts/turn-waits.json` freezes today's 254 waits in 71 files;
`scripts/conventions.test.ts` holds it with the same `countRatchet` as
`fixed-sleeps.json`, so it may only shrink. `bun scripts/fixed-sleeps.ts
--turns` prints the counts. The fixed-sleep and marked-wait counts are
unchanged (the loop scan moved into `loopAround`, which both use).
- `server/core/status.ts` hands out `codexLooks()`: a promise that
settles once every rollout look begun has ended and told what it found.
`server/core/codex-status-hub.test.ts` awaits it instead of a
`setImmediate` (5 places, `settled()` included), so "no second read" is
asserted only after the look that could do it has finished.
- `.github/REVIEW.md` names the new baseline beside the other two.
## Why
A turn ends before work that waits on a file, a timer or a socket. An
assertion that something did not happen then passes before it could, on
a busy runner more often (#4803 was this shape).
## Validation
- Failing first: the new `turn waits` conventions tests fail on main's
`scripts/fixed-sleeps.ts` (`Export named 'turnWaitCounts' not found`).
- Mutation: with `noteCodexSession` no longer ending the turn on a
session change (so the replacement session's rollout is read), `bun test
server/core/codex-status-hub.test.ts` on 2 cores (`taskset -c 0,1`) x10:
main's test passed (missed it) 3 times; the new test failed (caught it)
10 of 10.
- Unmutated: the new hub test passes 50 of 50 on 2 cores.
- Review fixes (one round, after the omo review CLEAR and Codex's 4
MEDIUM / 3 LOW): decrementing and for-of loops count, a nested
callback's `return` no longer exempts a loop, the race exemption covers
only the race's own operands, timer imports and namespace imports count,
helper declarations no longer count as calls and helper calls with
arguments do, do-while polls are recognised, and the file list covers
every test package. Fixed-sleep and marked-wait counts are
byte-identical to main's.
- `bun run check fast` (after the fixes): ok (workflow syntax, generated
types, generated themes, typecheck, build, unit tests 28849 pass, 0
fail).
- Skipped: `check full` and browser regressions (no browser or UI code
changed).
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
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.
Change
Fixes the flaky
server/core/codex-status-hub.test.tstest "still finds a late failure after therollout tail contains no turn markers (#3760)" that failed the 0.5.10 Release run's
"Fast checks (GitHub-hosted)" job (run 45782602477:
Expected number of calls: 3, Received: 2).The product is fine: the snapshot that follows the late error does start the third rollout read,
but
codexRestbegins that read only afterstat()of the rollout returns from the thread pool.The test counted reads after
settled(), which waits for onesetImmediate; on a slow 2-corerunner the
stathas often not returned by then. The test now awaits the read itself(
h.looked()) before counting, with a bounded 2 s timeout like its neighbours.h.looked()itself now fails after 1.5 s, beforethe test's own timeout, so a missing read fails the test with its
finallyrun and the file's spies restored.Test-only change: no changelog fragment.
Validation
taskset -c 2,3) under 4 busy loops onthe same CPUs: 20 of 30 runs failed with
Received number of calls: 2on origin/main.server/core/status.tsfrom before fix(codex): read a turn's late error after herdr reports the pane at rest #4791, the changed test still fails (times out at 2 s),so it still guards codex: a failed turn whose error is written after herdr reports rest still reads DONE #3760.
bun run check fast: green at 950c2bc (28807 unit pass, 0 fail). Re-run green at 3efac03 (28807 pass, 0 fail). A first run under the lane's longTMPDIRfailed onlyserver/ssh-account-add.test.tsbecause its forwarded socket path exceeded the Unix socket limit; with a shortTMPDIRit passes 3 of 3, unrelated to this change.stat()returns, which can hide a regression but never fails a run). omo gate: confirmed the root cause and no product change; 1 MEDIUM (a missing read hit only the runner's timeout, sofinallynever restored the spies), fixed in 3efac03. Re-checked: withstatus.tsfrom before fix(codex): read a turn's late error after herdr reports the pane at rest #4791 the test now fails at 1.5 s withno rollout read finished; 50 of 50 runs pass again under the 2-CPU load.