Skip to content

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

address review (agy): report a task claimed mid-spawn as started, and name the new-task resume outcome

[._.]/ Adam Eivy5d149ddf7479
diff --git a/client/src/components/cos/tabs/AgentsTab.jsx b/client/src/components/cos/tabs/AgentsTab.jsx
index 25eb2782ea..3b14af18e2 100644
--- a/client/src/components/cos/tabs/AgentsTab.jsx
+++ b/client/src/components/cos/tabs/AgentsTab.jsx
@@ -22,6 +22,10 @@ const RESUME_MESSAGES = {
queued: 'Resumed — the paused task is queued on its preserved worktree',
running: 'Resumed — the paused task is running again on its preserved worktree',
},
+ 'new-task': {
+ queued: 'Resumed — a replacement task is queued',
+ running: 'Resumed — a replacement task is running',
+ },
'already-active': { queued: 'Its task is already queued or running — nothing new was created' },
superseded: { queued: 'A later agent now holds this task paused — that pause was left intact' },
};
diff --git a/client/src/components/cos/tabs/AgentsTab.test.jsx b/client/src/components/cos/tabs/AgentsTab.test.jsx
index 01a781332c..80e3efc9e4 100644
--- a/client/src/components/cos/tabs/AgentsTab.test.jsx
+++ b/client/src/components/cos/tabs/AgentsTab.test.jsx
@@ -221,6 +221,22 @@ describe('AgentsTab resume routing', () => {
await waitFor(() => expect(toast.success).toHaveBeenCalledWith(expect.stringMatching(/No available agent slots \(3\/3\)/)));
});
+ // `new-task` is the mode where the paused task was gone, so a REPLACEMENT was
+ // queued — and it is force-spawned like any other. Without its own entry it fell
+ // through to the generic "Created resume task", which says nothing about whether
+ // the replacement actually started.
+ it('says a replacement task is running when the server started that too', async () => {
+ const user = userEvent.setup();
+ api.resumeCosAgent.mockResolvedValue({ success: true, taskId: 'task-new', mode: 'new-task', created: true, spawned: true });
+ renderTab([pausedAgent]);
+ await act(async () => {});
+
+ await user.click(screen.getByRole('button', { name: 'Resume agent-paused' }));
+ await user.click(screen.getByRole('button', { name: 'Submit resume' }));
+
+ await waitFor(() => expect(toast.success).toHaveBeenCalledWith(expect.stringMatching(/replacement task is running/i)));
+ });
+
// The default has to be safe by construction, not by keeping a copy of the server's
// mode enum in sync — a future non-creating mode this build has no wording for must
// not regress to announcing a task that was never queued.
diff --git a/server/services/agentManagement.js b/server/services/agentManagement.js
index 9fbacde85c..0cc731c20f 100644
--- a/server/services/agentManagement.js
+++ b/server/services/agentManagement.js
@@ -478,11 +478,26 @@ async function dispatchResumedTask({ taskId, mode }) {
if (result?.success) return { spawned: true, spawnHold: null };
// The dequeue `completeAgent` schedules races this call, so a refusal can mean
- // "already claimed" rather than "held". Read the task back and treat only a
- // real claim (`in_progress`) as started — string-matching the refusal would
- // drift the moment forceSpawnTask reworded one of them.
- const task = await getTaskById(taskId).catch(() => null);
- if (task?.status === 'in_progress') return { spawned: true, spawnHold: null };
+ // "already claimed" rather than "held". Read the state back and treat a real
+ // claim as started — string-matching the refusal would drift the moment
+ // forceSpawnTask reworded one of them.
+ //
+ // BOTH halves are load-bearing. A spawn registers its agent as `running`
+ // BEFORE it flips the task off `pending` (the window `forceSpawnTask`'s own
+ // holder guard exists for), so mid-spawn the task still reads `pending` while
+ // the run is genuinely under way — and the refusal that lands there is that
+ // holder guard, so checking only the task status would report a hold for a
+ // task that is already running. The holder half is only reachable while that
+ // guard is refusing, i.e. while the holder is young enough to be mid-spawn:
+ // an older, zombie holder is superseded by `forceSpawnTask` instead, so this
+ // can't read a dead agent's record as a live run.
+ const [task, agents] = await Promise.all([
+ getTaskById(taskId).catch(() => null),
+ getAgents().catch(() => []),
+ ]);
+ const heldByRunningAgent = agents.some(agent =>
+ agent.status === 'running' && (agent.taskId === taskId || agent.metadata?.taskId === taskId));
+ if (task?.status === 'in_progress' || heldByRunningAgent) return { spawned: true, spawnHold: null };
const spawnHold = result?.error || 'Task could not be spawned';
emitLog('info', `⏳ Resumed task ${taskId} stays queued — ${spawnHold}`, { taskId });
diff --git a/server/services/agentManagement.test.js b/server/services/agentManagement.test.js
index 8fbc1a4f42..2083dd4409 100644
--- a/server/services/agentManagement.test.js
+++ b/server/services/agentManagement.test.js
@@ -924,6 +924,7 @@ describe('resumeAgent — requeues the paused agent\'s own task', () => {
resumeWorktreePath: '/tmp/worktrees/agent-paused-1',
});
forceSpawnTask.mockResolvedValue({ success: true, taskId: 'task-abc' });
+ getAgents.mockResolvedValue([]);
});
it('flips the SAME task back to pending — no new task', async () => {
@@ -1166,6 +1167,20 @@ describe('resumeAgent — requeues the paused agent\'s own task', () => {
await expect(resumeAgent('agent-paused-1')).resolves.toMatchObject({ spawned: true, spawnHold: null });
});
+ // A spawn registers its agent as `running` BEFORE it flips the task off
+ // `pending`, and the refusal that lands in that window is forceSpawnTask's own
+ // holder guard. Reading the task status alone still sees `pending` there, so
+ // the resume would report a hold for a run that is already under way — the
+ // exact mis-report this dispatch exists to avoid.
+ it('treats a task claimed mid-spawn as started, even while it still reads pending', async () => {
+ forceSpawnTask.mockImplementation(async () => {
+ getAgents.mockResolvedValue([{ id: 'agent-new-1', status: 'running', taskId: 'task-abc' }]);
+ return { error: 'Agent agent-new-1 is already running this task' };
+ });
+
+ await expect(resumeAgent('agent-paused-1')).resolves.toMatchObject({ spawned: true, spawnHold: null });
+ });
+
it('does not dispatch a mode that deliberately queued nothing', async () => {
// `already-active` means some other path already put the work in flight —
// force-spawning here is the duplicate agent classifyResume exists to prevent.
@@ -1217,6 +1232,7 @@ describe('relaunchAgent — moves a running agent\'s task onto another provider'
getTaskById.mockResolvedValue(PAUSED_TASK);
reviveBlockedTask.mockResolvedValue({ metadata: {} });
forceSpawnTask.mockResolvedValue({ success: true, taskId: 'task-abc' });
+ getAgents.mockResolvedValue([]);
});
it('requeues the SAME task with the new provider/model/effort — no second task', async () => {