Skip to content

test(codex): wait for the late-failure read instead of one event-loop turn - #4803

Merged
devswha merged 3 commits into
mainfrom
fix/codex-late-failure-flake
Nov 26, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/codex-late-failure-flake

Conversation

@devswha

@devswha devswha commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Change

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

… 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.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

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.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Updated the late-failure test to wait for the rollout status snapshot before checking that the failure was detected.

The late-failure test now waits for the rollout read before checking that the third read detected and recorded the failure.

Changes: Late rollout failure test

Layer / File(s) Summary
Synchronize late-failure assertions
server/core/codex-status-hub.test.ts
After appending the failure marker, the test waits for looked() before checking the third read and recorded failure. The test timeout is now 2,000 ms.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Other

Possibly related issues

  • 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: Passed 4

Check name Status Explanation
Title check Passed 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 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.
Description check Passed 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.

Share

Recent review info

Run configuration

Commits

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.
@devswha

devswha commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

Review notes (not fixed in this PR, LOW):

  • 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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Deploying ovis with  Cloudflare Pages  Cloudflare Pages

Latest commit: b5b85cd
Status: ✅  Deploy successful!
Preview URL: https://3d7a17ea.ovis.pages.dev
Branch Preview URL: https://fix-codex-late-failure-flake.ovis.pages.dev

View logs

@devswha
devswha merged commit 7c993e0 into main Nov 26, 2026
14 checks passed
@devswha
devswha deleted the fix/codex-late-failure-flake branch November 26, 2026 10:08
@devswha

devswha commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

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.

devswha added a commit that referenced this pull request Nov 27, 2026
…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).
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