Skip to content

Suppress stale agent completion replay after new work - #5620

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/notification-replay-after-working
Jun 17, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/notification-replay-after-working

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • keep hook-backed completion identities durable when a new hook working event starts
  • suppress stale same-agent title/hook completion replays after the user sends another message and then switches worktrees/windows
  • add regression coverage that still allows a genuinely new hook completion with a different stateStartedAt

What changed, concretely

This is not a remote-only notification bug. The relevant code is shared terminal lifecycle code. connectPanePty creates one agentCompletionCoordinator per pane, feeds it terminal title changes (onTitleChange -> observeTitle) and explicit idle events (onAgentBecameIdle -> observeClassifiedTitleCompletion), and reattach/attach paths can write replayed terminal output through onReplayData.

The June 2026 terminal lifecycle work made Orca preserve and adopt live terminal sessions across inactive/background panes more aggressively. Two concrete examples in the history:

  • 178b9bde8 (Fix automation tabs showing a shell instead of the live agent) changed first-mount/background local PTY handling so a still-live local agent PTY with an eager buffer is adopted via attach()+replay instead of spawning a fresh shell. That is local, not remote.
  • 36277801e (Make remote hosts first class: concurrent multi-host workbench) expanded the same shared terminal ownership/reattach/runtime paths for multi-host/remote work. Local and remote panes both still flow through pty-connection.ts and the same completion coordinator.

Those changes are generally correct: they keep background agents and remote/local terminal sessions alive through worktree switches, remounts, and reattach. The notification bug was that replayed/rehydrated terminal state could include the old completed state/title (Codex done).

How we missed it

PR #5572 fixed the simple replay case: old completion notifies, pane remounts/switches, same completion replays, suppress it.

It missed the sequence the user reported:

  1. Codex finishes and Orca notifies.
  2. User sends another message, so a hook-backed working event starts the next turn.
  3. The old implementation deleted lastCompletionIdentityByPaneKey during that hook working.
  4. User switches worktrees/windows; old hook/title state replays.
  5. Because the old completion identity had been deleted, the stale Codex done replay could dispatch a second “Codex finished” notification before the new turn actually finished.

Why this fix is correct

Hook-backed working still starts a new turn, cancels provisional hook done, and clears pending title state. It no longer deletes the durable previous completion identity. That means stale old hook/title replays still compare against the previous completion and are suppressed. A real new completion is still allowed because hook completions carry a different stateStartedAt, so their completion identity is different.

Verification

  • Before/after proof in a temp worktree:
    • parent commit + only the new regression tests: agent-completion-coordinator.test.ts failed in both replay-after-working cases (got 2 notifications instead of 1)
    • parent commit + tests + PR production change: same suite passed (41 passed)
  • pnpm test src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts src/renderer/src/hooks/agent-hook-completion-notifications.test.ts
  • pnpm test src/renderer/src/components/terminal-pane/use-notification-dispatch.test.ts
  • pnpm exec oxlint src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts
  • pnpm run typecheck:web

Note: commands warn that this shell is Node 26 while the repo asks for Node 24, but the checks passed.

@ghost

ghost commented Jun 17, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 2 individual chapters for you:

Title
1 Maintain durable completion identities during new work
2 Verify suppression of stale agent completion replays
Open in Stage

Chapters generated by Stage for commit 798de1d on Jun 17, 2026 7:13pm UTC.

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/notification-replay-after-working branch from 9ba2846 to 798de1d Compare June 17, 2026 19:12
@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

In createAgentCompletionCoordinator, the title-working handling path is changed to clear the coordinator instance's lastCompletionIdentity field rather than deleting the pane-keyed entry from the module-level lastCompletionIdentityByPaneKey map. Two new tests are added covering: (1) replay of the same hook done snapshot after a fresh working transition being suppressed, with a subsequent distinct prompt still dispatching; and (2) the same suppression when fresh work is introduced via hook-backed working followed by a observeClassifiedTitleCompletion, ensuring only the next distinct done prompt triggers a new dispatch.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: suppressing stale agent completion replay after new work starts, which is the core fix in this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering the issue, concrete changes, root cause analysis, and verification steps.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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 and usage tips.

@Jinwoo-H
Jinwoo-H merged commit 9b96fd3 into main Jun 17, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/notification-replay-after-working branch June 17, 2026 19:49
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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

Development

Successfully merging this pull request may close these issues.

1 participant