Repository navigation
Suppress stale agent completion replay after new work - #5620
Conversation
Co-authored-by: Orca <[email protected]>
|
Ready to review this PR? Stage has broken it down into 2 individual chapters for you:
Chapters generated by Stage for commit 798de1d on Jun 17, 2026 7:13pm UTC. |
9ba2846 to
798de1d
Compare
📝 WalkthroughWalkthroughIn 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Co-authored-by: Orca <[email protected]>
Summary
workingevent startsstateStartedAtWhat changed, concretely
This is not a remote-only notification bug. The relevant code is shared terminal lifecycle code.
connectPanePtycreates oneagentCompletionCoordinatorper pane, feeds it terminal title changes (onTitleChange -> observeTitle) and explicit idle events (onAgentBecameIdle -> observeClassifiedTitleCompletion), and reattach/attach paths can write replayed terminal output throughonReplayData.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 viaattach()+replayinstead 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 throughpty-connection.tsand 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:
workingevent starts the next turn.lastCompletionIdentityByPaneKeyduring that hookworking.Codex donereplay could dispatch a second “Codex finished” notification before the new turn actually finished.Why this fix is correct
Hook-backed
workingstill 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 differentstateStartedAt, so their completion identity is different.Verification
agent-completion-coordinator.test.tsfailed in both replay-after-working cases (got 2notifications instead of1)41 passed)pnpm test src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts src/renderer/src/hooks/agent-hook-completion-notifications.test.tspnpm test src/renderer/src/components/terminal-pane/use-notification-dispatch.test.tspnpm exec oxlint src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.tspnpm run typecheck:webNote: commands warn that this shell is Node 26 while the repo asks for Node 24, but the checks passed.