Repository navigation
Stop PermissionRequest/blocked/waiting hook states from firing agent-task-complete - #6540
Conversation
…task-complete 'waiting' (e.g. a Claude PermissionRequest) and 'blocked' (e.g. a Copilot elicitation dialog) occur mid-turn while the agent is still alive, yet isCompletionHookState treated them as completion and dispatched a false agent-task-complete. Restrict completion to a genuine 'done' and add an isAttentionHookState early return that also cancels a pending done-quiet timer when an attention pause arrives first. The 'needs you' notification for these states is raised separately (smart-attention), so it is unaffected. Fixes #5698
📝 WalkthroughWalkthroughA new 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
🧒 ELI5 — for your merge decisionWhen Claude asked for permission mid-task (a "PermissionRequest" hook), Orca wrongly fired an "agent task complete" notification, so you'd get a false "done" ping while the agent was actually still waiting on you. This PR makes completion fire only on a genuine finish, and cancels a pending "done" if a waiting/blocked state arrives first. What you'll notice: No more false "agent finished" notifications when an agent pauses for a permission prompt mid-task. Real completions still notify once. Behavior change Behavior change is the fix itself: 'waiting'/'blocked' states no longer count as completion. Real completions still fire exactly once after the quiet window. Scoped to the completion-coordinator logic; no setting, no user action. Merge risk: low Auto-generated summary to aid review. Reproduction + lint/typecheck/test evidence is in the PR body / checks. This PR was produced and independently reviewed by an automated bug-bash; please verify before merging. |
|
Thanks for the fix. I added a maintainer follow-up so PermissionRequest/blocked/waiting states no longer fire false completion notifications, but still raise the needs-input attention notification for Claude-style permission waits. Validated with targeted tests, typecheck/lint, and Electron validation of a Claude waiting state. |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 88f5536f-30ac-4690-9db7-7265b22d9090
📒 Files selected for processing (6)
src/renderer/src/components/terminal-pane/agent-completion-coordinator-types.tssrc/renderer/src/components/terminal-pane/agent-completion-coordinator.test.tssrc/renderer/src/components/terminal-pane/agent-completion-coordinator.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/hooks/agent-hook-completion-notifications.test.tssrc/renderer/src/hooks/agent-hook-completion-notifications.ts
| function isAttentionHookState(state: ParsedAgentStatusPayload['state']): boolean { | ||
| // Why: 'waiting' (e.g. a Claude PermissionRequest) and 'blocked' (e.g. a | ||
| // Copilot elicitation dialog) pause mid-turn — the agent is still alive and | ||
| // has not completed, so they must not fire agent-task-complete. The "needs | ||
| // you" notification for these states is raised separately (smart-attention). | ||
| return state === 'waiting' || state === 'blocked' |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Don't make blocked globally non-terminal.
The linked objective explicitly says blocked should only skip completion when it means “waiting for user.” This helper now routes every blocked payload through the attention path, so any agent that uses blocked as a terminal/failure state will never emit agent-task-complete. Gate blocked on agent-specific semantics or an explicit “needs user input” signal instead.
| let lastCompletedTurn: number | null = null | ||
| let lastCompletionSource: CompletionSource | null = null | ||
| let lastCompletionIdentity: LastCompletionIdentity | null = null | ||
| let lastAttentionToken: string | null = null |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Attention dedup resets on live coordinator recreation.
lastAttentionToken is instance-local, but this file already preserves completion dedup across live remounts because hook snapshots can be replayed on activation/switching. Recreating the coordinator while a pane is still waiting/blocked can therefore dispatch the same attention notification again. Mirror the pane-key-scoped completion dedup if this spam guard is meant to survive remounts too.
Also applies to: 277-290
…task-complete (stablyai#6540) * Stop PermissionRequest/blocked/waiting hook states from firing agent-task-complete 'waiting' (e.g. a Claude PermissionRequest) and 'blocked' (e.g. a Copilot elicitation dialog) occur mid-turn while the agent is still alive, yet isCompletionHookState treated them as completion and dispatched a false agent-task-complete. Restrict completion to a genuine 'done' and add an isAttentionHookState early return that also cancels a pending done-quiet timer when an attention pause arrives first. The 'needs you' notification for these states is raised separately (smart-attention), so it is unaffected. Fixes stablyai#5698 * Preserve attention notifications for waiting hooks --------- Co-authored-by: brennanb2025 <[email protected]> Co-authored-by: Neil <[email protected]> (cherry picked from commit 211138e)
…task-complete (stablyai#6540) * Stop PermissionRequest/blocked/waiting hook states from firing agent-task-complete 'waiting' (e.g. a Claude PermissionRequest) and 'blocked' (e.g. a Copilot elicitation dialog) occur mid-turn while the agent is still alive, yet isCompletionHookState treated them as completion and dispatched a false agent-task-complete. Restrict completion to a genuine 'done' and add an isAttentionHookState early return that also cancels a pending done-quiet timer when an attention pause arrives first. The 'needs you' notification for these states is raised separately (smart-attention), so it is unaffected. Fixes stablyai#5698 * Preserve attention notifications for waiting hooks --------- Co-authored-by: brennanb2025 <[email protected]> Co-authored-by: Neil <[email protected]>
Fixes #5698
Root cause
isCompletionHookStateinsrc/renderer/src/components/terminal-pane/agent-completion-coordinator.tsreturnedtruefor'done' || 'waiting' || 'blocked'. But'waiting'(e.g. a Claude PermissionRequest) and'blocked'(e.g. a Copilot elicitation dialog) are mid-turn states — the agent is still alive and has not completed. Treating them as completion made the coordinator dispatch a falseagent-task-completenotification on every permission prompt / tool pause.The "needs you" attention notification for
waiting/blockedis raised on a separate path (smart-attention.ts/notifications.ts), so it was already covered — the coordinator was double-counting these states as completions.Change
isCompletionHookStatenow matches only a genuine'done'.isAttentionHookState('waiting' | 'blocked') handled by an early return inobserveHookStatusthat cancels any pending done-quiet timer (clearPendingHookDone()), so a pause arriving before the 1.5s quiet window can never resolve into a false completion. Recognized-agent evidence is still established at the top ofobserveHookStatus, so attention states keep updating agent identity.waitingmid-turn -> 0 completions;blockedmid-turn -> 0 completions;done-then-waiting-before-quiet-window -> pending done cancelled, 0 completions. (Replaces the old test that asserted the buggy 2-dispatch behavior.)Confined to
agent-completion-coordinator.ts+ its test. No change to the separate attention-notification path.Evidence
Regression tests FAIL before the fix (against unmodified source)
After the fix — full coordinator suite + downstream notification suites PASS
Lint (changed files clean)
Typecheck (clean)
Re-implements the approach of community PR #6316 (rodboev), with a broader test run (full coordinator + downstream notification suites) and added "Why:" comments.