Skip to content

fix(agent-completion): stop PermissionRequest hooks from firing false completion notifications - #6316

Merged
nwparker merged 3 commits into
stablyai:mainfrom
rodboev:pr/fix-permission-request-completion
Jul 3, 2026
Merged

nwparker merged 3 commits into
stablyai:mainfrom
rodboev:pr/fix-permission-request-completion

Conversation

@rodboev

@rodboev rodboev commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes #5698 (P1): Claude/Devin/Kimi/Copilot PermissionRequest hooks were firing false agent-task-complete notifications, because the completion coordinator treated the waiting (PermissionRequest) and blocked (Copilot elicitation) states as completion signals.

The source fix for this bug has already landed on main. isCompletionHookState now returns 'done' only, and a dedicated isAttentionHookState routes waiting/blocked through dispatchAttention (which cancels any pending quiet-window done timer) instead of the completion path. main additionally gained a shouldSuppressHookCompletion layer that hardens the same seam. Issue #5698 is closed.

What remained missing was positive-path regression coverage. The existing suite proves waiting/blocked do not complete (the negative direction), but nothing proved that a genuine done still completes after an intervening permission pause in the same turn. That is the exact real-world flow from the bug report (agent pauses for a permission prompt, user approves, agent finishes) and the scenario most at risk of being broken by an over-correction of the fix.

This PR (now scoped to test-only) adds that guard:

  • working → waiting → working → done dispatches attention exactly once (for the pause) and completion exactly once (for the genuine finish).

Takeover note: the original ~33-line diff already reduced to a single test because the source change merged separately. This branch merges current main, keeps the author's test, and polishes it to also assert the attention dispatch — matching the sibling tests in the file that assert on both the completion and attention paths.

Evidence

Failing under the pre-fix bug (temporarily reverting isCompletionHookState to include waiting/blocked and disabling isAttentionHookState, simulating June behavior):

FAIL > still dispatches completion on done after an intervening waiting state in the same turn
AssertionError: expected "vi.fn()" to be called 1 times, but got 2 times
  1543|     expect(dispatchCompletion).toHaveBeenCalledTimes(1)
Test Files  1 failed (1)
      Tests  3 failed | 54 skipped (57)

The mid-turn waiting fires a false completion (call #1) on top of the real done completion (call #2) — exactly the #5698 symptom.

Passing on main + this test (fix restored):

Test Files  1 passed (1)
      Tests  57 passed (57)
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts — 57 passed
  • pnpm run typecheck — clean (node + cli + web)
  • oxlint + oxfmt --check on the touched file — clean

ELI5

When Claude stops to ask "can I run this command?", that's the middle of a job, not the end. The app used to ding you with "task complete!" every time it asked. That bug is already fixed. This change adds a safety net that makes sure the fix didn't go too far: after Claude asks permission, you approve, and it actually finishes — you should still get exactly one "done" ding. The test proves you do.

Trade-offs

  • No behavior change / no regressions. This is a test-only addition on top of an already-merged fix. It adds no runtime code.
  • The broader product decision (whether waiting/blocked should raise their own distinct "needs attention" notification instead of only the inline sidebar indicator) remains out of scope — that would be a new notification category with its own settings and throttling.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The coordinator now treats only done as a completion hook state and treats waiting and blocked as attention states. When an attention state arrives, pending hook-done quieting is cleared and the handler returns early. Tests cover mid-turn waiting and blocked transitions, plus cancellation of a pending done timer when waiting arrives before the quiet window ends.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR explains the fix, but it misses most required template sections: Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Add the missing template sections with a concise summary, screenshots or no visual change, test checklist, AI review, security audit, and notes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main fix to agent-completion notifications.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 force-pushed the pr/fix-permission-request-completion branch from a7cbe5b to e6eaf82 Compare June 30, 2026 01:01
nwparker and others added 2 commits July 3, 2026 12:30
…aiting

Wire dispatchAttention into the done-after-waiting regression test so it
verifies both halves of the stablyai#5698 fix: the mid-turn permission pause
surfaces as attention exactly once, and the later genuine 'done' still
completes exactly once. Matches sibling tests that assert on both paths.

Co-authored-by: Orca <[email protected]>
@nwparker

nwparker commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Takeover + validation summary

I took over this PR, screened it, verified it against current main, and pushed a polish commit. Not merging — leaving that to a human.

Verdict: VALIDATED (reduced scope: test-only).

  • Security screen: clean. The diff is a single test-file addition — no source, IPC, filesystem, network, dependency, or CI changes; no obfuscation or injection.
  • Validity: the source fix described in the original PR body already landed on main — isCompletionHookState returns 'done' only, waiting/blocked route through isAttentionHookState/dispatchAttention, and main further added a shouldSuppressHookCompletion hardening layer. Issue [Bug]: Claude PermissionRequest hook dispatches "agent-task-complete" notification while agent is still waiting on user #5698 is closed. So the remaining, still-valuable delta is a positive-path regression test: the existing suite covers "waiting/blocked don't complete" but nothing covered "a genuine done still completes after an intervening permission pause in the same turn" — the exact bug-report flow.
  • Reproduced first: reverting the source to the pre-fix behavior makes the new test fail (dispatchCompletion called 2×: the false completion on waiting + the real one on done) — proving it's a real guard, not a tautology. Restoring the fix makes all 57 tests pass.
  • Polish: merged current main; wired dispatchAttention into the test and asserted it fires exactly once, so the test now verifies both halves of the fix (attention surfaces, completion still fires), matching the sibling tests' conventions.

Checks: vitest 57/57 passed · pnpm run typecheck clean · oxlint + oxfmt clean on the touched file · code-review (high) returned no findings.

Trade-off: test-only, no runtime behavior change, no regressions.

@nwparker
nwparker merged commit 1fd9547 into stablyai:main Jul 3, 2026
@nwparker

nwparker commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Merged — this passed our review bar. @rodboev thanks for the contribution! The runtime fix had already landed on main by the time we reviewed, so we kept your regression test (polished to also assert the attention dispatch) as a permanent guard for #5698.

@nwparker

nwparker commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Thanks again, @rodboev. Even with the underlying fix already on main, keeping your regression test to lock in "a permission pause still yields exactly one completion" is well worth it — that's exactly the kind of guard that saves a future headache. Merged!

@nwparker

nwparker commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Thanks Rod 🙏 By the time we reviewed, the runtime fix had already landed — but your regression test earns its keep by proving a permission pause still ends in exactly one real completion. Good tests outlive the bug that inspired them. Grateful for it. 🐋

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… completion notifications (stablyai#6316)

* test(agent-completion): cover done after waiting pause

Co-authored-by: Orca <[email protected]>

* test(agent-completion): assert attention fires alongside done-after-waiting

Wire dispatchAttention into the done-after-waiting regression test so it
verifies both halves of the stablyai#5698 fix: the mid-turn permission pause
surfaces as attention exactly once, and the later genuine 'done' still
completes exactly once. Matches sibling tests that assert on both paths.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: brennanb2025 <[email protected]>
Co-authored-by: Orca <[email protected]>
Co-authored-by: Neil <[email protected]>
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.

[Bug]: Claude PermissionRequest hook dispatches "agent-task-complete" notification while agent is still waiting on user

3 participants