Skip to content

Keep product deadlines from deciding test results - #5962

Merged
max-sixty merged 3 commits into
mainfrom
test-timers-review
Nov 14, 2026
Merged

max-sixty merged 3 commits into
mainfrom
test-timers-review

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Some tests ran real work under a deadline the product sets, so their result depended on how fast the machine runs, against tests/AGENTS.md's "Results do not depend on execution speed". The suite's check, test_a_wait_takes_the_suites_deadline, reads only deadlines written in test source, so it missed every one.

The prompt hook gives a resumed session's page server 5 s to start (reconnect.SERVE_WITHIN) and hands the turn its input inline only within 10 s of its own start (hook_transport.CONFIRM_WITHIN). A start takes about 1 s on an idle Mac and about 3 s on CI, over 5 s at the tail. On 14 Nov two CI runs (#5863's and another a minute later) failed four test_session_lifecycle.py tests with "did not become ready". Across 324 CI runs since the tests landed in #5555, their call time shows no drift: every day's slowest run sits within half a second of the bound. An autouse fixture in tests/interact_support.py now gives both bounds STATED_TIMEOUT in every in-process test, replacing the one test that patched CONFIRM_WITHIN to 600 s for the same reason. The port held arm keeps 0.5 s, which holds at any speed because the held port means its start never becomes ready.

An audit of every other product deadline a test runs work under, or shortens with monkeypatch, found three more:

  • Two presence tests count neighbor scans while the presence cache's 2 s age runs out; they now give it STATED_TIMEOUT.
  • The render gate's stopped-server journey cut SERVED_TIMEOUT_MS to 1.5 s for every probe and read in four renders; now only the stalled read is cut.
  • Three arms of the Codex desktop start test cut START_TIMEOUT to 0.2 s, so a late answer read as lost, the outcome those arms expect; now only the lost-answer arm cuts it.

tests/AGENTS.md now says to give such a deadline STATED_TIMEOUT and shorten it only to 0 or where the work it bounds can never finish. Still exposed: tests/journeys/test_session_lifecycle.py runs the hook as a subprocess, which a fixture can't reach.

Tests: under twelve busy loops on the Mac's efficiency cores, all six reconnect tests fail on main and pass here (one start took 40 s); with only SERVE_WITHIN raised, the resumed-session test fails on CONFIRM_WITHIN instead. The presence tests passed 6 of 6 under the same load. The edited journey, the hook, lifecycle, Codex adapter and suite-source tests, and the other hook-reaching model tests pass. Asked for by Max, reviewing a CI failure his session flagged.

This was written by Claude Code on behalf of max-sixty

The prompt hook gives a resumed session's page server 5 s to start
(`reconnect.SERVE_WITHIN`) and hands the turn its input inline only within
10 s of its own start (`hook_transport.CONFIRM_WITHIN`). Tests in
`test_session_lifecycle.py` run a real start under both. A start takes about
1 s on an idle Mac and about 3 s on CI, over 5 s at the tail, so on 14 Nov two
CI runs failed four of these tests with "did not become ready". Slowing a Mac
with busy loops on its efficiency cores fails all six; with only SERVE_WITHIN
raised, the resumed-session test fails on CONFIRM_WITHIN instead, its delivery
becoming a pointer.

An autouse fixture now gives both bounds STATED_TIMEOUT in every in-process
test, as tests/AGENTS.md's "Results do not depend on execution speed" asks of a
timer. A test whose subject is a bound still sets its own: the `port held` arm
keeps 0.5 s, since the held port means its start is never ready. The fixture
replaces the one test that patched CONFIRM_WITHIN to 600 s for the same
reason, and tests/AGENTS.md now says that `test_a_wait_takes_the_suites_deadline`
can't see such product deadlines and where they go.
leaf-agent
leaf-agent previously approved these changes Nov 14, 2026
An audit of every product deadline a Python test runs work under, or
shortens with monkeypatch, found three more tests whose result depends on
machine speed:

- Two presence tests in test_interact_server.py count neighbor scans while
  the presence cache's two-second age runs; on a slow machine it expires
  mid-test. They now give the cache STATED_TIMEOUT, since only a changed file
  is their subject.
- The render gate's stopped-server journey cut SERVED_TIMEOUT_MS to 1.5 s,
  which reached every probe and read in all four renders. Only the stalled
  read is cut now.
- Three arms of the Codex desktop start test cut START_TIMEOUT to 0.2 s, so a
  late answer read as lost, the outcome those arms expect. Only the
  lost-answer arm cuts it now.

tests/AGENTS.md now states the rule these follow: give a product deadline or
cache age STATED_TIMEOUT, and shorten it only to 0 or where the work it bounds
can never finish.
@max-sixty max-sixty changed the title Give the prompt hook's bounds the suite's deadline in process Keep product deadlines from deciding test results Nov 14, 2026
@max-sixty
max-sixty merged commit dd31f9e into main Nov 14, 2026
5 checks passed
@max-sixty
max-sixty deleted the test-timers-review branch November 14, 2026 23:04
max-sixty added a commit that referenced this pull request Nov 14, 2026
Every state read after the first ended at 10 s and showed the page
offline, with Decisions disabled, even while the server was still
answering. A leaf.page container that has just run a turn answers its
next state read in 2252–3918 ms (the measurement
`test_the_first_read_and_the_user_s_later_ones_are_bounded_apart`
recorded), so the bound sat 2.5–4× above real work, and each retry on
the 2 s clock met the same bound.

The bound existed so a read in flight, which holds the page's one read
slot, couldn't keep a gone server's reading on screen. The page already
asks for news every 250 ms, and that request tells a slow server from a
gone one. Now a failed news look ends every state read in flight as a
lost request (`abandonReads`), so the page shows the offline line
exactly as a timed-out read did. A server that stops answering still
reads offline within the look's own 10 s (`NEWS_TIMEOUT_MS`); a slow
live one keeps its read. Every state read takes the first read's 120 s
as its hang bound, which now decides only for a read that hangs while
news answers and for reads no look stands beside: the first read, a
hidden tab's, and a passive leaf.page session's.

Worth weighing: any failed look abandons reads, including a live
server's HTTP error on `/api/news`. News and state share the server's
activation path, so a news 500 almost always means state fails too;
narrowing to rejected fetches and 502/503/504 would cost one branch.

Part of a review of Leaf's timeouts that Max asked for, of timers that
can fail work a slow machine would finish. Independent of #5962 and
#5973.

Tests:
`test_a_state_read_waits_while_news_answers_and_ends_when_a_look_fails`
replaces the test that asserted the two bounds' values; it fails on the
old code in both halves. A Node test holds the abandon decision in the
module. `test_a_state_read_timing_out_during_its_body_is_offline` drops
a fake `AbortSignal.timeout` that `AbortSignal.any` rejects. `pnpm run
check`, `pnpm run test:runtime`, the changed browser tests and seven
neighbouring freshness and restart tests pass locally.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 14, 2026
The prompt hook gave each resumed page's server start 5 s
(`reconnect.SERVE_WITHIN`), which refused starts a loaded runner would
have finished: a start takes about 1 s on an idle Mac, 3.4 s on CI and
up to 40 s under load, and #5962 covers the CI failures this caused. The
bound existed only because `hosting.listening_socket` retried EADDRINUSE
for 90 s. A bind that sets SO_REUSEADDR already passes TIME_WAIT, so its
EADDRINUSE means a live listener, which waiting won't move: a previous
Leaf server closes its listener before it releases the lease a restart
waits on. Such a bind now refuses at once. Only the macOS wildcard
(`--host`) bind, which can't reuse, still waits for its port.

`SERVE_WITHIN` is gone. The starts share the hook's one deadline,
`CONFIRM_WITHIN` (10 s) after the hook began, passed as an absolute
`deadline` through `claim_and_start` and `starting_detached`, so the
child's confirmation counts against it too; the Codex adapter and the
preview launcher pass their existing bounds as deadlines. A start
between 5 and 10 s now serves its page. One over 10 s is refused and its
turn gets its input as a pointer rather than inline, where before it was
refused at 5 s with the input inline. Several pages now share 10 s
instead of taking 5 s each, so they can't add up past the harness's 20 s
kill.

Follows #5962, whose suite fixture loses its `SERVE_WITHIN` line here.
Part of a review of Leaf's timeouts that Max asked for. Codex reviewed
the diff; its one finding, that the confirmation read got a second full
timeout, is fixed here.

Tests: the refused-start test gains a `no time left` arm, and its `port
held` arm now expects the immediate refusal. A held port refuses at its
first bind, which fails on the old retry. The macOS wildcard wait keeps
a test, skipped on Linux. The focused hook, lifecycle, port, Codex
adapter and preview tests pass locally.

> _This was written by Claude Code on behalf of max-sixty_
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.

2 participants