Replace accepted rows when observing a surviving tmux host

This commit is contained in:
Brennan Benson
2026-11-16 01:23:08 -08:00
parent 9072b20d41
commit c317afe7cd
2 changed files with 16 additions and 9 deletions
@@ -6,11 +6,12 @@ import type { AgentHookEventPayload } from '../../../shared/agent-hook-listener/
import type { AgentHookSource } from '../../../shared/agent-hook-listener/transport/agent-hook-relay'
import {
cliWriterTopology,
retainTmuxWriterTopology,
tmuxCliWriterEvent,
type CliWriterObservation
} from './cli-writer-observation'
import type { AgentStatusIpcPayload } from '../../../shared/agent-status/contracts/agent-status-ipc-payload'
import type { ParsedAgentStatusPayload } from '../../../shared/agent-status/contracts/agent-status-types'
import type { EnrichedAgentHookEventPayload } from './server-types'
import {
ClaudeSessionContinuationTracker,
resolvePaneClaudeContinuation
@@ -141,7 +142,10 @@ export class AgentHookServer extends AgentHookServerLifecycle {
* a sleep or adoption captures the conversation as the pane's own. */
private async observeTmuxHostedWriter(paneKey: string): Promise<void> {
const resolved = this.resolvePaneKeyAlias(paneKey)
const row = this.state.lastStatusByPaneKey.get(resolved)
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: main stores enriched accepted rows in the base-typed cache.
const row = this.state.lastStatusByPaneKey.get(resolved) as
| EnrichedAgentHookEventPayload
| undefined
const binding = row?.providerSession
const read = this.readPaneTmuxHost
if (
@@ -159,8 +163,11 @@ export class AgentHookServer extends AgentHookServerLifecycle {
worktreeId: row.worktreeId,
...(presence?.process && !presence.ended ? { process: presence.process } : {})
}).catch(() => false)
if (hosted && this.state.lastStatusByPaneKey.get(resolved)?.providerSession === binding) {
retainTmuxWriterTopology(binding)
if (hosted && this.state.lastStatusByPaneKey.get(resolved) === row) {
const hostedRow = tmuxCliWriterEvent(row)
if (this.writeLegacyStatusRow(hostedRow)) {
this.commitStatusRowMutation(row, hostedRow)
}
}
}
@@ -22,7 +22,7 @@ vi.mock('./agent-hook-completion-notifications', () => ({
syncAgentHookCompletionNotificationsForStoreUpdate: () => {}
}))
vi.mock('../store/github/refresh/stale-worktree-refresh-actions', () => ({
refreshGitHubForWorktreeIfStale: vi.fn()
createStaleWorktreeRefreshActions: () => ({ refreshGitHubForWorktreeIfStale: vi.fn() })
}))
vi.mock('@/lib/notifications/desktop-notification-sound', () => ({
playDesktopNotificationSound: vi.fn()
@@ -113,7 +113,7 @@ describe('waking a pane slept mid-turn', () => {
it.each(['claude', 'codex'] as const)(
'announces no %s finish until the pane runs a new turn',
async (agentType) => {
const working: AgentStatusIpcPayload = {
const working = {
paneKey: PANE,
connectionId: null,
tabId: 'tab-1',
@@ -123,7 +123,7 @@ describe('waking a pane slept mid-turn', () => {
agentType,
receivedAt: NOW,
stateStartedAt: NOW
}
} satisfies AgentStatusIpcPayload
send(working)
const slept = {
...working,
@@ -136,7 +136,7 @@ describe('waking a pane slept mid-turn', () => {
vi.setSystemTime(NOW + 30_000)
bindPty('pty-2')
// Main hands the slept turn back to the resumed process.
const resumed: AgentStatusIpcPayload = {
const resumed = {
...slept,
isReplay: true,
observation: {
@@ -147,7 +147,7 @@ describe('waking a pane slept mid-turn', () => {
observedAt: NOW + 30_000,
kind: 'snapshot'
}
}
} satisfies AgentStatusIpcPayload
send(resumed)
vi.advanceTimersByTime(40)