Skip to content

The agent that grows with you

fix(desktop): dismissing a background row never hides roster-reported work

Tekniumc7c7e0fa92f4
diff --git a/apps/desktop/src/store/composer-status.ts b/apps/desktop/src/store/composer-status.ts
index e43e2b430a1..e462bfa44d7 100644
--- a/apps/desktop/src/store/composer-status.ts
+++ b/apps/desktop/src/store/composer-status.ts
@@ -52,7 +52,9 @@ export interface ComposerStatusItem {
// Writable source for background work, synced from the gateway's process
// registry (`terminal(background=true)` spawns) via `process.list`.
export const $backgroundStatusBySession = atom<Record<string, ComposerStatusItem[]>>({})
-// When each list was written: the freshness the live-work roster compares against.
+// When the backend snapshot behind each list arrived: the freshness the
+// live-work roster compares against. Local removals (dismiss, auto-clear) carry
+// the snapshot's stamp forward; they are not new backend data.
const backgroundWrittenAt = new WeakMap<readonly ComposerStatusItem[], number>()
// Stored session ids that have at least one RUNNING background process. The
@@ -288,13 +290,16 @@ export function groupStatusItems(items: readonly ComposerStatusItem[]): StatusGr
return TYPE_ORDER.filter(type => byType.has(type)).map(type => ({ items: byType.get(type)!, type }))
}
-const writeBackground = (sid: string, items: ComposerStatusItem[]) => {
+const writeBackground = (sid: string, items: ComposerStatusItem[], snapshotAt: number | undefined) => {
const current = $backgroundStatusBySession.get()
const next = { ...current }
if (items.length > 0) {
next[sid] = items
- backgroundWrittenAt.set(items, Date.now())
+
+ if (snapshotAt !== undefined) {
+ backgroundWrittenAt.set(items, snapshotAt)
+ }
} else {
delete next[sid]
}
@@ -419,7 +424,7 @@ export function reconcileBackgroundProcesses(sid: string, procs: GatewayProcessE
return
}
- writeBackground(sid, next)
+ writeBackground(sid, next, Date.now())
}
/** Pull the session's live process snapshot from the gateway. */
@@ -467,7 +472,8 @@ export function dismissBackgroundProcess(sid: string, id: string) {
writeBackground(
sid,
- list.filter(item => item.id !== id)
+ list.filter(item => item.id !== id),
+ backgroundWrittenAt.get(list)
)
}
@@ -544,5 +550,5 @@ export function resetSessionBackground(sid: string) {
}
dismissedBySession.set(sid, dismissed)
- writeBackground(sid, [])
+ writeBackground(sid, [], undefined)
}
diff --git a/apps/desktop/src/store/live-work-roster.test.ts b/apps/desktop/src/store/live-work-roster.test.ts
index 8ed30368057..ad2ba66ddac 100644
--- a/apps/desktop/src/store/live-work-roster.test.ts
+++ b/apps/desktop/src/store/live-work-roster.test.ts
@@ -1,6 +1,11 @@
-import { afterEach, describe, expect, it } from 'vitest'
+import { afterEach, describe, expect, it, vi } from 'vitest'
-import { $backgroundRunningSessionIds, $backgroundStatusBySession } from './composer-status'
+import {
+ $backgroundRunningSessionIds,
+ $backgroundStatusBySession,
+ dismissBackgroundProcess,
+ reconcileBackgroundProcesses
+} from './composer-status'
import { $liveWorkRoster, setLiveWorkRosterSource } from './live-work-roster'
import { $delegatingSessionIds } from './session-dot-state'
import { $subagentsBySession, type SubagentProgress } from './subagents'
@@ -9,6 +14,8 @@ const child = (status: SubagentProgress['status'], updatedAt: number) =>
({ id: 'c1', index: 0, status, updatedAt }) as unknown as SubagentProgress
afterEach(() => {
+ vi.clearAllTimers()
+ vi.useRealTimers()
$liveWorkRoster.set({})
$subagentsBySession.set({})
$backgroundStatusBySession.set({})
@@ -41,4 +48,20 @@ describe('backend roster feeds rows no mounted tile speaks for', () => {
expect($backgroundRunningSessionIds.get()).toContain('old-pane')
})
+
+ it('never stamps a local dismissal as a fresher backend snapshot than the roster read', () => {
+ vi.useFakeTimers()
+ vi.setSystemTime(1_000)
+ reconcileBackgroundProcesses('pane', [
+ { command: 'a', exit_code: 0, session_id: 'p1', status: 'exited' },
+ { command: 'b', exit_code: 0, session_id: 'p2', status: 'exited' }
+ ])
+ setLiveWorkRosterSource('ambient', [{ session_id: 'pane', subagents: 0, background: 1 }], 2_000)
+
+ vi.setSystemTime(3_000)
+ dismissBackgroundProcess('pane', 'p1')
+
+ expect($backgroundStatusBySession.get().pane?.map(item => item.id)).toEqual(['p2'])
+ expect($backgroundRunningSessionIds.get()).toContain('pane')
+ })
})