Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep a late run.spawned from talking a finished run back into running (#4540)
[._.]/ Adam Eivyae9a5b619c4c
diff --git a/server/lib/agentRunEvents.js b/server/lib/agentRunEvents.jsindex 5d98fa89ce..05363f815b 100644--- a/server/lib/agentRunEvents.js+++ b/server/lib/agentRunEvents.js@@ -441,8 +441,13 @@ function applyKind(state, event) {const data = event.data ?? {};switch (event.kind) {case 'run.spawned':- state.status = 'running';- state.startedAt = event.at;+ // Guarded like every other non-terminal arm. A spawn should never follow a+ // finalize for the same run, but the ledger is a stream several+ // independent call sites append to, and the one thing the fold must never+ // do is talk a finished run back into `running`. `startedAt` is first-wins+ // for the same reason: the first spawn is the run's real start.+ if (!isTerminal(state)) state.status = 'running';+ state.startedAt = state.startedAt ?? event.at;if (typeof data.providerId === 'string') state.providerId = data.providerId;if (typeof data.model === 'string') state.model = data.model;break;diff --git a/server/lib/agentRunEvents.test.js b/server/lib/agentRunEvents.test.jsindex 5aa80b1c08..947611dde7 100644--- a/server/lib/agentRunEvents.test.js+++ b/server/lib/agentRunEvents.test.js@@ -361,6 +361,16 @@ describe('projectRunStates — the second-slice boundaries (#4540)', () => {expect(state.eventCount).toBe(5);});+ it('does not let a late spawn talk a finished run back into running', () => {+ const [state] = projectRunStates([+ buildRunEvent({ kind: 'run.spawned', runId: 'r1', at: at('10:00') }),+ buildRunEvent({ kind: 'run.finalized', runId: 'r1', at: at('11:00'), data: { success: true, exitCode: 0 } }),+ buildRunEvent({ kind: 'run.spawned', runId: 'r1', at: at('11:05') })+ ]);+ expect(state.status).toBe('completed');+ expect(state.startedAt).toBe(at('10:00'));+ });+it('records a REJECTED handoff without claiming an owner', () => {const [state] = projectRunStates([buildRunEvent({ kind: 'run.spawned', runId: 'r1', at: at('10:00') }),