fix(remote): refresh mirrored resume attribution

This commit is contained in:
Brennan Benson
2026-07-29 19:32:45 -07:00
parent d644677a8c
commit a73e37c032
2 changed files with 34 additions and 2 deletions
@@ -1954,6 +1954,35 @@ describe('applyWebSessionTabsSnapshot', () => {
expect(attributionPatch.agentStatusEpoch).toBe(8)
expect(attributionPatch.sortEpoch).toBe(12)
const fresherAttributionPatch = applyWebSessionTabsSnapshot(
makeState({
...initial,
agentStatusByPaneKey: {
[mirroredPaneKey]: {
...existing,
updatedAt: NOW,
worktreeId: 'stale-worktree',
tabId: 'stale-tab',
providerSession: undefined
}
},
agentStatusEpoch: 7,
sortEpoch: 11
}),
{ ...snapshot, snapshotVersion: 3 },
ENV,
NOW
) as Partial<WebSessionTabsSyncState>
expect(fresherAttributionPatch.agentStatusByPaneKey?.[mirroredPaneKey]).toMatchObject({
worktreeId: existing.worktreeId,
tabId: existing.tabId,
updatedAt: NOW,
providerSession: { key: 'session_id', id: 'session-1' }
})
expect(fresherAttributionPatch.agentStatusEpoch).toBe(8)
expect(fresherAttributionPatch.sortEpoch).toBe(12)
const identityPatch = applyWebSessionTabsSnapshot(
makeState({
...initial,
@@ -1966,7 +1995,7 @@ describe('applyWebSessionTabsSnapshot', () => {
}
}
}),
{ ...snapshot, snapshotVersion: 3 },
{ ...snapshot, snapshotVersion: 4 },
ENV,
NOW
) as Partial<WebSessionTabsSyncState>
@@ -713,11 +713,14 @@ function buildMirroredAgentStatusPatch(
continue
}
const existing = state.agentStatusByPaneKey[entry.paneKey]
// Why: an active web stream can report a fresher OSC 9999 status before the next host snapshot, so don't rewind it with an older host publication.
// Why: keep fresher OSC state while taking remapped ownership metadata from the authoritative host snapshot.
const nextEntry =
existing && existing.updatedAt > entry.updatedAt
? {
...normalizeCompatibleAgentStatusEntryForOwner(existing, entry.agentType),
paneKey: entry.paneKey,
worktreeId: entry.worktreeId ?? existing.worktreeId,
tabId: entry.tabId,
providerSession: existing.providerSession ?? entry.providerSession
}
: entry