Skip to content

Follow a hosted turn on one connection, and end the turn when it ends - #834

Merged
max-sixty merged 11 commits into
mainfrom
fix-772-turn-follower-bound
Sep 19, 2026
Merged

max-sixty merged 11 commits into
mainfrom
fix-772-turn-follower-bound

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

publish-site failed on main at 8baf6c4 against a page that read working: Starting for the gate's whole ten minutes. Workers Observability holds the shape of it: over four and a half days, 70 of 73 hosted turns dropped their subscription at start and took a fresh one, 69 of them holding no turn. Five turns ended failed and every one of them was an unbound follower that had been given a turn id — App Server answered turn/start, _start_turn discarded that answer on purpose, and should_resubscribe then closed the socket carrying the turn. The refusal that killed each of them was Leaf's own: only _resume_turn_stream asked thread/resume for the thread's turns (excludeTurns: False), and App Server refuses to list them until a new thread's SQLite row exists. All five provider turns went on calling the model for another 11 to 46 seconds with nobody reading their answers.

So the recovery machinery was reached by every turn, recovered nothing, and was the only thing that ever lost one.

A turn is now followed on the connection it was started on, from turn/start to turn/completed. thread/start and thread/resume subscribe the connection that asked for as long as it lives and turn/start neither subscribes nor unsubscribes, so that one socket already carries everything the turn will say. HostedTurn takes the acknowledged turn id at construction and opens the page's turn as its own first step; TurnStream is a socket, its buffered notifications, and a clock.

Every other way a turn can stop — a dropped connection, silence past STREAM_SILENCE, a fault of any shape — now ends it. Leaf holds only a reader of a turn running in a child process, so the follower interrupts the provider turn rather than leaving one answering into nothing, and a thread found running a turn no follower holds is interrupted before the next delivery starts rather than queued behind. A start that names no turn withdraws its delivery and its reserved reply seat and raises, and the reader gets a startup_failed receipt for it. Which side writes that receipt follows who asked. The Worker's dispatch writes it for the request it is still holding. The container writes it for the starts nobody holds: a delivery carries at most one reply-owing move, so messages sent while a turn is already being followed are answered started on that turn's thread and queue behind it, and the dispatch for each is over before anything starts it. The turn's ending is the only scan they get, so _continue_page is one rule for it: while the page has a move no delivery holds, start it; a start that throws receipts its move and the scan takes the next, each receipted id joining excluding so one that does not settle is not handed back forever. The first start that succeeds ends the chain, because its own follower ends here too. Handing the page on is part of every ending rather than a reward for a tidy one — a follower that faulted leaves the same moves outstanding — which also closes a seam older than this branch, where a fault in closing a turn stranded every move queued behind it. The scan that hands the page on asks the log what the page still owes and nothing more: it used to activate the source first, which put a start-door condition in front of a reading that does not need one and fired on exactly the ending with the most to say, since closing a turn re-reads the source and a turn's own work can leave it unopenable. Activation belongs at the door and the door holds it, because attach reaches agent_event_pending. Both that handler and attach's own take every exception class rather than a named list: attach only records and re-raises, so a class nobody listed is exactly the one worth a record of, and the continuation is the top of a daemon thread, where what the reader is owed does not depend on which class ended the start. The list that was there named three and left out the connection's own — websockets raises WebSocketException, which descends from Exception alone — and _request opens the socket, shakes hands and sends thread/start before _start_turn's guard exists, so a refused handshake was the one start reaching neither the record nor the receipt.

That leaves one account of an ending, and every ending takes it: the reply seat is given up, the claim turn closes, the live reading comes off the page, and a move still owed an answer gets the turn_failed receipt. That receipt is new for a turn that picked a move up, and it has to be: only_if_unclaimed refuses every writer for a picked-up move, and the turn that picked it up is the one writing here. Its absence was not only the incident's frozen page — a dropped move is never redelivered either, because next_unaccepted_agent_event skips an obligation whose interaction names a delivery session.

Gone with it: should_resubscribe, reconcile, _delivered_turn, _restart_turn, TurnStream.resume and _resume_turn_stream, StreamLost, StreamRestart, awaiting and every arm that read it, _restore_reply, disconnect_reply, the delivery-keyed activity name, and the worker's two uses of the delivery-id text parser. worker/server.py loses about a quarter of its lines. The local Codex carrier keeps resume, because it observes turns it did not start.

Two readings change for the reader. An unanswered ending now says so instead of leaving a message picked up by a turn that is gone. And the "Starting" reading appears when the turn opens rather than when the request that made it went out, which in production is 34 to 84 milliseconds later, well inside the page's own two-second state poll.

Verification

tests/test_website_server.py loses the eight cases that described discovering a turn, recovering one, or queuing a delivery behind an active thread. Five more are rewritten to the endings that replace them: a refused or lost start gives the message back, an active thread has its turn stopped, a dropped stream and a silent one each end the turn and receipt the move, and a fault of any shape does the same. Eight new cases state what nothing asserted before — a turn that completes without an answer is still receipted, an interrupt the provider refuses is recorded rather than raised, a turn that will not stop leaves the thread rather than the reader, a continuation that cannot start receipts the move it was for whichever class ended it, a move queued behind that one is reached too, a follower that faults still hands the page on, an ending on a page the turn left unopenable still answers every move, and a start that fails on its connection is recorded like any other. Each behaviour was checked against a reverted fix.

Everyday suite, tests/test_website_server.py, pre-commit.

Closes #772

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

max-sixty and others added 7 commits September 18, 2026 12:08
`publish-site` failed on `main` at 8baf6c4 against a page that read
`working: Starting` for the gate's whole ten minutes while the agent inside
the container had claimed its delivery and published a revision. The follower
watching that turn never bound it, and an unbound follower has no ending.

`_start_turn` sends `turn/start` carrying the delivery as its
`clientUserMessageId` and as its `leaf_delivery` tool output, and App Server
answers with the turn it made for it. That answer was discarded on purpose —
"the follower learns which App Server turn took this delivery from the
notification stream, which is the one reading that survives a lost
acknowledgement" — so every healthy dispatch entered the recovery machinery
written for the rare lost acknowledgement, and that machinery has no exit.

It also has a trigger. `should_resubscribe` is armed on the first loop
iteration of every unbound follower, and its test for "App Server has not
started this delivery" is the delivery still being `offering` — which, in the
container, only `bind` itself ever clears. So the one thing standing between a
dispatch and a dropped subscription is `stream.pending`: the `turn/started`
that `_send` buffered behind the `turn/start` response. Arriving a moment
later instead, it is on a socket the follower closes before reading it. What
follows has no exit either. `_delivered_turn` looks for a turn whose own items
name the delivery and finds none; `_restart_turn` declines because the thread
is active; `_follow_turn` waits out another `STREAM_SILENCE` and repeats.
Nothing raises for the receipt #779 and #783 built.

The acknowledgement is the binding. A follower now begins bound and
`_restart_turn` binds the turn it starts, so only a start that was refused,
lost, or never sent still learns its turn from the stream — the case that
machinery was written for, and the one where no turn is running to lose. Bound,
every way the stream can stop reaches a terminal status or a fault the follower
reports, and `should_resubscribe` is out of reach of a live subscription.

Two readings travel with it. Until a turn is named the live reading is keyed by
the delivery, so `bind` gives that key up and the turn's own notifications
carry it from there. Clearing moves to `commit`, which also closes the ending
that had none: a `thread/resume` answering with a turn already finished sends
no completion to fold, so its reading stood for the whole working grace.

A turn that binds and then fails is receipted by nobody, which is unchanged but
now reached more often: `write_failure_receipt` answers only a move no turn has
picked up, and binding is that pickup, so the follower closes the turn and
leaves the move to the page. A new case states that outcome rather than leaving
it implied, since the population reaching it has grown.

`tests/test_website_server.py` also gains the two shapes behind the incident —
a stream carrying the whole turn except the notification that names the
delivery, and a resumed thread whose turn carries no `leaf_delivery` item. All
three are checked against a reverted fix. Three cases that produced their
unbound follower from an acknowledged start now lose the acknowledgement
instead, which is what leaves a follower unbound; one that counted activity
clears now names the reading, and one that asserted a cleared reading takes the
waiter lease its page needs for that assertion to mean anything.

Everyday suite (1,146) and `tests/test_website_server.py` (81), pre-commit.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…#772)

`publish-site` failed on `main` at 8baf6c4 against a page that read
`working: Starting` for the gate's whole ten minutes. Workers Observability
holds the shape of it: over four and a half days, 70 of 73 hosted turns dropped
their subscription at start and took a fresh one, 69 of them holding no turn.
Five turns ended failed and every one of them was an unbound follower that had
been given a turn id — App Server answered `turn/start`, `_start_turn` discarded
that answer on purpose, and `should_resubscribe` then closed the socket carrying
the turn. The refusal that killed each of them was Leaf's own: only
`_resume_turn_stream` asked `thread/resume` for the thread's turns
(`excludeTurns: False`), and App Server refuses to list them until a new thread's
SQLite row exists. All five provider turns went on calling the model for another
11 to 46 seconds with nobody reading their answers.

So the recovery machinery was reached by every turn, recovered nothing, and was
the only thing that ever lost one.

A turn is now followed on the connection it was started on, from `turn/start` to
`turn/completed`. `thread/start` and `thread/resume` subscribe the connection
that asked for as long as it lives and `turn/start` neither subscribes nor
unsubscribes, so that one socket already carries everything the turn will say.
`HostedTurn` takes the acknowledged turn id at construction and opens the page's
turn as its own first step; `TurnStream` is a socket, its buffered notifications,
and a clock.

Every other way a turn can stop — a dropped connection, silence past
`STREAM_SILENCE`, a fault of any shape — now ends it. Leaf holds only a reader
of a turn running in a child process, so the follower interrupts the provider
turn rather than leaving one answering into nothing, and a thread found running a
turn no follower holds is interrupted before the next delivery starts rather than
queued behind. A start that names no turn withdraws its delivery and its reserved
reply seat and raises, which is what lets the Worker's own `startup_failed`
receipt reach the reader.

That leaves one account of an ending, and every ending takes it: the reply seat
is given up, the claim turn closes, the live reading comes off the page, and a
move still owed an answer gets the `turn_failed` receipt. That receipt is new for
a turn that picked a move up, and it has to be: `only_if_unclaimed` refuses every
writer for a picked-up move, and the turn that picked it up is the one writing
here. Its absence was not only the incident's frozen page — a dropped move is
never redelivered either, because `next_unaccepted_agent_event` skips an
obligation whose interaction names a delivery session.

Gone with it: `should_resubscribe`, `reconcile`, `_delivered_turn`,
`_restart_turn`, `TurnStream.resume` and `_resume_turn_stream`, `StreamLost`,
`StreamRestart`, `awaiting` and every arm that read it, `_restore_reply`,
`disconnect_reply`, the delivery-keyed activity name, and the worker's two uses
of the delivery-id text parser. `worker/server.py` loses about a quarter of its
lines. The local Codex carrier keeps resume, because it observes turns it did not
start.

Two readings change for the reader. An unanswered ending now says so instead of
leaving a message picked up by a turn that is gone. And the "Starting" reading
appears when the turn opens rather than when the request that made it went out,
which in production is 34 to 84 milliseconds later, well inside the page's own
two-second state poll.

`tests/test_website_server.py` loses the eight cases that described discovering a
turn, recovering one, or queuing a delivery behind an active thread. Five more
are rewritten to the endings that replace them: a refused or lost start gives the
message back, an active thread has its turn stopped, a dropped stream and a
silent one each end the turn and receipt the move, and a fault of any shape does
the same. Two new cases state what nothing asserted before — a turn that
completes without an answer is still receipted, and an interrupt the provider
refuses is recorded rather than raised. Each behaviour was checked against a
reverted fix.

Everyday suite, `tests/test_website_server.py`, pre-commit.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
# Conflicts:
#	tests/test_website_server.py
`commit` closed the Leaf turn before receipting, and closing re-reads the page
— which the turn's own work can leave unopenable. The `ValueError` that raised
then skipped the receipt, so a turn that streamed an answer onto a page it had
broken left the reader with no reply, no receipt, and nothing to redeliver: the
exact ending this change is for.

Clearing the reading and receipting the move move into `commit`'s `finally`,
where every ending reaches them. `test_a_rejected_streamed_reply_still_releases
_its_website_turn` already drove that path and asserted only the raise; it now
asserts the receipt. A second case covers the other uncovered arm, a turn that
does not stop within `TURN_ABORT_WAIT`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The follower reads its delivery back by id when it accounts for the turn,
so a made-up `delivery-1` is refused there rather than at the send: the
case passed while its follower thread died on `SystemExit: invalid
delivery id`, which pytest reported as an unhandled thread exception and
nothing failed on. It prepares a real delivery against a real comment now,
as the neighbouring cases do.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The rewrite reads well and the new endings are convincing — one gap in the accounting, on the _start_turn withdraw path rather than on the follower.

_start_turn now raises when App Server names no turn, and the receipt for that is delegated: "the startup_failed receipt the Worker writes when this raises". That holds for the caller the Worker dispatched. It does not hold for the other caller. A second reader message that arrives while the container is following the first turn is answered {"status": "started"} by attach — thread_id in self.following_threads skips the start — so dispatchAgentTask resolves and its catch/startup_failed branch is spent. The only route left for that message is the continuation at the end of _run_follow_turn (if continuation is not None and not self.stop_event.is_set(): self.attach(page_dir, continuation)), which is not wrapped. A refused or lost turn/start there withdraws the delivery, escapes into the daemon thread, and leaves the move with no reply, no receipt, and no redelivery until the reader happens to send a third message.

Before this change that path recovered — a refused start returned an unbound follower that reconciled and retried turn/start under retry_delay. So the queued-message path loses the recovery without picking up the receipt that replaced it, which is the same reader-visible shape as #772 reached from the other side.

Giving the continuation the receipt the Worker owns for a dispatch would close it: wrap that attach call and write startup_failed for continuation when it raises. Happy to push that if you'd like it.

Comment thread worker/server.py Resolved
A move that arrives while a turn is already being followed is answered
`started` on that turn's thread: `attach` sees the claim's thread in
`following_threads` and returns without starting anything, so the Worker's
dispatch — and the `startup_failed` receipt it writes when a start throws —
is over before the move is ever started. The only call that starts it is the
continuation at the end of `_run_follow_turn`, and that one nobody holds.

`_start_turn` raising when App Server names no turn is new here, so that
raise reached the daemon thread with no receipt and no redelivery: the same
reader-visible shape as #772, from the other caller. The continuation now
writes `startup_failed` for the move it was for, and records
`container_continuation_receipted` so a `container_start_failed` can be read
for which of the two owners answered the reader.

Found by leaf-agent's review of #834.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The continuation receipt is the right owner and the right place — one gap in its reach: attach can fail before it ever gets to _start_turn, and those failures still escape unreceipted.

_start_turn names WebSocketException in its own except tuple, so a dropped App Server socket is already understood to be reachable on this connection. But the socket is opened and handshaken before _start_turn runs. _request calls app_server_connect and then app_server_handshake, and the thread/start or thread/resume request goes out on it as well — all outside _start_turn's try. app_server_request sends and receives on the raw socket without wrapping, so a ConnectionClosed (or an InvalidHandshake from the connect) propagates as a bare WebSocketException, which subclasses Exception and not OSError, RuntimeError, or ValueError.

That lands on exactly the ending this commit is for: the continuation start dies in the daemon thread, no startup_failed is written, and — as the new comment says of this path — the scan that would find the move again is the one that just produced it, so the reader waits on a turn that never began. It goes unrecorded too, because attach's own catch, the one that logs container_start_failed before re-raising, names the same three types.

Widening both tuples closes it; WebSocketException is already imported in this module. The inline suggestion covers the handler this commit adds. attach's catch is outside the diff — happy to push the matching widening there if you'd like it.

Comment thread worker/server.py Resolved
max-sixty and others added 2 commits September 18, 2026 22:20
`attach` named three exception classes, and the connection's own was not
among them: `websockets` raises `WebSocketException`, which descends from
`Exception` alone. `_request` opens the socket, shakes hands, and sends
`thread/start` before `_start_turn`'s own guard exists, so a refused
handshake or a socket dropped mid-request was the one start that reached
neither the `container_start_failed` record nor — from the continuation,
which nobody holds — the `startup_failed` receipt. That is the failure this
branch is about, arriving by the one route left open.

Both catches take every class now rather than a fourth name. `attach` only
records and re-raises, so its caller still meets the exception it would have
met and a class nobody listed is exactly the one worth a record of. The
continuation is the top of a daemon thread: what the reader is owed does not
depend on which class ended the start, and anything uncaught there is a
traceback on stdout and a page that waits forever.

`test_a_continuation_that_cannot_start_receipts_the_move_it_was_for` is
parametrized over a class the list held and one it did not, and
`test_a_start_that_fails_on_its_connection_is_recorded_like_any_other` covers
the record, which nothing asserted before.

Found by leaf-agent's review of #834.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
)

A delivery carries at most one reply-owing move — `append_batch` breaks on
the second — so two messages sent during a followed turn are two
obligations, both answered `started` on that turn's thread. The turn's
ending is the only scan either gets. Receipting the first and returning left
the second with no delivery holding it, no dispatch behind it and no later
scan: the page read `listening` against it until its reader sent a third.

At the merge base a refusal returned the unbound turn, so a follower still
ran and its ending still scanned. Raising ends the thread of execution that
owned the scan, so the receipt has to carry the scan with it.

`_continue_page` is that one rule: while the page has a move no delivery
holds, start it; a start that throws receipts its move and the scan takes
the next, with each receipted id joining `excluding` so one that does not
settle is not handed back forever. The first start that succeeds ends the
loop, because its own follower ends here too.

The same seam gated the scan on a clean ending, which stranded every queued
move whenever a follower faulted — closing a turn re-reads the page, which
the turn's own work may have left unopenable. Handing the page on is part of
the ending now, not a reward for a tidy one, and it runs on what the page
still owes rather than on how the turn finished.

`test_a_move_queued_behind_one_that_could_not_start_is_reached_too` and
`test_a_follower_that_faults_still_hands_the_page_on` cover the two halves;
each fails against its own reverted fix.

Found by leaf-agent's review of #834.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The hand-on's named fault class is a turn whose own work left `index.html`
unopenable: closing the turn re-reads the source, so `_finish_turn` raises
there. That is the ending with the most to tell its reader, and it was the
one ending that told them nothing. `next_unaccepted_agent_event` opened with
the same activation `_finish_turn` had just failed, so the scan raised
before naming any move: none was attached, none was receipted, both stayed
in `obligations`, and the scan's complaint replaced the ending's own fault
on the way out, leaving it as `__context__`. The gate this branch took out
of `if completed:` was sitting in the first line of the thing it gated.

The scan asks the log what the page still owes, and nothing more.
Obligations and interactions come out of `full_state`, which reads that page
without complaint, and the receipt was always writable — `write_failure_receipt`
does not activate. Activation is a start-door condition and the door holds it
already: `attach` reaches `agent_event_pending`, which raises on such a page,
so a start there throws to the handler that receipts its move and takes the
next. The ending can now say "no answer is coming" for every move the page
owes, instead of two readings of one page disagreeing about whether it can be
read at all.

`test_an_ending_on_an_unopenable_page_still_answers_every_move` asserts both
moves are receipted, no obligation is left standing, and the fault that
surfaces is the ending's own. Restoring the guard reddens it.

Found by leaf-agent's review of #834.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 9fe01d5 into main Sep 19, 2026
7 checks passed
@max-sixty
max-sixty deleted the fix-772-turn-follower-bound branch September 19, 2026 06:10
max-sixty added a commit that referenced this pull request Sep 19, 2026
`leaf codex start` carried every delivery through one observing
connection. The adapter's main loop handed a payload to that
connection's thread over a queue and waited on a reply queue with no
timeout, and the answer came back only once a notification's items
parsed back to the delivery id. So a turn this process had just started
was indistinguishable from one it merely watched, and a turn whose
notifications never carried the id back ran to completion with its reply
unbound and its caller still blocked.

A delivery now opens a connection of its own. `start_delivery_turn`
resumes the thread, reads its status, starts the turn, and hands the
socket to one follower that reads it to its reply. `thread/resume`
subscribes the connection that asked for as long as it lives and
`turn/start` neither subscribes nor unsubscribes, so that socket carries
everything the turn will say, and losing it is the turn ending rather
than a gap to read across. The turn id comes from the response, so
nothing recovers a binding the starter already had. This is the model
`#834` landed for the hosted carrier, which the merged change named as a
deliberate exemption for this one.

Two connections may resume one thread and both then receive everything
it says. Measured against App Server 0.155, in a throwaway thread since
deleted: a second connection resumed a thread the first already held,
its `turn/start` came back with a turn id, and that connection received
its own turn's whole stream — `turn/started`, `item/started`,
`item/agentMessage/delta`, `item/completed`, `turn/completed`.
`TaskObserver` therefore holds a delivery this process is carrying from
before its `turn/start` goes out, and passes over that turn; without it
one delivery would have two reply writers. The observer keeps what only
it can do: the user's own turns in the terminal, a queued pointer the
task picks up by itself, and their activity on the page.

That deleted the cross-thread scheduler — `waiters`, `requests`,
`deferred`, `_next_delivery`, `_defer_delivery`, `_answer_delivery`,
`_fail_pending`, `available`, `start_delivery`, and `_read`'s
`defer_answer`. It is not a net deletion. Counting statements without
comments or docstrings, `codex_adapter` goes 826 to 869 and `codex`
gains 29 for the moved stream, against 25 out of `worker/server`: a turn
object that owns its own lifetime costs about what the scheduler did.
What changes is that a turn has exactly one owner for its whole life.

`TurnStream` moves to `codex.py`, which both carriers already share, and
takes its silence bound as a parameter. The website gives 120 seconds
because nobody is at that task; the adapter gives none, because a turn
waiting on a terminal approval is silent for as long as the person takes
to answer it.

A turn ends the same way however it ended: `DeliveryTurn.commit` closes
the Leaf turn and takes the activity reading off the page from a
`finally`, because `DeliveryReply` guards only the commit of a completed
answer and a fault in the rest would otherwise leave the page saying the
agent is working until the claim's fifteen-minute grace expired.
`worker/server.py`'s `HostedTurn.commit` already did this; the near-copy
did not.

Only `active` is a status worth waiting for. `notLoaded` and
`systemError` are not states a task comes out of by being left alone, so
they raise onto the delivery loop's retry ladder, where the failure is
reported once and backed off rather than read as an ordinary busy task.
That reaches the adapter's log and no further: this carrier has no
writer that tells a reader no answer is coming — `write_failure_receipt`
is the website's alone — so a task stuck in one of those states still
leaves the move unanswered until someone reads `codex.log`. Closing that
needs a receipt policy for a carrier whose whole model is to retry, and
it is not closed here. Holding back costs no connection either: the loop
reads the observer's own fold of `turn/started` and `turn/completed`
rather than reconnecting once a second to ask the task, and that fold
now records a turn id only when the resume names one — the word "active"
standing in for an unnamed turn was something no `turn/completed` could
ever clear.

The idle rule is unchanged and now authoritative. `turn/start` against a
running turn steers into it rather than refusing — App Server says of
`turnTrigger` that it is "Ignored when this request steers an
already-active turn" — so the status is read on the starting connection
one request before the start, rather than from a fold another connection
left behind. That narrows the race without closing it. `turn/steer`'s
`expectedTurnId` would close it, and using it is a reply-routing
decision rather than a transport change, because a steered turn has one
final answer and two deliveries would share it.
`notes/codex-integration.md` records that as the open question, and
corrects its claim that the API has no such precondition.

**Reviewing.** `skills/leaf/scripts/leaf/codex_adapter.py` holds the
whole change: `TaskObserver` is the old client with the delivery role
removed, `start_delivery_turn` and `DeliveryTurn` are new.
`worker/server.py` only loses `TurnStream` and `recv_notification` to
`codex.py`. The test diff is large because the suite around the deleted
scheduler went with it.

Tests: a delivery turn streams and commits its reply on its own
connection, a busy task keeps its delivery for a later turn, a refused
start gives up the seat it reserved while an unacknowledged one keeps
it, a turn this process carries is not adopted by its observer, a
dropped connection ends the turn it was carrying, a stopping adapter
leaves a running turn to a later carrier, a delivery already being
carried holds back the next one, and a connection failure in the
delivery loop is retried. Each behaviour was checked against a reverted
fix.

Everyday suite 1163 passed with thread exceptions promoted to errors,
`tests/test_website_server.py` 86, pre-commit across the tree.

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Sep 19, 2026
Three changes from a survey session: one code fix found by hitting it,
and the list and note edits that follow from the survey's own results.
Item numbers below are `TODO.md` ids, written without a hash so they do
not read as issue references.

## A claim this version cannot read is dropped, not raised on

The claims directory is one per machine and every worktree, host and
session on it writes there, each running the leaf it was built from — so
a record older than the code reading it is ordinary rather than
exceptional. #813 removed the last shim on the premise that "every claim
is written by the running version", which a shared state home makes
false.

Found by hitting it an hour ago: a session held six preview pages
claimed before #811 named a harness, merged a main that had landed it,
and every `leaf wait` afterwards died in `owned_by` on
`claim["harness"]` — taking the watcher off the unrelated page the
reader was on. The page's own loop guard then fired on every turn, and
nothing in the message said why.

This is the third refusal in the family #822 named an hour earlier, from
the same cause: an update swaps the running Leaf under standing state.
#822 fixed the registry read and the re-vendor; the claim read was still
crashing.

Stage still owes nothing to what an older version wrote, so nothing here
migrates a record or reads its old shape. `readable_claim` is one
predicate on the two file readers every other reader goes through: a
record the readings above can take their answers from is a claim, and
any other record is not one this version can read, so its page reads as
unclaimed until something claims it again. That is what deleting the
stale state would have done, without the deletion, and no session is
taken down by state it does not own.

The harness *name* is decided at that same door, which review caught:
`host.claim_harness` does `HARNESSES[claim["harness"]]`, so carrying the
field was not enough — a record naming a harness outside this version's
table passed the predicate and raised two calls further in, in the Stop
hook and in the nudge the append door takes under its lock. Renaming a
harness is reachable by exactly the mechanism that made the field rename
reachable. `turn_closed` joins the field set for the same reason:
`event_endpoint` brackets it, and it was covered only by the accident
that it predates `turn` in the schema.

`CLAUDE.md`'s Stage section gains the missing half of its own rule — it
said stale state is thrown away without saying who throws it.

### Verification


`test_a_claim_an_older_leaf_wrote_is_dropped_rather_than_read_or_raised_on`
runs the reported journey: two pages held by one session, the first
claimed in the shape written before #811, and `leaf wait` on the second.
Bug-back with `readable_claim` removed reproduces the exact production
error, `KeyError('harness')` out of `leaf wait`, rather than a weaker
assertion failure — which needed the stale page to sort ahead of the
reader's page in the watcher's walk, as it did in the wild.

The two review cases go through the Stop hook, which is where their
consequence is. Bug-back on the harness-name guard raises
`KeyError('some-host-a-later-leaf-named')` out of the hook; bug-back on
`turn_closed` has the hook name a page nothing owns, which is the flood
this PR is fixing rather than a raise.

Everyday suite green on the merged head: 1,172 passed.

## `TODO.md`: item 25 retired, items 5 and 7 re-measured

Item 25 asked for one App Server client instead of two. #811, #813 and
#834 dissolved what it named: `codex.py` exports `app_server_connect`,
`app_server_handshake` and `app_server_request`, both callers use them,
`AppServerClient` moved out to `codex_adapter.py`, and
`worker/server.py` imports 17 public names and no private one. The
reconnect backoff, written four ways when the item was raised, is
written once.

What survived it is two turn supervisors over that one protocol —
`HostedTurn` and `WebsiteCodexHost` in `worker/server.py` at about 900
lines, against `TaskObserver` and `DeliveryTurn` in `codex_adapter.py`
at about 1,000. They supervise different things, a local Codex process
with a queue and a lease against a hosted per-reader container turn, so
merging them is a restructure with no deletion. That is item 6's
question, under the product condition item 6 already carries, so item 25
retires and item 6 states what is left of it.

Items 5 and 7 carried figures from before #808, #815 and #797 landed;
both are re-measured against `main` at `76252900` and dated.

## `notes/dependency-survey.md`

One line pointed at a `TODO.md` item `b7e1efd0` had already removed. It
now points at the work that landed.

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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 — an unbound hosted turn follower never reaches a receipt

2 participants