Prevent cross-coordinator title replays

This commit is contained in:
Brennan Benson
2026-08-14 14:36:47 -07:00
parent c72a864e06
commit 1003fff7ca
2 changed files with 67 additions and 1 deletions
@@ -1469,6 +1469,68 @@ describe('agent completion coordinator', () => {
expect(dispatchCompletion).toHaveBeenCalledTimes(1)
})
it('does not let a pane title duplicate another coordinator stamped completion', () => {
const dispatchCompletion = vi.fn()
const hookCoordinator = createAgentCompletionCoordinator({
paneKey: 'tab-1:leaf-1',
getPtyId: () => 'pty-1',
getSettings: () => null,
inspectProcess: vi.fn(),
dispatchCompletion,
isLive: () => true
})
const paneCoordinator = createAgentCompletionCoordinator({
paneKey: 'tab-1:leaf-1',
getPtyId: () => 'pty-1',
getSettings: () => null,
inspectProcess: vi.fn(),
dispatchCompletion,
isLive: () => true
})
hookCoordinator.observeHookStatus({
state: 'working',
prompt: 'review the PR',
agentType: 'claude',
stateStartedAt: 1_700_000_000_000
})
hookCoordinator.observeHookStatus({
state: 'working',
prompt: 'review the PR',
agentType: 'claude',
stateStartedAt: 1_700_000_000_000,
turnCompletedAt: 1_700_000_005_000
})
expect(dispatchCompletion).toHaveBeenCalledTimes(1)
vi.advanceTimersByTime(2_000)
paneCoordinator.observeTitleWorking()
paneCoordinator.observeClassifiedTitleCompletion('Claude done')
expect(dispatchCompletion).toHaveBeenCalledTimes(1)
hookCoordinator.observeHookStatus({
state: 'working',
prompt: 'continue the review',
agentType: 'claude',
stateStartedAt: 1_700_000_010_000
})
hookCoordinator.observeHookStatus({
state: 'done',
prompt: 'continue the review',
agentType: 'claude',
stateStartedAt: 1_700_000_020_000
})
vi.advanceTimersByTime(HOOK_DONE_QUIET_MS)
expect(dispatchCompletion).toHaveBeenCalledTimes(2)
paneCoordinator.observeTitleWorking()
paneCoordinator.observeClassifiedTitleCompletion('Claude done')
expect(dispatchCompletion).toHaveBeenCalledTimes(3)
})
it('does not let a vetoed gated Stop swallow the later all-clear', () => {
const dispatchCompletion = vi.fn()
const coordinator = createAgentCompletionCoordinator({
@@ -328,6 +328,8 @@ export function createAgentCompletionCoordinator(
options.paneKey,
optionsOverride.completionIdentity.lastTurnCompletedAtNotified
)
} else {
handledTurnCompletedAtByPaneKey.delete(options.paneKey)
}
}
if (
@@ -741,7 +743,9 @@ export function createAgentCompletionCoordinator(
clearPendingCodexAttention()
workingStatusObserved = true
requiresFreshWorking = false
lastCompletionIdentityByPaneKey.delete(options.paneKey)
if (!handledTurnCompletedAtByPaneKey.has(options.paneKey)) {
lastCompletionIdentityByPaneKey.delete(options.paneKey)
}
currentTurn += 1
dropPendingTitle()
return true