Repository navigation
fix(agentctl): make prompt --wait follow a prompt Claude Code queues - #587
olebhansen-agent wants to merge 16 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
@olebhansen, for 51f3426 (fix(agentctl): take only a dequeued turn for queued input's). This pull request is rebased onto the new head of #586 (2869995), with no change to its own commits. Since the last report it gained a rename, a checklist row and two fixes, each with a test first, for a prompt sent while the hooks of the one ahead run. Claude Code then writes the prompt's Waiting for youTwo cases the red team found still end the wait early, as
Decided on your behalf
Checks
|
1d35b7d to
37a3a1f
Compare
a32f6e3 to
62e5b7d
Compare
37a3a1f to
99fca5d
Compare
|
Rebased on the new head of #586, which is rebased on |
62e5b7d to
5315dbf
Compare
99fca5d to
3edc8f7
Compare
69b8865 to
9339d42
Compare
9339d42 to
5287b35
Compare
5287b35 to
2869995
Compare
…ueues A prompt pasted while Claude Code writes an answer is queued as a turn of its own, but its UserPromptSubmit fires at once, so the wait ends with the running turn's Stop. The transcript's queue-operation lines show the queue. The fixture holds turns recorded with Claude Code 2.1.321: a prompt queued behind an answer, one absorbed during a tool call, and one queued behind an answer the operator then interrupted. The conversation signals gain `queued`, which the tracker does not set yet. The tests fail on that, on a wait that ends with the running turn, and on a wait that ends at an interruption a queued turn follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A prompt pasted while Claude Code writes an answer is queued as a turn of its own, and its UserPromptSubmit fires at once, so the wait ended with the running turn's Stop. The Claude Code tracker now follows the operator input the transcript's queue-operation lines show as queued, until the turn it starts ends. A settled completion then keeps the wait going, and the conversation is read again about once a second until the turn ends. Claude Code queues its own notifications too, and runs them in turns of their own, so the tracker leaves out what it wrote itself. A `dequeue` doesn't say whose input it takes, and it sits above the end of the turn before it, since conversation lines are written in batches. So the tracker goes by what follows that end: the start of the operator's turn, of a notification's turn, or something else, such as the warning that the input is an unknown command. An interruption that a queued turn follows no longer ends the wait, since that turn is the prompt's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arted does not hold the wait Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…laude Code's queue Input queued after the prompt has started its turn or left the queue is someone else's, such as a prompt sent without --wait, and the prompt's turn no longer waits for it. Only a turn the operator started counts as the operator's, and the line Claude Code writes when a scheduled task fires doesn't count as input that started no turn, so a scheduled prompt taken ahead of the operator's no longer ends the wait early. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efore the mark is followed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efore it A prompt sent without --wait just before the waited one can write its turn's start below the mark, since Claude Code writes a prompt only after its hooks have run. Its lines and those of the waited prompt's own turn are the same, so the tracker now knows the prompt, and takes a turn that starts with nothing queued for the prompt's only when it holds the prompt's text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s turn started is not followed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude Code writes a pasted prompt of several lines wrapped in <pasted_content> tags, with its tabs and line breaks changed, and a slash command as its echo. The tracker now compares the prompt with the line that starts a turn without whitespace, those tags, or the echo's markup, so input queued behind such a prompt's turn no longer holds the wait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…head of it is followed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude Code writes an enqueue at once and a typed prompt only after its hooks have run. So a prompt pasted while those hooks run is queued above the turn ahead of it, and that turn, which was typed and not taken from the queue, ended the wait before the queued prompt was answered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es with it The signal also holds while the queued input's own turn runs, when nothing is queued any more. What the wait reads from it is that the operator's input has not been answered yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ws its prompt prompt --wait tells its prompt's turn from a later one's by the prompt's text, in the forms Claude Code writes it. A Claude Code that writes a prompt in a new form makes the wait follow the later turn too, and no test with recorded lines would show that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54d71f5 to
0d5a337
Compare
… run is followed Claude Code 2.1.321 writes the enqueue of input pasted while it runs the UserPromptSubmit hooks of the prompt ahead without its text, so the tracker passes over it and the wait ends with the turn ahead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ad run Claude Code writes the enqueue of input sent while it runs the UserPromptSubmit hooks of the prompt ahead without its text, and the tracker passed over such an enqueue, so the wait ended with the turn ahead. The tracker now counts it as the operator's input. Without the text it may be Claude Code's own, so a turn for Claude Code's input that the dequeue starts drops it, and the wait doesn't hold to its timeout. It may also be someone else's input sent while the prompt's own hooks ran, so a typed turn that holds the prompt drops it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s hooks run is followed A slash command's echo has no promptSource, so the tracker took the slash command's turn for the queued prompt's and ended the wait with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A slash command's echo has no promptSource, so the typed rule could not tell a slash command typed at idle from queued input, and the wait ended with the slash command's turn. A turn for queued input always follows the dequeue that took it, which a typed prompt or slash command never does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
A prompt pasted while Claude Code writes an answer is queued as a turn of its own. Its
UserPromptSubmitfires at once, inside the running turn, and nothing fires when its turn starts, soprompt --waitended with the running turn'sStop. The transcript shows the queue, and the conversation reader from #586 now reads it.<task-notification>, which also run in turns of their own.enqueueof input sent while it runs theUserPromptSubmithooks of the prompt ahead without its text. The tracker counts such input as the operator's. Since it may be Claude Code's own, a turn for Claude Code's input that adequeuestarts drops it again, so the wait can't hold to its timeout.--waitor typed into the attached terminal, and the wait doesn't follow its turn. A prompt sent just before the waited one can start its turn below the mark with the same lines as the prompt's own turn, so a turn that starts with nothing queued counts as the prompt's only when it holds the prompt's text. The comparison leaves out what Claude Code changes as it writes a prompt: whitespace, the<pasted_content>tags around a pasted prompt of several lines, and a slash command's echo markup.dequeuetook input before it. A prompt or slash command typed when nothing ran has none, even when Claude Code writes it below input queued while its hooks ran.dequeuedoesn't say whose input it takes, and Claude Code takes its own input and the operator's in the order they came. The tracker therefore goes by what the conversation shows once the turn before has ended: the start of the operator's turn (turnOriginhuman: the prompt, or a slash command's echo), the start of a turn for Claude Code's own input (a notification, or a scheduled prompt from cron or/loop), or anything else other than the lines Claude Code writes between turns, such as its warning that the input is an unknown command.stop_hook_summary, an API error message or the interruption marker.agentctl/docs/harness-upgrades.mdgets a row for each of the two cases, since a Claude Code that writes its queue or a prompt in a new form breaks them without a test noticing.Plan. Stacked on #586, which adds the reader. Review that one first.
Closes #155
Evidence
cargo test -p agent --lib claude_code::transcriptandcargo test -p agent --test integration prompt_waitAt "test(agentctl): pin that prompt --wait follows a prompt Claude Code queues", which fails on purpose (the squash merge keeps it out of
main), four tracker tests and one service test fail on their assertions, for example:Six more pairs of commits pin and fix input the tracker took for the prompt's, or missed. Each test fails at the fix before it, on its assertion:
"-qqqqqq"against"-------"."---------"against"-qqqqqqq-"."-qqqqqq"against"-------"."qqqq-----"against"qqqqqqqq-"."-----"against"qqqq-"."-----"against"qqqq-".At the head, "fix(agentctl): take only a dequeued turn for queued input's",
make fmt lint build testpasses. Each rule of the tracker and the wait, broken on its own, fails a test, except that the comparison's removal of U+200B is untested.In use. On Linux, with debug builds of agentd in a home of their own, and an agent from
ghcr.io/digdir/agentctl-base:ubuntu-26.04-desktoprunning Claude Code 2.1.321 on Haiku. Times are when the wait returned, by the host's clock, and when the turn'sstop_hook_summarywas written, by the agent's.A first prompt is sent without
--wait, then the second with--waitwhile the first is answered:main(84e4878)turns --last 1shows the prompt with no answer. In one run the wait returned 0.3 s after the essay ended, 6 s before the queued turn did.turns --last 1shows the answer.UserPromptSubmithook that takes 3 s, an essay, then "Reply with exactly THIRD" 1 s later. Claude Code writes the second prompt'senqueuewithout its text.turns --last 1shows the answer.At earlier commits of this pull request, before the fixes that changed only which input counts as the prompt's:
/otters, a project command, returned 0.4 s after its turn ended, and/nosuchcommand, which Claude Code takes from the queue and warns it doesn't know, returned 4.5 s after it was sent. A prompt of three lines sent with--wait, with another sent without it 3 s later, returned 0.62 s after its own turn ended, while the later prompt's turn ran.Not run live: input absorbed during a tool call, an interruption that a queued turn follows, a notification or scheduled prompt queued ahead of the prompt, and a slash command typed ahead of the prompt within its hooks. The tracker tests cover each, with lines recorded from Claude Code 2.1.321.
Risk
maindoes, and both need a prompt sent within theUserPromptSubmithooks of the one ahead. The prompt's text was also sent just before, so the lines match someone else's input sent during the prompt's own hooks, which the wait must not follow. Or a background task's notification was queued ahead of the prompt.--waitand queued just before the waited one may be answered in a turn of its own. The tracker may then end with that turn.Follow-ups
prompt --waitservice test that races the completion it waits for. It predates this change.🤖 Generated with Claude Code