Skip to content

Fail a blocked prompt, carry a switch after a limit, survive a sleep - #188

Merged
khalilgharbaoui merged 6 commits into
masterfrom
fix/blocked-prompt
Nov 15, 2026
Merged

khalilgharbaoui merged 6 commits into
masterfrom
fix/blocked-prompt

Conversation

@khalilgharbaoui

@khalilgharbaoui khalilgharbaoui commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

A message a Claude Code UserPromptSubmit hook ended read as an empty reply, and when that message was a history replay, the conversation's history was lost without a word (h #g314).

What happened

On 2026-11-14, after a switch from Opus 5.5 (appical) to Fable 5.2 (default), the plugin replayed the thread as text. agent-guard's prompt guard blocked the replay ("it contains secret-like values"). Claude Code made no API call and reported success with num_turns: 0, so the plugin showed ▌ **no reply:** ("Nothing failed"). It also recorded the empty Claude session as the one continuing the conversation, so every later message went to it with no history.

Measured (Claude Code 2.1.293, 2.1.314, 2.1.322, scratch hook)

  • 2.1.314+ send one system/informational frame with prompt_submit_outcome: {kind, prompt_kept, reason} and prevent_continuation: true, then a success result with num_turns: 0. 2.1.293 sends the frame without the outcome.
  • The frame's content and the result's result repeat the whole original prompt, so only the outcome is read. Nothing logs either text.
  • A message queued mid-turn is judged too. It gets the same frame while the turn goes on (num_turns: 2).

Change

  • This turn's own message blocked: the turn finishes {unified: "error", raw: "blocked_by_hook"} (or the CLI's other kinds) under a ▌ **prompt blocked:** note quoting the hook's reason. There is no no reply note and no turnStats footer. The session is kept.
  • Blocked replay into a session that had none: the child and its session id are dropped before anything is recorded, so the next message replays again. The plugin never sets a hook's bypass variable.
  • Blocked steered message inside a turn that went on: note only.
  • Blocked compaction: no text, error part (h #g214).
  • Found on the way: REFUSAL_FALLBACK_MARKER was never in PLUGIN_NOTE_MARKERS, so that note was replayed as Claude's words. It is registered now, and a test scans src/ for any ▌ marker missing from the list.

The interactive transport (measured under a PTY on 2.1.322)

  • The TUI records the block as a system/informational record with promptSubmitEnding: {ending: {kind, reason}, promptKept} and writes no user or assistant record after it, so a PTY turn waited out its whole turnTimeoutMs. The turn now ends on that record.
  • The TUI hands the blocked text back to its input box, and the next paste joined it: the next message's record held the 40 blocked lines plus the new message (1,425 characters), and a blocked replay would ride into every later message. One Ctrl+C before the next paste clears it (measured: only the new 35-character message recorded, TUI still up). It is never sent while a turn runs.
  • The record is renamed into the stream's prompt_submit_outcome shape with its content (the whole prompt) dropped, and the synthesized result is headless's num_turns: 0 success, so the note, the error finish and the blocked-replay drop are the headless code unchanged.
  • The location-switch empty turn in TODO.md (ses_e2898d33effeo0ojQzfvfWVOJK) was this same block: agent-guard refused the replay into the worktree's new session key by size, 6 s after the step started.

Why the switch replayed at all (h #g315)

The appical session hit its 5-hour limit twice before the switch. A resume record was only written after a served turn, so the limited turns' messages sat past it, and the by-hand switch to the default account refused the carry (sibling-conversation-changed). Claude Code's transcript holds both limited turns (user record plus a <synthetic> rate_limit reply), so the session was intact. Now the record is also written after a turn that failed on a usage limit or an account block with the CLI's own failure reply. Other failures, such as a 529 or a too-long prompt, keep the replay. A restart after a limit benefits the same way.

The watchdog and a sleeping Mac (h #g316)

The same evening a subagent's turn was closed as a stream timeout during a dark wake and its CLI ran on unattended for about 28 minutes. Its transcript and pmset -g log show the 60 s wire-inactivity timer counts wall-clock time, sleep included: it fired 3 s into a dark wake with at most 41 s of awake time behind it. A fire more than 5 s past its deadline now waits a fresh full delay, because the silence was never observed (a sleep, or an event-loop stall with output still in the pipe). A fire that does close the turn sends the CLI an interrupt, as an abort does. The start watchdog follows the same late-fire rule, and an api_retry frame makes whichever watchdog is armed wait out the backoff the CLI announces, so a long retry neither closes the turn nor respawns a working child. Proxied calls that arrive with no stream attached are unchanged (late-result recovery).

Checks

  • npm run typecheck, npm test (2316 pass), npm run build
  • test/prompt-blocked.test.ts drives real doStream turns against a fake CLI replaying the measured frames, with a secret-like string that must reach neither the reply nor the log
  • test/account-groups.test.ts: a by-hand switch after a usage limit resumes the first account's session with no replay (fails without the change), and one after a 529 still replays
  • The fake-CLI half of test/prompt-blocked.test.ts is skipped on Windows, like the other fake-CLI files; the parser and note tests run there
  • test/result-fallback-sleep.test.ts: a fire made ten minutes late by a jumped clock re-arms and the CLI's answer lands, and a closing fire sends exactly one interrupt; each fails with its change switched off
  • test/interactive-pty.test.ts: a scripted TUI that ends a prompt the measured way: the record and its stream frame, the synthesized result, a turn ended at once and one Ctrl+C before the next paste, ask failing, a queued message leaving its turn running, and doStream turns for the note and a blocked replay dropping its session

A UserPromptSubmit hook that ends a message now fails the turn under a
prompt blocked note quoting the hook's reason, instead of an empty reply
saying nothing failed. A blocked history replay drops its empty session,
so the next message replays again rather than going on without it.

Also registers REFUSAL_FALLBACK_MARKER in PLUGIN_NOTE_MARKERS and adds a
test that scans src/ for any marker missing from the list. h #g314
A turn that failed on a usage limit or an account block, answered by the
CLI's own failure reply, leaves a session that holds its message, so its
resume record is written. Before, a by-hand switch to another account
after a limit replayed the whole thread (sibling-conversation-changed),
and so did a restart. Other failures keep the replay. h #g315
@khalilgharbaoui khalilgharbaoui changed the title Fail a turn whose prompt a hook blocked Fail a blocked prompt, and carry a switch after a usage limit Nov 14, 2026
The wire-inactivity watchdog counts wall-clock time, sleep included, so a
sleeping Mac read as a silent CLI and closed a subagent's turn while its
CLI only waited for the network; the CLI then ran on unattended for 28
minutes. A fire well past its deadline now waits a fresh delay, and a
fire that closes the turn interrupts the CLI. h #g316
@khalilgharbaoui khalilgharbaoui changed the title Fail a blocked prompt, and carry a switch after a usage limit Fail a blocked prompt, carry a switch after a limit, survive a sleep Nov 14, 2026
An api_retry frame says how long the CLI will wait before its next
attempt; whichever watchdog is armed now waits that much longer, so a
long backoff neither closes the turn nor respawns a working child. The
start watchdog also re-arms on a late fire, like the inactivity one.
h #g316
The TUI records a prompt a UserPromptSubmit hook ends as a system/informational record with promptSubmitEnding and nothing after it, so a PTY turn waited out its whole timeout, and it hands the text back to its input box, where the next paste joined it. End the turn on that record, clear the box with one Ctrl+C before the next paste, and hand the parser headless's frame and result so the note, the error finish and the blocked-replay drop are shared. Measured under a PTY on Claude Code 2.1.322 (h #g314).
@khalilgharbaoui
khalilgharbaoui merged commit 7f893c2 into master Nov 15, 2026
2 checks passed
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.

1 participant