Skip to content

End a state read when a news look fails, not after 10 seconds - #5975

Merged
max-sixty merged 2 commits into
mainfrom
state-read-news
Nov 14, 2026
Merged

max-sixty merged 2 commits into
mainfrom
state-read-news

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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

A later state read on a slow but live server no longer flips the page
offline at 10 s. A leaf.page container that has just run a turn answers
its next state read in 2252-3918 ms, so the old bound sat at 2.5-4x the
answers it was meant to wait for, and on expiry the page showed the
offline line with Decisions disabled while the server was still
answering; each retry on the 2 s clock met the same bound.

The bound existed so a read still in flight, which holds the page's one
read slot, couldn't keep a dead server's reading on screen. The news
look already says when the server is gone, so a failed look now ends
every state read in flight as a lost request (`abandonReads` in
`runtime/state-feed.js`). A server that stops answering still reads
offline within the look's own 10 s bound, now `NEWS_TIMEOUT_MS`, and one
whose connections reset still ends the read at once. Every state read keeps the
first read's 120 s bound as `STATE_READ_TIMEOUT_MS`, which decides only
for a read that hangs while news answers and for reads no look stands
beside: the first read, a hidden tab's, a passive leaf.page session's.

Tests: `test_a_state_read_waits_while_news_answers_and_ends_when_a_look_fails`
replaces `test_the_first_read_and_the_user_s_later_ones_are_bounded_apart`,
which asserted the two bounds' values. It holds every bound in the page,
fires the bound a read lasting 40 s would pass (the old code's 10 s
bound fires there), lets news answer and checks the held read lands;
then it refuses news and expects the offline line, which the old code
never reaches while its read is held. A Node test holds the abandon
decision at the module. `test_a_state_read_timing_out_during_its_body_is_offline`
drops its fake `AbortSignal.timeout`, which `AbortSignal.any` rejects,
and still covers a body lost after the headers.

> _This was written by Claude Code on behalf of max-sixty_
@max-sixty
max-sixty merged commit 7ec8751 into main Nov 14, 2026
4 checks passed
@max-sixty
max-sixty deleted the state-read-news branch November 14, 2026 23:05
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