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(status): a restored mirror entry is marked, and is never proof

enes19b822d7525b
diff --git a/src/core/agent-status-mirror.test.ts b/src/core/agent-status-mirror.test.ts
index 8c95d5604..7c325a9a9 100644
--- a/src/core/agent-status-mirror.test.ts
+++ b/src/core/agent-status-mirror.test.ts
@@ -1795,3 +1795,62 @@ describe('reduceEntry records whether the state transition was verified', () =>
expect(b.verifiedAt).toBe(1000)
})
})
+
+describe('a restored entry is never proof', () => {
+ let dir = ''
+ beforeEach(() => {
+ _resetForTest()
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-status-restored-'))
+ })
+ afterEach(() => {
+ _resetForTest()
+ fs.rmSync(dir, { recursive: true, force: true })
+ })
+
+ it('is marked, and carries no proof, however the file was written', () => {
+ const file = path.join(dir, 'agent-status.json')
+ // `stateVerified: true` cannot come out of buildFile — but a hand-edited, downgraded or
+ // future-written file is not a thing this process controls, and the restore is what gate 2
+ // would read. Force the hostile shape.
+ fs.writeFileSync(
+ file,
+ JSON.stringify({
+ v: 1,
+ updatedAt: Date.now(),
+ nodes: { n1: { state: 'done', agentId: 'claude', stateVerified: true, updatedAt: Date.now() } }
+ })
+ )
+ initAgentStatusMirror(file)
+ expect(_snapshot().n1?.state).toBe('done')
+ expect(_snapshot().n1?.restored).toBe(true)
+ expect(_snapshot().n1?.stateVerified).toBe(false)
+ })
+
+ it('the first live event clears `restored`', () => {
+ const a = { state: 'done', stateVerified: false, restored: true, updatedAt: 0 } as MirrorEntry
+ expect(reduceEntry(a, ev({ state: 'working', verified: true }), 5).restored).toBeUndefined()
+ })
+
+ it('even an event that changes nothing clears it — the entry is live evidence now', () => {
+ // A context/usage event is not a state transition, but it IS this run's traffic from that
+ // node. What `restored` means is "nothing has been heard from this node since boot".
+ const a = { state: 'done', restored: true, updatedAt: 0 } as MirrorEntry
+ expect(reduceEntry(a, ev({ kind: 'context' } as never), 5).restored).toBeUndefined()
+ })
+
+ it('a restored `stateVerified` never survives to disk either', () => {
+ const file = path.join(dir, 'agent-status.json')
+ fs.writeFileSync(
+ file,
+ JSON.stringify({
+ v: 1,
+ updatedAt: Date.now(),
+ nodes: { n1: { state: 'done', stateVerified: true, restored: true, updatedAt: Date.now() } }
+ })
+ )
+ initAgentStatusMirror(file)
+ const doc = buildFile(_snapshot(), Date.now())
+ expect('stateVerified' in doc.nodes.n1).toBe(false)
+ expect('restored' in doc.nodes.n1).toBe(false)
+ })
+})
diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.ts
index 7d555d13c..d4d275b6c 100644
--- a/src/core/agent-status-mirror.ts
+++ b/src/core/agent-status-mirror.ts
@@ -73,6 +73,17 @@ export interface MirrorEntry {
* node prove itself" stays true, and it is what separates a node that CAN verify (retryable)
* from one that never has (not retryable). See the plan's Correction C1 mitigation. */
verifiedAt?: number
+ /**
+ * This entry's `state` came off disk at boot, not off a hook event this run. The mirror restores
+ * with a 6 h expiry and never pushes the restored copy to a listener — it is 6-hour-old evidence
+ * about a pane that has since done anything at all, including being replaced.
+ *
+ * Gate 2 refuses it outright (`targetNotIdleUnknown`), which is why the flag exists: without it a
+ * restored `done` is indistinguishable from a fresh one and the most dangerous moment in the
+ * product (just after a relaunch, sessions re-adopted, nothing re-confirmed) would read as the
+ * safest. Cleared by the first live event.
+ */
+ restored?: true
}
/** This host's Server-Edition install metadata (spec: server-update). Written by the installer
@@ -325,6 +336,10 @@ export function reduceEntry(
now: number
): MirrorEntry {
const next: MirrorEntry = prev ? { ...prev } : { updatedAt: now }
+ // ANY event is this run's traffic from this node, so the entry is no longer "restored and
+ // unheard-from". Done before every branch — including the ones that return early — because what
+ // the flag means is "nothing has been heard since boot", not "the state is still the restored one".
+ delete next.restored
// Identity is captured off ANY event (mirrors the renderer's per-event setSessionId +
// agentId threading). agentId is always present on a NormalizedAgentEvent.
if (ev.agentId) next.agentId = ev.agentId
@@ -1021,7 +1036,13 @@ function loadPersisted(file: string): void {
agentId: e.agentId,
sessionId: e.sessionId,
...(e.name ? { name: e.name } : {}),
- updatedAt
+ updatedAt,
+ // Marked, and FORCED unverified whatever the file said. `buildFile` writes neither field
+ // — it is an allowlist, which is what keeps `stateVerified` off disk — but a file this
+ // process did not write (hand-edited, downgraded, or from a future build) must not be
+ // able to hand gate 2 a proof nothing presented this run. See `restored`.
+ restored: true,
+ stateVerified: false
})
}
}