Skip to content

End a turn on its answer: Stop leaves late input to the watch - #3256

Merged
max-sixty merged 7 commits into
mainfrom
agent-a95a9b33a345e0272
Oct 20, 2026
Merged

max-sixty merged 7 commits into
mainfrom
agent-a95a9b33a345e0272

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Max reads Claude Code in focus view, which shows each turn's prompt and final message only. When a page comment arrived after a turn's last tool call, Leaf's Stop hook handed it into that turn and continued it, so the agent's reply to the comment became the turn's final message and hid the answer the user had asked for. Max's sessions of 2026-10-10 to 10-19 hold 65 Leaf Stop continuations; 56 handed in new input this way, and 59 of the 65 replaced a final message of 300 characters or more. A scripted real session on main reproduced it: a 350-word answer to a terminal question gave way to "You asked 'When could that fix land?'…".

What changes

  • Stop leaves late input to the watch (hook_transport.carry_turn). Where a watch follows the turn (Harness.watches_between_turns: Claude Code at its terminal or fed --input-format stream-json, Pi with a UI), Stop hands no input over. It closes the turn, the watch wakes on the close, and the input arrives through the prompt hook of a turn of its own. The same scripted run on this branch ended the user's turn on its answer and answered the comment in the woken turn; arrival to pickup took 11 s against 13 s on main, both mostly the model writing its answer. Under plain claude -p or pi --print, where nothing watches after the run, Stop still hands input into the turn it continues.
  • Pi says whether it watches. PiHarness.watches_between_turns answered yes in every mode, though the extension starts its watch only with a UI; the extension now exports LEAF_PI_WATCH, so a print run keeps its Stop handover.
  • The hooks module stops appending deliveries. With no inline delivery at Stop in an interactive session, the module no longer runs Leaf's Stop hook itself to append one out of the terminal's sight. Its mark stands down only the background watch, and hooks.json's Stop registration runs beneath it as without the module. The leaf_delivery output field had no other reader and goes, with the test driver's append support.
  • Prose in session-lifetime.md, harness-claude-code.md, the site's "Stop hook checks" and the module headers now says Stop hands input over only where no watch follows.

Tests

Stop-delivery receipt tests run under a new printing fixture (plain --print); new tests hold that an interactive Stop leaves input to a turn of its own, for Claude Code in process, through the hooks module, and through Pi's extension. Each fails against main's rule. The claude-code journey now requires, at every step, that no Stop hook continued a turn with input. It passed in full without the hooks module; with it, every step through escape passed and woken failed on an expectation #3169 left stale (it waits for a mid-turn pickup the module no longer makes), which this PR doesn't touch.

Left open

Stop still continues a turn once for an update picked up and unanswered, or for a page it could not re-vendor, which also replaces the turn's answer in focus view (9 of the 65). Waking a turn for that reminder needs a record that it reminded, or an agent that won't act is woken without end; dropping it leaves only the next prompt's reminder. TODO.md holds that as Max's decision.

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

max-sixty and others added 7 commits October 19, 2026 22:42
Max reads Claude Code in focus view, which shows each turn's prompt and
final message only. When a page comment arrived after a turn's last tool
call, Leaf's Stop hook handed it into that turn and continued it, so the
agent's reply to the comment became the turn's final message and hid the
answer the user had asked for. Max's sessions of 2026-10-10 to 10-19 hold
65 such Leaf continuations; 56 were this new-input case, and 59 replaced
a final message of 300 characters or more. A real session on main
reproduced it: a 350-word answer to a terminal question gave way to "You
asked 'When could that fix land?'...".

Where a watch follows the turn (`Harness.watches_between_turns`: Claude
Code at its terminal, `--input-format stream-json`, Pi), Stop now hands no
input over. It closes the turn, the watch wakes on the close, and the
input arrives through the prompt hook of a turn of its own. The same run
on this branch ended the user's turn on its answer and answered the
comment in the woken turn; arrival to pickup took 11 s against 13 s on
main, both mostly the model writing the answer. Under plain `--print`,
where nothing watches after the run, Stop still hands input into the
turn it continues.

With no inline delivery left at Stop in an interactive session, the hooks
module no longer runs Leaf's Stop hook itself to append a delivery out of
the terminal's sight. Its mark now stands down only the background watch,
and `hooks.json`'s Stop registration runs beneath it as without the
module. The `leaf_delivery` output field had no other reader and goes,
with the driver's append support.

Stop still continues a turn once for an update picked up and unanswered,
or for a page it could not re-vendor, which also replaces the turn's
answer in focus view (9 of the 65). Waking a turn for that reminder
instead needs a record that it reminded, or an agent that won't act is
woken without end, so TODO.md now holds that as Max's decision.

Behavior changes in tests: Stop-delivery receipt tests run under the new
`printing` fixture; a new test holds that an interactive Stop leaves the
input to a turn of its own, and the module test asserts the woken prompt
instead of the appended delivery. The claude-code journey requires, at
every step, that no Stop hook continued a turn with input.

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

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…Stop now leaves it

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

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Review found that `PiHarness.watches_between_turns` answered yes in every
mode, while the extension starts its watch only where Pi has a UI. Under
`pi --print` the Stop hook therefore held back input that arrived as the
run ended, and nothing woke a run for it. The extension now states
whether it watches as LEAF_PI_WATCH, which the harness reads, so a print
run still takes that input at Stop as a Claude Code `-p` run does. A new
test holds the TUI side: the Stop hook hands nothing over and the watch
starts a run that takes the input.

The harness docstring also said the watch calls the prompt hook itself
on waking an idle session; the extension sends a notification, and the
prompt hook completes the run's accepted message.

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

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…n step

#3169 left mid-turn delivery to PostToolBatch under either watcher, so the
module no longer hands a comment to a turn while its command runs. The
`woken` step still waited for that pickup under `--hooks-module` and
failed with "the command ended before Escape"; it now waits only for the
watch to wake, as it does without the module.

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

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 6217aa5 into main Oct 20, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-a95a9b33a345e0272 branch October 20, 2026 06:25
max-sixty added a commit that referenced this pull request Oct 21, 2026
Applies #3256's Stop rule to Codex. #3256 made Claude Code's and Pi's
Stop hook hand no late page input into a finishing turn where a watch
follows it, so the turn ends on its answer and the input gets a turn of
its own. Codex's Stop hook still blocked the turn's end and handed a
late comment in, so the agent wrote one more message after its answer,
and that reply became the turn's final message.

### What changes

- **One predicate says whether a later turn takes late input**
(`Harness.later_turn_takes_input`). It is the watch between turns for
Claude Code and Pi (`watches_between_turns`), and the live delivery
adapter for Codex (`adapter_is_live`). `hook_transport.carry_turn` and
`CodexHarness.offer_at_step` both read it, so Codex's Stop offers
nothing while the adapter runs. The turn closes, and the adapter offers
the input in a turn of its own: a `turn/start` with a `leaf_delivery`
tool output over App Server, or the queue's next turn through `codex
queue`. A Codex task that waits with `leaf wait` has no adapter, so its
Stop still hands input over, as under plain `claude -p`.
- **An owed update this owner holds no usable reference for counts as
input, not as a debt** (`hook_transport.read_plans`). Such an update,
received by another session before the page changed hands, is already
deliverable again (`delivery.unreferenced`). Stop used to remind the
agent about it as well, which with Codex's adapter running continued the
turn with a reminder naming the `leaf wait` that would deliver its
reference. Now Stop hands it over with the other input or leaves it to
the later turn. The same applies to Claude Code and Pi with a watch.
- Prose in the `codex.py` and `hook_transport.py` headers,
`session-lifetime.md`, `harness-codex.md` ("Delivery"), the site's "Stop
hook checks" and `TODO.md` now says Stop hands input over only where
nothing opens a later turn for it.

### Codex's TUI shows every message of a turn

The question was whether replacing the final message matters in Codex
the way it does in Claude Code's focus view. In codex-cli 0.160.0's TUI,
a turn asked to send a progress message, run a command and then answer
showed all three in the transcript (`• ALPHAONE`, `• Ran echo hi`, `•
OMEGATWO`). So the TUI never hid the answer. What this change keeps in
Codex is that a turn's final message is its answer, and that late input
gets a turn of its own; surfaces that show a turn's final message alone
were not checked.

### Tests

- New `test_a_codex_stop_leaves_late_input_to_the_adapters_own_turn`:
with the adapter live, a comment collected as the turn ends gets no Stop
output, the turn closes, and the adapter queues it once. It fails with
the Stop early return removed (Stop blocks with the envelope).
- `test_a_stop_reminder_recovers_the_exact_reply_address`: the handoff
cases now reach the new owner through the adapter's offer after Stop.
They fail without the `read_plans` change (Stop continues with the
reminder).
-
`test_codex_stop_leaves_quiet_input_but_delivers_the_whole_batch_with_owed_input`
is deleted: it asserted that an owed comment keeps the turn open with
the adapter running, the behavior this PR reverses.
`test_a_codex_stop_keeps_the_revision_returned_by_its_offer` now runs
without an adapter, where Stop still offers.
- The `codex-app-server` and `codex-queue` journeys pass. Their `resume`
step now runs on both transports and requires that a comment sent during
an empty-input resumed turn, whose first boundary is its Stop, is
answered in a turn of its own rather than handed into the resumed turn.
- Focused suites pass, except
`test_codex_app_server.py::test_a_turn_that_shares_a_user_message_leaves_the_delivery_owed`,
which fails the same way on `main` (`KeyError: 'status.json'`, from
#3380 meeting #3384).

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

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 21, 2026
…s over App Server (#3435)

#3425 applied #3256's Stop rule to Codex: while the delivery adapter
runs, Stop hands no late input into the finishing turn, and the adapter
offers it in a turn of its own. Over App Server that turn opens quietly,
on a `leaf_delivery` tool output. On the `codex queue` route (the
desktop app and IDE), the adapter queues a `leaf-delivery` pointer,
which Codex records as a `userMessage` and runs as a user turn of its
own (measured below), so #3425 turned every comment that lands at Stop
into a message in the user's name. Before #3425 such a comment entered
the finishing turn instead. Max's rule: "In codex, adding a message to
the user turn is very noisy to the user, so we only want to do it when
we need to."

### What changes

- **`CodexHarness.later_turn_takes_input` is true only for an App Server
adapter.** It reads the live adapter's lease record
(`codex_adapter.running_adapter`, formerly `_running_adapter`), whose
`app_server` names the transport, under the adapter start lock: an
adapter takes its lease before writing that record, and
`preparing_adapter` holds the start lock until the adapter has written
it, so Stop never reads a half-started adapter's empty record. Stop
reads it only in a session that holds a page and has a live adapter, so
a hook in a session holding nothing still loads no page reading.
`build/browser/protocol-baseline.json` carries the record's renamed
reference. On the queue route Stop again hands late input into the
finishing turn, as before #3425. The base
`Harness.later_turn_takes_input` docstring now states the criterion: the
later turn must open without the agent asking and show the user less
than continuing the ending turn would.
- Prose in the `codex.py` and `hook_transport.py` headers,
`session-lifetime.md`, `harness-codex.md` ("Delivery"), the site's "Stop
hook checks" and `TODO.md` now names the App Server adapter, not any
adapter.

### Evidence (codex-cli 0.160.0)

`codex queue --thread T --message M`, run twice while a turn ran,
produced two later turns, each opening on a `userMessage` item holding
`M`, and each answered. `_item_delivery_id` already reads a queued
`leaf-delivery` pointer as a `userMessage`. How the desktop app and the
TUI draw that item was not checked.

### Tests

-
`test_a_codex_stop_leaves_late_input_to_an_app_server_adapters_own_turn`
runs both transports: with an App Server adapter Stop prints nothing and
leaves the comment collected for the adapter; with a queue adapter Stop
blocks with the envelope, the comment opens in the ending turn, and
nothing is queued.
- `test_a_stop_reminder_recovers_the_exact_reply_address` returns to its
queue form: the new owner's redelivered update comes through Stop.
- Tests that took a bare adapter lease now write its record
(`interact_support.adapter_lease`), as a running adapter does.
- Controls: with the predicate back at `adapter_is_live`, the queue case
and two reminder cases fail; with it always false, the App Server case
fails.
- The `codex-queue` journey's `resume` step again requires the comment
to enter the empty-input resumed turn and start no turn of its own;
`codex-app-server` keeps #3425's requirement. Both journeys pass on this
branch. In the `codex-queue` run, the four deliveries offered while the
task was idle each arrived as a `leaf-delivery` user message, and the
comment sent during the resumed turn arrived through Stop with no
message of its own.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 22, 2026
…in a turn of its own (#3596)

Max's decision #3a on the overnight report: when a Claude Code turn ends
still owing a page answer, end it on its answer and remind the agent in
a turn of its own (option A).

### The defect

Leaf's Stop hook continued a turn that still owed an answer to a
delivered update, telling the agent which update it owed. The agent then
wrote one more message, usually a short note about the comment. Claude
Code's focus view shows only each turn's last message, so that note
stood in place of the answer the turn had written. In Max's sessions of
10–19 October this was 9 of the 65 Stop continuations; #3256 had already
moved the late-input cases to a turn of their own.

### What changes

- **Stop ends the turn on its answer** where a watch follows the turn
(`Harness.watches_between_turns`: Claude Code at its terminal, Pi with a
UI). `hook_transport.stop_continues` no longer counts response debt
there. Under plain `--print` and on Codex, where no watch wakes a later
turn, Stop still continues the turn as before. A page Leaf could not
re-vendor still continues the turn.
- **The watch wakes a turn of its own for the reminder**
(`session.left_owed`, `activity.left_owed`). After a Stop closes the
turn, the watch wakes for each owed answer that turn didn't start and
that no prompt has named since the update's delivery. It wakes the same
way #3256 wakes for late input. That turn's prompt hook names the owed
answer with its exact ref, as every prompt already does. The wake line
says the page has an update still owed an answer, rather than new input.
- **The record that Leaf reminded is the prompt's existing pickup, with
no new record.** When a prompt re-presents an update already received
and still owed, the prompt hook records an opened pickup without the
update's `answer.ref` (`pick_up_acknowledged`). `delivery.reminded`
reads that pickup: a ref-less pickup after the newest delivering one
means a prompt has named the update since its delivery. This is the same
pickup record #3591 (decision #2) reads as handed but unconfirmed. So a
turn that ends still owing the same answer wakes nothing more, whether
the reminder came from the watch's turn or from a prompt the user typed.
A new delivery of the update, as when it changes hands, starts over.
- `leaf wait` and the Codex adapter keep their watch passes as they
were: `session.read_watch_pass`'s default still wakes only for a batch.
- The TODO entry for this decision is removed.

### Checks

- New
`test_a_turn_ends_on_its_answer_and_a_turn_of_its_own_names_what_it_owes`:
a prompt hands a comment over, and Stop ends the turn with no output.
The watch wakes with the owed-answer line, the next prompt names the
comment, and when that turn ends still owing it, nothing more is owed a
wake. On main, the first Stop continues the turn instead.
- `test_agent_sees_the_complete_interaction_recovery`'s snapshot now
shows a Stop with no output, the watch's reminder wake, and the reminder
in the next prompt, where it used to show the reminder in the Stop
hook's output.
- Tests whose subject is what Stop says when it holds a turn now run
under plain `--print` (`printing`), where it still does. Two
monkeypatched policies take the new keyword.
- `leaf-dev journey claude-code` gains a `deferred` step. The user's own
turn, told to leave Leaf's comments for later, is handed a comment at a
tool boundary and ends on its answer, with no Stop hook continuing it.
The step checks that the user's turn closed with the comment unanswered,
that no Stop hook output named it, and that a later prompt named it
before it was answered. The full journey passed every step on this
branch. In `deferred`, the user's turn ended on "done", and the woken
turn answered the comment 35 s after it was sent, with one wake row and
no empty one. The journey's row count now counts a wake as filled when
its prompt carries a reminder (`ATTENTION_OPENING`) as well as a
delivery. The `--hooks-module` arm named in the decision no longer
exists, since #3540 removed the module's watch, so the plugin's module
loaded in this one run.
- Model and process tests covering hooks, waits, receipts, activity,
workflows, Codex and the hooks module pass.

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

---------

Co-authored-by: Claude Opus 5.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.

2 participants