Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(unread): keep orphaned status entries until their clock ages out (90 days)

review650585ed68fa
diff --git a/CLAUDE.md b/CLAUDE.md
index 67cef08e3..8c14438f0 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -4140,12 +4140,14 @@ command-bearing opens; this does not add a human-confirm dialog or change mobile
This NEVER changes the workflow bucket: read state is independent from agent state.
The unread COUNT is the macOS Dock badge (counted over nodes some project HOLDS, closed ones
included — never over the raw status table, which outlives nodes deleted by paths that skip
- `remove`; stale entries are swept at load past a 7-day grace, `lib/unreadBadge.ts`), and on **Windows** a taskbar overlay icon (pure
- `planBadge` + BGRA rasterizer `rasterizeBadge`, "9+" above nine, `main/taskbar-badge.ts`) plus a
- `flashFrame` when the count RISES while unfocused (cleared on focus); Linux shows nothing. Windows
- toasts need `app.setAppUserModelId` set before ready to the package.json `build.appId` the NSIS
- shortcut carries (`main/app-identity.ts`, pinned by test; `execPath` in dev) — without it toasts
- are dropped or mis-attributed silently (Windows never emits Notification `failed`).
+ `remove`; an orphaned entry is swept at load once its 90-day `lastSeen` clock ages out, and the
+ sweep is skipped whenever the load is incomplete, `lib/unreadBadge.ts`), and on **Windows** a
+ taskbar overlay icon (pure `planBadge` + BGRA rasterizer `rasterizeBadge`, "9+" above nine,
+ `main/taskbar-badge.ts`) plus a `flashFrame` when the count RISES while unfocused (cleared on
+ focus); Linux shows nothing. Windows toasts need `app.setAppUserModelId` set before ready to the
+ package.json `build.appId` the NSIS shortcut carries (`main/app-identity.ts`, pinned by test;
+ `execPath` in dev) — without it toasts are dropped or mis-attributed silently (Windows never
+ emits Notification `failed`).
- **Sound alerts + custom sounds** (issue #289) — the `done` / `needsYou` alert (`SfxKind`) is a
synthesized WebAudio chime (`renderer/lib/sfx.ts`, fired from Canvas's `alert` closure, gated by
`soundEffects`, 5 s/node cooldown). Settings → Notifications lets the user replace either with their
diff --git a/src/renderer/lib/unreadBadge.test.ts b/src/renderer/lib/unreadBadge.test.ts
index b80ce82d0..bd0fb2381 100644
--- a/src/renderer/lib/unreadBadge.test.ts
+++ b/src/renderer/lib/unreadBadge.test.ts
@@ -6,6 +6,7 @@ import {
unreadIdSet,
unreadIdsSig
} from './unreadBadge'
+import { LAST_SEEN_MAX_AGE_MS } from '../state/agentStatus'
const DAY = 24 * 60 * 60_000
const NOW = 1_800_000_000_000
@@ -50,6 +51,15 @@ describe('orphanStatusIds (the boot sweep)', () => {
expect(orphanStatusIds(byId, projects, NOW)).toEqual([])
})
+ it('keeps an orphan for weeks, not days — a folder re-opened after an index rebuild keeps its node ids', () => {
+ const byId = { weeks: { unread: true, lastSeen: { at: NOW - 30 * DAY } } }
+ expect(orphanStatusIds(byId, projects, NOW)).toEqual([])
+ })
+
+ it('drops an orphan exactly when its clock would age out on load, never earlier', () => {
+ expect(ORPHAN_STATUS_GRACE_MS).toBe(LAST_SEEN_MAX_AGE_MS)
+ })
+
it('judges nothing when the load is incomplete: no projects, or an unreadable one', () => {
const byId = { x: { unread: true } }
expect(orphanStatusIds(byId, [], NOW)).toEqual([])
diff --git a/src/renderer/lib/unreadBadge.ts b/src/renderer/lib/unreadBadge.ts
index 1b8d38477..00e51457d 100644
--- a/src/renderer/lib/unreadBadge.ts
+++ b/src/renderer/lib/unreadBadge.ts
@@ -52,9 +52,12 @@ export function countUnreadInProjects(
/** A status entry whose node is in no project is kept this long after its last hook event before
* the boot sweep drops it. The node may come back: an SSH project's offline copy can lag the host
- * until the next reconcile, and a git checkout can restore an older canvas — dropping its entry at
- * once would cost it its resume id. */
-export const ORPHAN_STATUS_GRACE_MS = 7 * 24 * 60 * 60_000
+ * until the next reconcile, a git checkout can restore an older canvas, and a folder dropped from a
+ * rebuilt index keeps its node ids when it is opened again — dropping its entry would cost it its
+ * resume id. Deliberately EQUAL to `LAST_SEEN_MAX_AGE_MS` (state/agentStatus.ts, pinned by the
+ * test): an orphan goes on the same boot its clock ages out, and never earlier. The count no longer
+ * reads orphans, so a long window costs only a little storage. */
+export const ORPHAN_STATUS_GRACE_MS = 90 * 24 * 60 * 60_000
/**
* The status ids the boot sweep may drop: their node is in no project, and their last hook event
diff --git a/src/renderer/state/agentStatus.ts b/src/renderer/state/agentStatus.ts
index 4be0aa008..09e2b2369 100644
--- a/src/renderer/state/agentStatus.ts
+++ b/src/renderer/state/agentStatus.ts
@@ -72,7 +72,9 @@ export interface AgentNodeStatus {
* `saveClocks`) — never inside the main table, whose write cadence stays exactly what it was.
* Bounded: `LAST_SEEN_MAX` newest, `LAST_SEEN_MAX_AGE_MS` old at most, dropped with the node by
* `remove` (a deletion path that bypasses `remove` leaves a clock that ages out; it can never make
- * a row, since rows come from canvas nodes).
+ * a row, since rows come from canvas nodes). The age-out is also the boot sweep's grace: an entry
+ * whose node is in no project is dropped once its clock is gone (`orphanStatusIds`,
+ * lib/unreadBadge.ts).
*
* It is a record of the PAST, restored as nothing else:
* - NOT as `state`: after a relaunch nothing has reported, a turn may have started or ended while