Skip to content

fix(pause): card replies always reach the agent; the server asks on the card for user-only steps - #494

Open
AmrDab wants to merge 4 commits into
mainfrom
fix/card-replies
Open

AmrDab wants to merge 4 commits into
mainfrom
fix/card-replies

Conversation

@AmrDab

@AmrDab AmrDab commented Nov 29, 2026

Copy link
Copy Markdown
Owner

What

Three changes to the pause card (system action pause_for_user). One commit each, plus a follow-up:

  1. A reply on the card always reaches the agent (fix). An answer the user gives while no tool call is waiting for it is handed over ONCE. It goes to a re-call of that pause, or to the session's next tool call (any tool), whichever comes first. Typed text is no longer lost when Resume or a choice is clicked.
  2. The server opens the card for steps only the user can do. When a call is refused with SECURE_INPUT, KEYBOARD_OWNED, SCREEN_LOCKED or CAPTURE_DENIED, clawdcursor opens the card itself with its own text. It returns the answer in the same result, next to the refusal.
  3. The pill says the agent stopped. When the agent goes quiet after acting, the pill shows agent stopped · its message is in your chat for 10 s before it hides.

Why

A live Windows run with a Sonnet agent had two failures:

  • The agent asked its question in the CLI chat instead of the card, while the user was watching the screen.
  • The user typed a reply on the card, and the agent never saw it.

The code showed why:

  • Replies were thrown away. finish() kept an outcome only for a re-call of the SAME key within 5 minutes. The key was message + choices + input. Nothing else read it, so a reply was dropped when the agent moved on, ended its turn, reworded its re-call, or had its call cancelled by the host. The handler also ignored the abort signal.
  • Button clicks dropped typed text. banner.ps1 / overlay.swift dropped the text in the box when Resume or a choice was clicked.
  • The card depended on the model. Every route to the card was prose the model had to follow. Only confirm mode opened the card from server code.
  • The wait message pointed to the chat. The waiting next-text ended by steering to chat.

How

  • pause-gate.ts:
    • Each pending pause counts the calls awaiting it.
    • A call stops counting when its bound runs out or the host aborts (detach). The MCP extra.signal is threaded through asPauseOwner.
    • An answered outcome (replied / chose / Resume / End task) that settles with no one awaiting is kept for the owner session until it is delivered or the session closes.
    • takeSettled(owner) hands it over once. pause.reply_delivered and pause.reply_dropped are logged, without text.
  • mcp-server.ts: prepends one line per kept answer to the next result. For example: The user answered your question on the clawdcursor card ("…"): "…". The user's words are quoted as theirs, not as screen text.
  • agent.ts:
    • The re-attach key is the message alone, so a reworded re-call finds the open card.
    • busy echoes the card's choices and input.
    • The waiting text now leads with the re-call, and no longer points to chat.
    • The "ask in your own chat" line for when no overlay is available is unchanged.
  • banner.ps1 / overlay.swift: Resume with text sends the text; a choice with text sends <choice>: <text>; End task is unchanged. CI compiles scripts/mac/*.swift.
  • refusal-card.ts (new):
    • The server-written card for the four codes.
    • It waits for what is left of 45 s since the call began (at least 1 s), so call plus card stay under a host's ~60 s limit.
    • It never opens a second card, and opens nothing under the bench fence or with the overlay off.
    • It says plainly that the server asked, not the model.
  • Not included:
    • USER_ACTIVE / PAUSED / STOPPED: the user already has the desktop.
    • CLIPBOARD_HELD.
    • DANGEROUS_KEY: its card text is the agent's to write.
    • A password-field refusal: it has no result code and shares its text with "field not found". That's a separate change.
  • banner.ts: after the 30 s idle, if the agent acted since the last hide and no pause is pending, the pill shows the note on its waiting line for 10 s. Any call ends the note. There is no glow and no outline; the pill rules are unchanged.

Tests

  • pause-reply-delivery.test.ts (9):
    • the reply is delivered once on another tool's next result;
    • a reworded re-call takes it;
    • a host-cancelled call's answer is delivered later;
    • no double delivery, and dropped with its session;
    • logs without text.
  • refusal-card.test.ts (12):
    • each code opens the card and answers in the same result;
    • typed answer, End task, still-waiting then re-call;
    • the wait is bounded by the call's remaining time;
    • no second card; nothing under the fence or with the overlay off;
    • excluded codes.
  • banner.test.ts (+6): the stopped note and its edge cases, plus Send-Click run in real Windows PowerShell.
  • pause-card.test.ts: the old "different options = different question" test is replaced by re-attach + busy-echo tests.

typecheck, typecheck:tests, lint (0 errors, the 3 warnings as on main), npm run test:ci: 4322 passed, 3 failed, 80 skipped. The 3 failures are repo-invariants, telemetry (daily cap) and user-turn (shared budget). All three pass when run on their own (92/92) and are not touched here; the full run was on a heavily loaded machine.

Limits

  • The server never sees the model's chat and gets no "turn ended" signal from MCP. A reply typed after the agent's turn ended reaches it on its NEXT tool call, not before.
  • Questions the server can't detect still depend on the model calling pause_for_user. The pill note tells the user to look at the chat.

No release: for the 2.4 train.

🤖 Generated with Claude Code

AmrDab and others added 4 commits November 28, 2026 20:58
An outcome that settles while no tool call is waiting for it (the call was told
"waiting", the agent moved on, or the host cancelled the call) is kept for the
session that asked and handed over once: to a re-call of the pause, or ahead of
that session's next tool call, whichever comes first. A re-call matches the
pending or settled pause by message alone. The tool call honours the host's
abort signal. A reply with nothing pending is logged (pause.reply_dropped).
Resume or a choice clicked with text in the card's box (Windows and macOS)
sends the text too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a call ends in a refusal only the user can clear (macOS secure input, a
system dialog holding the keyboard, a locked screen, a denied Screen Recording
permission), the server opens the pause card itself with its own text, waits up
to 45 s, and returns the answer in the same result next to the refusal, so the
agent retries the step. If the user is still busy the result says how to keep
waiting (pause_for_user with that message re-attaches). No second card opens
over a pending one, and none under the test fence. The pause_for_user "waiting"
text now leads with the instruction and no longer points at the chat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the pill has been idle for 30 s after a tier-1+ act, it now says "agent
stopped · its message is in your chat" for 10 s before it hides. It uses the
pill's own activity line (small fixed width, marquee), with no glow and no
outline. Nothing is shown when no act happened since the last hide, or while a
pause is pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s time

A host limits a tool call to about 60 s. The refusal card waited a fixed 45 s after
the handler had already run, so a slow refusal plus the card could pass that limit.
It now waits for what is left of 45 s since the call began (at least 1 s), then says
how to keep waiting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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