Skip to content

Agent state: an approved long-running tool is served as needs-input until the tool completes #1851

Open

Description

@amrmelsayed

Summary

Found during #1595 Phase 8 real-session verification. After the operator approves a permission prompt for a long-running tool, the served agent state stays needs-input until the tool completes, because Claude Code fires no hook on approval; the next lifecycle event is PostToolUse when the tool ends. Measured: approved at 07:57:22, a 5.5-minute tool, needs-input served until 08:02:55.

This matches #1595's SC3 as written ("within 5 s of the approved tool completing") and is documented behaviour in that lane. It is still a false "needs input" for the whole run, visible on every attention surface, for any session that raises permission prompts (default permission mode; sessions launched with the skip-permissions flag never prompt, so most codev builders and architects do not hit it).

Candidate design (not decided)

The spike behind #1595 established that the TUI repaints its elapsed-time counter every second during a running foreground tool, while the screen is static at a permission prompt. So served needs-input plus PTY output fresher than about 3 s is evidence the prompt was answered and the tool is running. The sdk classifier could downgrade needs-input to working only while that freshness holds; a one-off output blip (a resize, a delivered message) would clear it for a few seconds and then needs-input returns.

This fuses a PTY signal back into a harness-reported state, which #1595 deliberately avoided, so it needs a conscious decision rather than a late patch:

  • it changes SC3's semantics and the needs-input row's meaning;
  • flicker on output blips must be bounded and verified in a real session;
  • the question tool is unaffected (answering completes the tool, so PostToolUse fires at once).

Alternative: leave as documented behaviour and revisit if the harness gains an approval hook.

Acceptance (if taken)

Activity

  1. added
    area/tower
    on Oct 21, 2026
  2. amrmelsayed commented on Oct 21, 2026

    @amrmelsayed
    CollaboratorAuthor

    Status from the #1595 lane (PR #1854): this stays open. #1854 ships it as a documented limitation (review doc Known Limitations, arch.md Agent State). Below: why the hook set can't close it, and the options worth exploring.

    Why hooks alone can't fix it

    Measured hook timeline around a permission prompt (Claude Code 2.1.289 and 2.1.306):

    Moment Hook
    Tool about to run PreToolUse
    Prompt drawn PermissionRequest (~10 ms later), Notification(permission_prompt) ~6 s later
    Operator approves none
    Tool completes PostToolUse
    Turn ends Stop

    Options to explore

    1. Composer/prompt-pane detection (preferred direction to evaluate). Rather than generic PTY freshness, look for positive evidence that the permission pane is gone. The render-gate work (tower: render-gate composer misclassification wedges delivery for minutes on a live session (busy holds never escalate) #1590, the Tower/afx: one sent message re-injected into a builder prompt dozens of times (byte-identical re-delivery loop), plus same-day truncation and stuck-composer incidents #1583 family) already models the composer region. "needs-input reported, prompt pane no longer on screen" is a stronger signal than "output is fresh", and it is the same screen model the delivery gate wants, so the two efforts could share it.
    2. PTY-freshness downgrade (the candidate in the body). Cheapest. The risk is asymmetric: a false working hides a real prompt, which is worse than today's false needs-input. Any version needs:
      • a minimum continuous-output window (not a single blip);
      • a test that an unanswered prompt survives resizes and delivered messages;
      • real-session measurement of how often the prompt pane itself repaints.
    3. Upstream approval signal. Re-spike each Claude Code release for a hook that fires on a permission decision or on tool start after approval. If one appears, it maps to tool-activity in the reporter with no Tower, contract or sdk change, and supersedes options 1 and 2. Worth raising as a harness feature request.
    4. Transcript evidence (verify first). Agent attention states (working / needs-input / idle / dead) from harness lifecycle hooks instead of PTY-silence inference #1595 rejected transcript tailing as a transport, but a narrow check might still help: does the session transcript record anything at approval time, before the tool_result? Unverified. If it records nothing until completion, drop this option.
    5. Presentation-only mitigation. Keep needs-input but show elapsed time since the prompt, plus "may be running" when output is fresh. The served state stays honest and the operator can judge. Cheap fallback if 1 to 3 don't pan out.

    Out of scope regardless

    The question tool is unaffected: answering completes the tool, so PostToolUse fires at once. Sessions launched with the skip-permissions flag never prompt, so this affects default-mode sessions only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tower

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions