Skip to content

Close the hosted turn when its App Server stream goes silent or its follower faults - #729

Merged
max-sixty merged 2 commits into
mainfrom
fix/ci-34941155345
Sep 15, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/ci-34941155345

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

publish-site failed on main at 0309bd0 in run 34941155345. The deploy itself succeeded and the release pass verified leaf.page in Chrome; the job then failed ten and a half minutes later on the hosted-agent pass with agent published but did not reply; the page read working. This is the third run with that shape (#694, #705), and the commit under test touches only skills/leaf/scripts/leaf/render_gate/ and exporting.py, neither of which can reach the Worker or the container.

The fault

The container ran the agent to a publication at 8.7 s and then projected nothing for the rest of the gate's TURN_LIMIT. The page kept reading working: Starting — the detail _follow_turn sets before its first notification — while the container answered every one of the gate's two-second state reads. Agent alive, follower projecting nothing, claim open, no receipt.

_follow_turn converts a stream that fails into a terminal turn: its handler synthesizes a failed status, clears the stream activity, commits the reply stream and closes the claim. #705 identified two exits that skipped it, both producing exactly that page state:

  • A stream that goes quiet instead of closing. socket.recv(timeout=1) raises TimeoutError every idle second, and that became continue with nothing bounding the repetition. Reconnection was reachable only from a socket error, so the recovery _resume_turn_stream already implements was never tried.
  • A fault outside the handler's four named types. The assert delivery_id is not None and the AppServerReplyStream construction sat ahead of the try entirely, and a KeyError or AttributeError inside the projection loop propagated out through _run_follow_turn, whose finally only discards the thread from following_threads.

The change

Both halves restore the same contract — worker/README.md's "a failed, interrupted, or completed-but-unanswered provider turn closes its active claim turn without inventing a reply" — and neither substitutes for the other: the guard cannot close a turn whose follower never returns, and the bound cannot close one whose follower raised.

  • recv_notification returns nothing while the stream is merely quiet and lets the TimeoutError through once the silence outlasts STREAM_SILENCE. TimeoutError is an OSError, so that routes a stalled subscription into the recovery a dropped one already takes, unchanged: thread/resume reads the authoritative turn, which carries the terminal status the stream never sent. A resume the turn did not need costs one round trip and reconciles the same way a real drop does, so the bound does not have to be tight — 120 s is past any gap between items a running turn produces, and well inside the ten minutes the reader spent watching a dead page.
  • The follower's whole body now sits inside its terminal guard, and the guard names any fault rather than four. A fault of any shape produces the failed terminal the stream-failure path produces: activity cleared, claim closed, no invented reply, reader obligation still open.

The consequence is wider than this gate. Any leaf.page reader whose turn landed here saw a page that read working indefinitely, with neither an answer nor a failure.

Verification

Three cases in tests/test_website_server.py, each failing on main and passing here: the silence bound distinguishes a quiet stream from a stalled one; a socket that only ever times out recovers its completed turn and commits the reply through the resume path; and a follower fault outside the named types closes the claim, leaves the activity no longer reading working, and leaves the obligation unanswered.

uv run pytest tests/test_website_server.py is green (72 passed). The everyday suite is green apart from four failures this sandbox owns, which reproduce unchanged on the merge base — two on a read-only /tmp, one on the sandbox umask, one on the Node bundler.

What no local run can prove is which of the two mechanisms produced the three observed stalls; separating them needs turn_stream_completed and container stderr from Workers Observability, and this account has no Cloudflare credentials. That is why both are repaired: each is reachable, and each alone leaves the contract broken.

Fixes #705

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The universal terminal guard is the right repair, and the silence bound routes a stalled subscription into the recovery a dropped one already takes. One consequence of the broadened guard is worth closing before it lands.

A fault outside the four previously named types used to propagate out of _follow_turn and reach the thread's excepthook, which printed a traceback to container stderr. It is now caught, and its only record is detail = str(error) or type(error).__name__ — which keeps the type only when the message is empty. So a KeyError in the projection loop, the exact fault the second half of this change exists to catch, is recorded as App Server turn stream failed: 'params': no type, no location. turn_stream_completed logs status and no error field at all, unlike the turn_delivery_unbound branch beside it, which already carries error=type(error).__name__.

That matters because it is the evidence this PR names as still outstanding: separating a stalled stream from a follower fault on the next occurrence needs turn_stream_completed and container stderr, and after this change neither names the fault. I am pushing the repair — name the type in detail, carry it on turn_stream_completed, and pin it in the follower-fault test.

Verified separately: all three new cases fail on the merge base ee83b181 and pass at this head, with the follower-fault case failing on base by KeyError escaping _follow_turn — the mechanism the change describes. uv run pytest tests/test_website_server.py is green here (72 passed).

The broadened guard stops a fault outside the four named types from
reaching the thread excepthook, which took the traceback with it. Carry
the exception type in the turn's failure detail and on
turn_stream_completed, so separating a stalled stream from a follower
fault stays readable from the log the next occurrence leaves.
@max-sixty
max-sixty merged commit 08018bb into main Sep 15, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/ci-34941155345 branch September 15, 2026 08:58
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.

ci-fix: publish-site failing — a stalled hosted turn never reaches a terminal receipt

2 participants