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
address review (codex): release spawn guard if identity resolution rejects
[._.]/ Adam Eivy78e52671757b
diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.jsindex 8919e16d8a..a1033a463b 100644--- a/server/services/agentLifecycle.js+++ b/server/services/agentLifecycle.js@@ -136,7 +136,19 @@ export async function spawnAgentForTask(task) {// task; the authoritative acquire-with-fresh-reread happens below, before any// spawn setup. No-op for a non-federated install (no claim metadata) and for// re-claiming our own task on retry/resume.- const instanceId = await ensureInstanceId();+ // Resolve identity defensively: this runs after `spawningTasks.add` but before+ // the main try/finally, so an uncaught rejection (e.g. cold-start identity+ // creation failing to write data/instances.json) would exit with the task id+ // stranded in `spawningTasks`, blocking every future spawn of it until restart+ // (codex review). Release the guard on failure.+ let instanceId;+ try {+ instanceId = await ensureInstanceId();+ } catch (err) {+ spawningTasks.delete(task.id);+ emitLog('error', `Failed to resolve instance identity for task ${task.id}: ${err?.message || err}`, { taskId: task.id });+ return null;+ }if (!isClaimableBy(task.metadata, instanceId)) {spawningTasks.delete(task.id);console.log(`🔒 Task ${task.id} is claimed by instance ${getClaimOwner(task.metadata)} (live lease) — skipping spawn on ${instanceId}`);diff --git a/server/services/agentLifecycle.test.js b/server/services/agentLifecycle.test.jsindex 1b2bdcb7f8..327fe0fba1 100644--- a/server/services/agentLifecycle.test.js+++ b/server/services/agentLifecycle.test.js@@ -727,6 +727,17 @@ describe('agentLifecycle — instance provenance stamping (#1563)', () => {expect(addIdx, 'the dedup guard must be acquired BEFORE the first await').toBeLessThan(firstAwaitIdx);});+ it('source: releases the spawn guard if identity resolution rejects', () => {+ // ensureInstanceId() runs after spawningTasks.add but before the main+ // try/finally, so a rejection must not strand the task in spawningTasks.+ const fnStart = AGENT_LIFECYCLE_SRC.indexOf('export async function spawnAgentForTask');+ const fnBody = AGENT_LIFECYCLE_SRC.slice(fnStart, fnStart + 60_000);+ const tryIdx = fnBody.indexOf('instanceId = await ensureInstanceId();');+ const catchSlice = fnBody.slice(tryIdx, tryIdx + 260);+ expect(tryIdx, 'ensureInstanceId must be awaited').toBeGreaterThan(-1);+ expect(catchSlice, 'a catch around ensureInstanceId must release the guard').toMatch(/catch[\s\S]*spawningTasks\.delete\(task\.id\)/);+ });+it('source: releases the claim on a failed-setup early exit (cleanupOnError)', () => {const fnStart = AGENT_LIFECYCLE_SRC.indexOf('const cleanupOnError = async');const fnBody = AGENT_LIFECYCLE_SRC.slice(fnStart, fnStart + 1200);