Skip to content

Wake once for a prompt Escape dropped, which Claude Code submits again - #5066

Merged
max-sixty merged 2 commits into
mainfrom
agent-a59ff17987702ec9e
Nov 3, 2026
Merged

max-sixty merged 2 commits into
mainfrom
agent-a59ff17987702ec9e

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A leaf-dev journey claude-code run on #4900 failed its dropped step with two "Leaf: new input" wakes 90 ms apart for one comment ({'Stop hook wake': 2, 'empty': 1}). Both rows were background-watch wakes, so admission's nudge played no part. The run's transcript, Claude Code's debug log and the page's watch records show the sequence:

  • The Stop hook's watch woke the session for the comment.
  • Escape cancelled that wake's prompt while another prompt hook slept, as the step intends, after Leaf's prompt hook had handed the comment over.
  • Claude Code queued the wake again and submitted it 46 ms after the Escape under a new prompt id. Its prompt hook handed the comment over again, and a turn answered it.
  • Around the Escape, the dropped prompt's own watch, which Claude Code's prompt registration starts and which outlives Escape, made a pass, prompted by the thread title the server wrote 55 ms before the Escape. It read Claude Code's idle, took the dropped turn for one Escape had stopped, and woke the session too. Claude Code queued that wake into the answering turn and attached it at the next tool boundary, where it had nothing to hand over.

The change

later_turn_wakes read idle as the end of a turn that nothing follows. That holds for a turn Escape stops while it runs. It doesn't hold for a queued prompt, such as a wake, that Escape drops during its prompt hooks: Claude Code submits that prompt again, and its hooks start the watch that takes over. A watch now treats such an ending as it already treated a Stop's: it wakes only if no successor has come within the hooks' time (20 s).

Claude Code's transcript tells the two endings apart. It writes a prompt's record, which names its promptId, only once the prompt's hooks let it through, and writes nothing of a dropped prompt (harness.claude_code_prompt_dropped, behind the new Harness.prompt_dropped). The watch now receives the hook payload, which names the transcript.

Every wake is kept. A typed prompt Escape drops goes back to the composer and is not submitted again (probed on 2.1.316), so its watch still wakes the session for what the dropped prompt was handed: about 20 s after the Escape rather than at its next look within 5 s, or not at all if the user sends the prompt again first, whose own hook hands the input over. A payload naming no transcript, or a transcript that can't be read, reads as not dropped and keeps the immediate wake.

Evidence

  • test_a_prompt_escape_dropped_is_handed_its_input_again_after_one_wake replaces the test that asserted the dropped prompt's watch wakes. Its [queued] case reproduces the journey's interleaving, a title write between the Escape and the resubmission, and fails without the new rule ("the dropped prompt's watch woke the session"); [typed] checks the wake still comes once no successor does.
  • Focused suites pass: test_wait.py, test_hooks.py, test_hook_registration.py, the layer contract's route test and test_interact_pi.py (134 passed).
  • leaf-dev journey claude-code passed all 12 steps twice with no empty wake or notice, and --forks passed its 6 steps. In those runs no dropped prompt's watch looked between the Escape and the resubmission, so they show the change breaks no step (woken, whose Escape stops a running turn, was still picked up 3.0 s after it) rather than reproducing the race; the [queued] test does that.

Not changed

Admission's nudge can still interleave with a Stop hook's watch where no watch holds the session's lease at a Stop, as after the turn that first claims a page: input admitted between the Stop hook closing the turn and the Stop's watch taking the lease is nudged, and the watch then wakes for it too. A scratch model test reproduced it; no run has shown it. The watch can't skip its wake on the nudge's mark (messaged_ending) without risking a lost wake, since a nudge that lands starts a turn only where Harness.input_wakes says so, which takes crossSessionInbound: accept in the user's settings.

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

max-sixty and others added 2 commits November 1, 2026 23:30
A watch read Claude Code's idle as the end of a turn nothing follows. A queued
prompt that Escape drops during its prompt hooks is submitted again, and that
prompt's hooks start the watch that takes over, so the dropped prompt's watch
woke the session a second time for the same input when it looked in between.
Claude Code's transcript holds no record of a dropped prompt, so the watch now
waits for a successor after one, as it does after a Stop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty merged commit 54f4226 into main Nov 3, 2026
4 checks passed
@max-sixty
max-sixty deleted the agent-a59ff17987702ec9e branch November 3, 2026 17:56
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