agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

[Bug]: Generic tool hooks can leave Summary Activity stuck on Input needed after approval

Open LaibaFirdouse opened this issue 1 month ago • 1 comments

Bug

In Summary → Activity, a session can remain Input needed for many minutes after a tool approval, and some harnesses can enter that status for ordinary tool use that does not require user input. waiting_input and blocked are intentionally sticky; blocked has a correlated-tool completion path, but generic pre-tool callbacks are classified as waiting_input, which does not clear on ordinary post-tool activity. For adapters without a distinct approval-resolution signal, the state may persist until a recognized resume or turn-boundary event.

Code-path confidence: High - the callback mappings and sticky-state behavior are present in current upstream source.

Priority: P2 - session status and related automated behavior can be misleading or degraded, but the session can continue and a later recognized signal can clear it.

Reproduction

The source-level path to check is:

  1. Start a session using Copilot, Cline, or Kiro etc and ask it to run a tool.
  2. Observe Summary → Activity when the harness emits its pre-tool callback; those adapters route it to AO's permission-request event.
  3. Allow the tool (or use a tool invocation that does not require an approval decision), then let the agent continue without ending the turn.
  4. Check whether Activity remains Input needed after work resumes, until a later recognized resume/turn signal arrives.

Droid is a related potential false-positive path: its Notification hook has no type discriminator, so every notification maps to waiting_input, including its idle notification. Exact occurrence may vary by harness and approval mode.

Expected: Input needed is shown only while user input or a pending approval is genuinely required, and an observed approval/resumption clears it without waiting for the whole turn to finish.

Actual: The reported status can remain after approval, and broad pre-tool/notification callbacks can classify work as waiting for user input even when no user decision is needed.

Root Cause

  • backend/internal/adapters/agent/activitystate/activitystate.go:11-35 maps permission-request to ActivityWaitingInput without examining the hook payload.
  • Copilot maps every preToolUse to permission-request (backend/internal/adapters/agent/copilot/hooks.go:76-86). Cline does the same for PreToolUse (backend/internal/adapters/agent/cline/hooks.go:60-74), as does Kiro for preToolUse (backend/internal/adapters/agent/kiro/hooks.go:58-71). Thus the event may describe an approval opportunity, not proof that user approval is required.
  • backend/internal/domain/activity.go:28-40 makes both waiting_input and blocked sticky and maps both to the needs_input status. In backend/internal/lifecycle/manager.go:1385-1388, generic tool-use activity cannot demote a sticky state; blocked additionally requires a correlated completed tool or safe turn boundary (manager.go:1244-1249,1349-1382).
  • Droid maps every notification to waiting_input (backend/internal/adapters/agent/droid/activity.go:20-38) because the payload does not distinguish permission-needed from idle notifications.
  • Cursor is not currently the same generic mapping: current upstream installs before/after execution hooks and evaluates permission mode (backend/internal/adapters/agent/cursor/hooks.go:113-125; backend/internal/adapters/agent/cursor/activity.go:41-66). Its prior sticky-activity report was #3306 and was addressed by #4495.

Fix

Audit each hook contract so an event meaning “tool is about to run” does not imply a user decision is pending. Preserve blocked for confirmed approval dialogs and its fail-closed correlated-tool/turn-boundary clearing. Add or use explicit approval-resolution/resume signals where the harness provides them; for harnesses without those signals, choose a state/mapping that does not falsely claim user input is required and define a safe fallback that cannot clear a genuine pending decision.

Impact

  • Summary Activity can mislead users about whether an agent is waiting or still working.
  • Sticky state can remain visible well beyond approval and until a recognized clearing callback arrives.
  • Code paths that suppress automation while a session needs input can delay otherwise safe automated delivery.
  • Over-classifying routine tool events as user decisions can create repeated false-positive notifications.

Related

  • #6224 — Codex Auto-review raises needs_input for approvals it handles itself; adjacent harness-specific false positive.
  • #3738 — Claude Code post-Stop agent_needs_input notification creates sticky stale state.
  • PR #6154 — proposed fix for the Claude post-Stop notification in #3738.
  • #3306 and PR #4495 — prior Cursor sticky-state issue and fix; current Cursor implementation uses a permission-aware path.

LaibaFirdouse avatar Oct 05 '26 17:10 LaibaFirdouse

Further Investigation notes:

Symptom (Copilot, same family as Cline/Kiro): Summary → Activity can show Input needed during ordinary tool use or stay sticky after approval until a clear signal arrives mainly agentStop / Cline TaskComplete / AO stop → idle, or the next userPromptSubmitted / UserPromptSubmit → active (not a vague “turn end” for every harness). RCA on current main: AO maps Copilot preToolUse → permission-request → sticky waiting_input (StandardDeriveActivityState). That is the only Copilot-managed hook that enters waiting_input; AO does not install postToolUse, and Copilot has no terminal waiting-recovery path. Same install pattern for Cline/Kiro (PreToolUse / preToolUse → permission-request). Stickiness explains the long-lived UI; the false entry is the generic pre-tool mapping (many-to-one: fires for every tool, not only human-gated ones). Cline is especially misleading after upstream cline/cline#7446 (merged 2025-11-13): when approval is required, PreToolUse runs after the user clicks Approve, so treating it as “needs you” is inverted. When auto-approve is on, PreToolUse still fires with no human prompt → ordinary false positive. That PR fixed Cline’s hook UX; it did not break Cline, but it makes AO’s permission-request mapping worse for interactive Cline sessions. Approach considered then discarded: Remap pre-tool → tool-use / active (same idea as closed, unmerged AO PR #2594). That kills false positives, but also drops Input needed for real interactive approvals when the harness only exposes this hook. Pre-tool payloads for Copilot/Cline/Kiro have no “approval pending” field. Contrast Claude (PermissionRequest + typed notifications), Cursor (AO evaluates AO_PERMISSION_MODE ask vs allow and reports blocked, with after-execution clear - #4495), Codex (native PermissionRequest; separate Auto-review sticky case #6224 / #5901). Decision: No speculative remapping-only PR for #6280 — it would make Activity worse for real approvals.

How I landed on follow-ups

We want both: (1) no false Input needed on ordinary tools, and (2) Input needed when a human really must approve. That ruled out “just remap preToolUse → active.” Option A — AO owns the gate (Cursor-like idea, different contract) On Copilot preToolUse, AO returns permissionDecision: ask | allow from session permission mode, and only then reports Input needed / working. Same idea as Cursor (#4495), different hooks: Cursor uses before-exec hooks + AO_PERMISSION_MODE and reports blocked, not waiting_input. Larger feature: changes who controls approvals, must clear correctly after approve, CLI edge cases. Valid long-term for Copilot; not a small #6280 hotfix. Cline/Kiro do not expose Copilot’s permissionDecision / permissionRequest shape (Cline PreToolUse is mainly cancel; Kiro is block-via-exit 2 / permissions.yaml UI). Option B — Observe when the human is really asked (without owning the gate) Don’t treat every pre-tool beep as permission. Set/clear Input needed from a signal that means “approval UI / elicitation is actually pending,” and treat ordinary tool traffic as active. Two shapes:

  • B (terminal / ACP): Parse the TUI for an approval dialog, and/or use Chat/ACP approval events if the session is on ACP Chat. Terminal scraping needs stable chrome + detectors; Copilot has none in AO today. ACP is a separate product surface and is not required for the Copilot hook fix below.
  • B1 (Copilot-specific, preferred for #6280): Observe, don’t own, using hooks Copilot documents and AO isn’t wiring correctly. AO’s adapter comment (citing the how-tos page) still says there is no permissionRequest event; the current hooks reference does document permissionRequest,notification (permission_prompt / elicitation_dialog, …), and postToolUse. Important nuance: permissionRequest fires before rules, session approvals, auto-allow/auto-deny, and user prompting. Empty/{} correctly falls through so AO need not own the gate — but a bare “permissionRequest fired → Input needed” can still false-positive when Copilot would auto-approve with no Yes/No. Prefer notification with permission_prompt (and maybe elicitation_dialog) as the Input needed entry signal; use permissionRequest only if we can prove UI-pending (or keep it as a no-op {} observer). Stop mapping generic preToolUse → waiting_input; install postToolUse (and/or a clear after the prompt resolves) to return to active. TUI/hook work only — no ACP Chat dependency. Cline / Kiro under Option B: They lack Copilot’s typed permission-notification surface that B1 relies on, so B1 does not transfer. Realistic path is Option B terminal (or future Chat) detection plus remapping PreToolUse/preToolUse off permission. Cline already has an active/idle terminal detector but deliberately ignores the approval fixture; Kiro has no detector yet. Cline’s post-#7446 ordering makes remapping off permission especially important for interactive sessions.

Summary

Preferred next step No PR from this investigation. Prefer Copilot B1 as the product-safe fix; treat A as a separate feature if we want AO to own the gate; treat Cline/Kiro as separate observation-based work (Cline worsened by merged upstream #7446 ordering, not caused by it alone). Cline and Kiro will be handled as separate issues/PRs.

LaibaFirdouse avatar Oct 08 '26 06:10 LaibaFirdouse