Skip to content

Let the prompt hook's server start take the hook's own deadline - #5973

Merged
max-sixty merged 5 commits into
mainfrom
timeout-events
Nov 14, 2026
Merged

max-sixty merged 5 commits into
mainfrom
timeout-events

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

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

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.
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.
A held port now refuses at once. A bind that sets SO_REUSEADDR already
passes TIME_WAIT, so its EADDRINUSE means a live listener, and a previous
Leaf server closes its listener before it releases the lease a restart
waits on, so waiting would not move the holder. Only the macOS wildcard
bind, which can't reuse, still retries for PORT_WAIT_SECONDS.

That left reconnect.SERVE_WITHIN (5 s per page) nothing to bound, and it
refused starts a loaded machine would finish: a start takes about 1 s
idle, 3.4 s on CI and up to 40 s under load. The starts now share the
hook's one deadline, CONFIRM_WITHIN after the hook began, carried 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 bounds as deadlines.

Behavior changes: a start between 5 and 10 s now serves its page; one
over 10 s is refused and the turn's input goes as a pointer instead of
inline; a held port refuses with "Address already in use" instead of
"did not become ready" after 5 s.
leaf-agent
leaf-agent previously approved these changes Nov 14, 2026
Base automatically changed from test-timers-review to main November 14, 2026 23:04
@max-sixty
max-sixty dismissed leaf-agent’s stale review November 14, 2026 23:04

The base branch was changed.

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_
# Conflicts:
#	tests/interact_support.py
@max-sixty
max-sixty merged commit 502ea05 into main Nov 14, 2026
5 checks passed
@max-sixty
max-sixty deleted the timeout-events branch November 14, 2026 23:21
max-sixty added a commit that referenced this pull request Nov 15, 2026
The earlier commit also passed outside deadlines down to steps the 20 s
bounds used to cover: the prompt hook's into adapter preparation and its
start lock, inference's 60 s cap into each request, and the eval's limit
into its startup. Each covers only an App Server that answers pings but
never a request, the case this change accepts, and the hook's adapter start
already ran past the hook's kill before #5973. This keeps only the
deletions: a request waits for its answer or the connection's close, the
adapter's first connection for its outcome, and a checkout switch for the
former adapter's exit. Production code is +10/-17 against main.
max-sixty added a commit that referenced this pull request Nov 15, 2026
Adds "Wait for the event that ends the work" to the root `AGENTS.md`'s
cross-runtime invariants: code waits for the event that ends the work,
and a deadline stands only where an outside party imposes one or to cap
a cost, as that party's whole budget, at least ten times above the work
on a loaded machine, taking a slower path on expiry where one exists.

The tests already had this rule (`tests/AGENTS.md`, "Results do not
depend on execution speed"); the product had none. A review of Leaf's
timers that Max asked for found five that could fail work a slow machine
would finish, each of which the rule would have ruled out: the prompt
hook's 5 s server start (removed in #5973), the browser's 10 s state
read (removed in #5975), the Codex adapter's two 20 s bounds, and the
render check's 180 s wall-time cap. Max picked this wording from a draft
on the review's page.

No tests; prose only.

> _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