Skip to content

fix(agent-status): notify Claude turn complete while background work runs - #13251

Closed
bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:fix/claude-turn-complete-while-background
Closed

bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:fix/claude-turn-complete-while-background

Conversation

@bbingz

@bbingz bbingz commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

When a Claude lead turn ends while background subagents/shells/crons are still registered, resolveClaudePaneState keeps the pane working so the sidebar does not go grey. That also suppressed the working → done edge that mints completion notifications — turns that end by asking the user something stay silent for the whole background lifetime (or forever for background shells).

  • Stamp turnCompleteWhileBackground on lead Stop/StopFailure when inventory gates the pane to working
  • Notify immediately from that edge (sidebar stays working)
  • Suppress the later all-clear done so the same turn does not double-fire

Fixes #13245

Test plan

  • pnpm exec vitest run src/shared/agent-status-types.test.ts src/shared/agent-hook-listener.test.ts src/shared/claude-background-task-status.test.ts src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts

…runs

Lead Stop/StopFailure already ends the turn, but resolveClaudePaneState keeps
the pane working for subagents/shells/crons, so the working→done notification
edge never fires (or fires late with a stale body). Stamp
turnCompleteWhileBackground on that Stop, notify immediately, and suppress the
later all-clear done so banners are not delayed by unrelated background work.

Fixes stablyai#13245
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e5254e8e-f659-49fa-93e0-092ea58121be

📥 Commits

Reviewing files that changed from the base of the PR and between 8698754 and 8adaba0.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts
  • src/renderer/src/hooks/useIpcEvents.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts

📝 Walkthrough

Walkthrough

The change adds turnCompleteWhileBackground to agent status payloads and preserves it only for working states. Claude hook processing sets the marker when a lead turn completes while background subagents or shell tasks remain active. The completion coordinator emits an immediate synthetic completion, records its identity, and suppresses the later done notification. Tests cover payload normalization, Claude hook state transitions, and duplicate-notification prevention.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug and test plan but omits the required AI Review Report, Security Audit, Notes, and Screenshots sections. Add the missing template sections and complete the required testing checklist or explain why each unchecked test was not run.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Claude agent-status fix and the immediate completion notification behavior.
Linked Issues check ✅ Passed The changes satisfy issue [#13245] by notifying at turn completion, preserving background tracking, and suppressing duplicate all-clear notifications.
Out of Scope Changes check ✅ Passed The code and tests are limited to turn-completion status propagation and notification coordination described in [#13245].

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 45e4f012-653c-441c-a325-a79d22630ad2

📥 Commits

Reviewing files that changed from the base of the PR and between 6da7b8e and 8698754.

📒 Files selected for processing (6)
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts
  • src/shared/agent-hook-listener.test.ts
  • src/shared/agent-hook-listener.ts
  • src/shared/agent-status-types.test.ts
  • src/shared/agent-status-types.ts

…ns end-to-end

Review follow-up for stablyai#13251/stablyai#13245:
- whitelist turnCompleteWhileBackground through applyAgentStatus IPC rebuild
- forward agentStatus on non-quiet hook completions and skip lifecycle for
  the synthetic done banner so the pane can stay working
- mint a later stateStartedAt so supersession does not drop the banner
- keep suppress sticky across shell/cron intermediate working (no subagent rows)
@bbingz

bbingz commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Review follow-up (batch 4)

Addressed confirmed high/medium findings:

  1. IPC whitelist — applyAgentStatus now copies turnCompleteWhileBackground so the coordinator sees the flag on the live Claude hook path.
  2. dispatchCompletion meta — always forwards agentStatus when provided; turn-complete-while-background uses notifyWithoutLifecycle so synthetic done does not fire completion side-effects while the pane stays working.
  3. Notification supersession — synthetic done uses stateStartedAt + 1 so same-timestamp working≠done is not treated as stale.
  4. Shell/cron suppress — suppress flag stays sticky until the late all-clear done (no longer cleared on intermediate working without subagent rows).

Tests updated to assert agentStatus meta + no lifecycle done + shell intermediate path.

@bbingz

bbingz commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Closing this branch because its suppression model is incomplete for the full #13245 reproduction.

The local turnCompleteWhileBackgroundNotified boolean is cleared only by a later done. Long-lived background shells and session crons can keep the pane in working and never emit that all-clear for turn N, so the marker can survive into turn N+1 and suppress a real completion; deriving the synthetic identity from the run-pinned stateStartedAt also cannot distinguish multiple turns in one continuous working run.

#13295 and #14580 cover the broader subagent/shell/cron cases by keying announcement and late-tail suppression to each turn’s own turnCompletedAt. Keeping the fork branch intact at 8adaba079789845504969ce654e9ca4e67018379 for history while #13245 remains open pending the stronger implementation.

@bbingz bbingz closed this Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants