Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(agentctl): make prompt --wait follow a prompt Claude Code queues - #587

Draft
olebhansen-agent wants to merge 16 commits into
147-prompt-wait-interruptedfrom
155-prompt-wait-queued
Draft

olebhansen-agent wants to merge 16 commits into
147-prompt-wait-interruptedfrom
155-prompt-wait-queued

Conversation

@olebhansen-agent

@olebhansen-agent olebhansen-agent commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A prompt pasted while Claude Code writes an answer is queued as a turn of its own. Its UserPromptSubmit fires at once, inside the running turn, and nothing fires when its turn starts, so prompt --wait ended with the running turn's Stop. The transcript shows the queue, and the conversation reader from #586 now reads it.

transcript                                        tracker says
enqueue      "Reply with exactly SECOND."         pending
dequeue      (written above the essay's end)      pending: whose input is not known yet
stop_hook_summary   (the essay's turn ends)       pending: the next line says what was taken
user "Reply with exactly SECOND."  turnOrigin=human   pending: its turn runs
stop_hook_summary   (its turn ends)               nothing pending
  • The Claude Code tracker follows the prompt's queued input. It leaves out the queue lines whose text Claude Code wrote itself, such as a background task's <task-notification>, which also run in turns of their own.
  • Claude Code writes the enqueue of input sent while it runs the UserPromptSubmit hooks 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 a dequeue starts drops it again, so the wait can't hold to its timeout.
  • It follows the prompt only. Once the prompt has started its turn or left the queue, input queued after it is someone else's, such as a prompt sent without --wait or 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.
  • A turn counts as queued input's only when a dequeue took 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.
  • A dequeue doesn'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 (turnOrigin human: 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.
  • It goes by the order of the file, not by timestamps. A turn ends at stop_hook_summary, an API error message or the interruption marker.
  • When a completion has settled, the wait reads the conversation once more and returns only when nothing of the operator's is pending. While something is, it reads again about once a second.
  • An interruption that a queued turn follows no longer ends the wait, since that turn is the prompt's. The tracker reports both, and the wait decides.
  • The upgrade checklist in agentctl/docs/harness-upgrades.md gets 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::transcript and cargo test -p agent --test integration prompt_wait

At "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:

assertion `left == right` failed: queued behind the essay
  left: "----------"
 right: "-qqqqqqq--"
prompt_wait_follows_a_prompt_queued_behind_the_running_turn: the running turn was interrupted, and the queued prompt's turn follows

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:

  • "test(agentctl): pin that input sent after the waited prompt's turn started does not hold the wait": "-qqqqqq" against "-------".
  • "test(agentctl): pin that a prompt queued behind a turn started just before the mark is followed": "---------" against "-qqqqqqq-".
  • "test(agentctl): pin that input sent after a pasted multi-line prompt's turn started is not followed": "-qqqqqq" against "-------".
  • "test(agentctl): pin that a prompt queued above the line of the turn ahead of it is followed": "qqqq-----" against "qqqqqqqq-".
  • "test(agentctl): pin that a prompt queued while the turn ahead's hooks run is followed": "-----" against "qqqq-".
  • "test(agentctl): pin that a prompt queued while a typed slash command's hooks run is followed": "-----" against "qqqq-".

At the head, "fix(agentctl): take only a dequeued turn for queued input's", make fmt lint build test passes. 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-desktop running Claude Code 2.1.321 on Haiku. Times are when the wait returned, by the host's clock, and when the turn's stop_hook_summary was written, by the agent's.

A first prompt is sent without --wait, then the second with --wait while the first is answered:

Case main (84e4878) This pull request, at the head
A 400-word essay, then "Write a 120-word paragraph about otters" 3 s later Returns early 3 of 3. turns --last 1 shows 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. Returns about 0.6 s after the queued turn ends, and turns --last 1 shows the answer.
A UserPromptSubmit hook that takes 3 s, an essay, then "Reply with exactly THIRD" 1 s later. Claude Code writes the second prompt's enqueue without its text. Returns about 0.6 s after the queued turn ends, 2 of 2, and turns --last 1 shows 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

  • Input Claude Code takes from the queue and then writes nothing at all about would keep the wait going to its timeout. Today such a wait returns before the prompt is answered. A queue operation the tracker doesn't know, and any line after a turn's end other than a turn's start, end the wait early instead, as today.
  • Each settled Claude Code completion costs one more read of the transcript, of the bytes added since the last read.
  • Two cases still end the wait early, as main does, and both need a prompt sent within the UserPromptSubmit hooks 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.
  • A prompt sent without --wait and queued just before the waited one may be answered in a turn of its own. The tracker may then end with that turn.
  • A prompt whose turn starts at once is known as the prompt's by its text. One Claude Code writes in a form the comparison doesn't undo, such as with its accents normalized, isn't, and input queued behind its turn then holds the wait until that input's turn ends. The wait returns late, not early.

Follow-ups

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7a781b2c-26a5-49e2-9728-3b293ffb8258

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@olebhansen-agent

olebhansen-agent commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

@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 enqueue without its text, and the tracker passed over it.

Waiting for you

Two cases the red team found still end the wait early, as main does today. Both need a prompt sent within the UserPromptSubmit hooks of the one ahead, which agentctl's own hooks keep short. Neither was seen live. The red team wrote a failing test for each, which is not on this branch. Say whether to leave them, which I would, or to handle them here:

  • The same text sent twice. The waited prompt follows the same text sent just before without --wait. Its lines are the same as those of the waited prompt typed with someone else's input sent during its hooks, which main gets right and this pull request does too. One of the two has to give, and the tracker keeps what main does.
  • A notification queued ahead of the prompt. A turn for Claude Code's own input drops input queued without its text, which was the prompt here. Telling them apart needs a count of Claude Code's own queued input as well. If that count went wrong, the wait would hold to its timeout instead of ending early.

Decided on your behalf

  • A slash command Claude Code doesn't know, or any other line after the turn's end that isn't a turn's start, ends the wait. The alternative is to wait for a turn that may never come, up to the 30-minute timeout. So a format change in Claude Code makes the wait end early, as it does today, rather than hang.
  • Only a turn Claude Code marks turnOrigin human, after a dequeue, is the operator's queued input's. Scheduled prompts (cron, /loop) and input from a peer or a channel count as Claude Code's own.
  • The tracker knows the prompt by its text when the order of the file can't tell. The challenger argued for dropping that and following all input queued after the mark. That would make the wait follow someone else's later turn in a case main gets right, so it stays. The comparison doesn't normalize Unicode, which would need a new dependency. It removes U+200B, which nothing tests. Claude Code 2.1.321 strips zero-width characters in several places, but no recorded line shows it in a prompt. A prompt it doesn't recognize makes the wait return late, never early. The upgrade checklist now has a row for it.

Checks

  • Build, challenger: two rounds on 17cd788. It withdrew its main objection and found nothing open. Its rename and checklist row are in 0b8761d and 0d5a337.
  • Build, red team: two rounds. The first, on 0d5a337, found the prompt sent during the hooks of the one ahead, live with Claude Code 2.1.321 3 of 3. The second, on 51f3426, found the fix sound, every rule caught by a test when broken, and the two cases above.
  • Build, QA: accepts 51f3426. It reproduced each test commit failing on its assertion, and its one low finding is the U+200B rule above.
  • In use: at 51f3426. See the description.
  • CI: passed on 51f3426, including the macOS, Windows and end-to-end jobs.
  • Test, challenger and QA: not run yet. CodeRabbit has not reviewed it. A later run does both once you have answered above.
  • Not run locally: macOS and Windows, which CI covers. The change reads the transcript inside the Linux sandbox on every host.
  • This pull request can't merge before fix(agentctl): end prompt --wait when a Claude Code turn is interrupted #586.

@olebhansen-agent

Copy link
Copy Markdown
Collaborator Author

Rebased on the new head of #586, which is rebased on main. No conflicts in this pull request's own commits.

olebhansen-agent and others added 7 commits November 23, 2026 21:08
…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>
olebhansen-agent and others added 5 commits November 23, 2026 21:08
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>
olebhansen-agent and others added 2 commits November 23, 2026 21:50
… 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>
olebhansen-agent and others added 2 commits November 23, 2026 21:54
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Let CI run, even for draft

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant