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

fix: accept a coordinator no-op and keep its type on resume

[._.]/ Adam Eivye52afbc274d0
diff --git a/server/lib/agentOutcome.js b/server/lib/agentOutcome.js
index 92a84d02b2..17b2795fd6 100644
--- a/server/lib/agentOutcome.js
+++ b/server/lib/agentOutcome.js
@@ -121,7 +121,7 @@ export function isTaskDeliveryComplete(agent) {
&& ['completed', 'no-action-needed'].includes(outcome?.status);
}
-export function resolveTaskOutcome({ reported, success, validationPassed, branchProvenEmpty, noChangeAllowed }) {
+export function resolveTaskOutcome({ reported, success, validationPassed, branchProvenEmpty, noChangeAllowed, noCommitDeclared = false }) {
if (reported && ['blocked', 'incomplete'].includes(reported.status)) return reported;
if (!success) return { status: 'incomplete', reason: 'Delivery checks did not pass.' };
// Legacy learning criteria include commit probes that are not delivery gates
@@ -130,7 +130,14 @@ export function resolveTaskOutcome({ reported, success, validationPassed, branch
if (validationPassed === false) return reported
? { status: 'incomplete', reason: 'Delivery checks did not pass.' } : null;
if (branchProvenEmpty && noChangeAllowed) return { status: 'no-action-needed', reason: 'The permitted no-change result was verified against the repository.' };
+ // Coordinators and the other no-commit shapes leave validation null on
+ // purpose: nothing was supposed to be committed, and the exit code already
+ // judged the run. A reported no-action is that run's delivery contract.
+ // Null means undeclared, not failed — an explicit false already lost above.
+ // A committing task must not take this branch; its null means the no-op was
+ // never checked against the repository.
if (reported?.status === 'no-action-needed' && validationPassed !== true) {
+ if (noCommitDeclared && validationPassed == null) return reported;
return { status: 'incomplete', reason: 'The reported no-action-needed result was not verified.' };
}
if (reported) return reported;
diff --git a/server/lib/agentOutcome.test.js b/server/lib/agentOutcome.test.js
index b560873ca1..d6cd0c4a3e 100644
--- a/server/lib/agentOutcome.test.js
+++ b/server/lib/agentOutcome.test.js
@@ -9,7 +9,7 @@
*/
import { describe, it, expect } from 'vitest';
-import { isAgentHandoff, isQueuedContinuation, agentHandoffReason } from './agentOutcome.js';
+import { isAgentHandoff, isQueuedContinuation, agentHandoffReason, resolveTaskOutcome } from './agentOutcome.js';
// The record `resumeAgent` retires when Relaunch swaps providers mid-run: it
// carries `success: false` and a summary in `error`, because the pause/requeue
@@ -95,3 +95,28 @@ describe('agentHandoffReason', () => {
expect(agentHandoffReason({ result: { resumed: true } })).toBe('Handed off to a new run');
});
});
+
+describe('resolveTaskOutcome', () => {
+ const reported = { status: 'no-action-needed', reason: 'Nothing left to reconcile.' };
+
+ it('keeps a no-commit no-op when validation was never declared', () => {
+ expect(resolveTaskOutcome({
+ reported, success: true, validationPassed: null, noCommitDeclared: true,
+ })).toEqual(reported);
+ expect(resolveTaskOutcome({
+ reported, success: true, noCommitDeclared: true,
+ })).toEqual(reported);
+ });
+
+ it('still rejects an unverified no-op from a committing task', () => {
+ expect(resolveTaskOutcome({
+ reported, success: true, validationPassed: null,
+ })).toEqual({ status: 'incomplete', reason: 'The reported no-action-needed result was not verified.' });
+ });
+
+ it('still rejects a no-commit no-op whose delivery check failed', () => {
+ expect(resolveTaskOutcome({
+ reported, success: true, validationPassed: false, noCommitDeclared: true,
+ })).toEqual({ status: 'incomplete', reason: 'Delivery checks did not pass.' });
+ });
+});
diff --git a/server/services/agentFinalization.js b/server/services/agentFinalization.js
index f78ff7b411..27f1f14db6 100644
--- a/server/services/agentFinalization.js
+++ b/server/services/agentFinalization.js
@@ -1278,7 +1278,7 @@ export async function retireDeadAgent({ agent, task, success, exitCode, duration
? mergedReviewFollowUp || claimDisposition.status === 'verified' ? true : null
: recoveredValidation;
const taskOutcome = reportedOutcome ? resolveTaskOutcome({ reported: reportedOutcome,
- success: effectiveSuccess, validationPassed }) : null;
+ success: effectiveSuccess, validationPassed, noCommitDeclared: declaresNoCommitCriterion(task) }) : null;
if (['blocked', 'incomplete'].includes(taskOutcome?.status)) effectiveSuccess = false;
if (agent.metadata?.runId) {
@@ -1981,7 +1981,8 @@ export async function finalizeAgent({
});
const taskOutcome = resolveTaskOutcome({ reported: reportedTaskOutcome, success: verdict.success,
- validationPassed, branchProvenEmpty, noChangeAllowed: permitsNoChangeCompletion(task) });
+ validationPassed, branchProvenEmpty, noChangeAllowed: permitsNoChangeCompletion(task),
+ noCommitDeclared: declaresNoCommitCriterion(task) });
const outcomeHeld = ['blocked', 'incomplete'].includes(taskOutcome?.status);
const deliverySuccess = verdict.success && !outcomeHeld;
const deliveryVerdict = !deliverySuccess && verdict.success ? { ...verdict, success: false,
diff --git a/server/services/agentFinalization.outputHooks.test.js b/server/services/agentFinalization.outputHooks.test.js
index 8ce2c9776a..dbef138c0f 100644
--- a/server/services/agentFinalization.outputHooks.test.js
+++ b/server/services/agentFinalization.outputHooks.test.js
@@ -57,7 +57,7 @@ vi.mock('./taskTypeHooks.js', () => ({
}));
import { getAgent, getAgentRecord, updateAgent, completeAgent } from './cosAgentLifecycle.js';
-import { canRunTaskOutputHookWithoutPayload, getTaskOutputHook, isProgrammaticIoTaskType } from './taskTypeHooks.js';
+import { canRunTaskOutputHookWithoutPayload, declaresNoCommitCriterion, getTaskOutputHook, isProgrammaticIoTaskType } from './taskTypeHooks.js';
import {
finalizeAgent,
retireDeadAgent,
@@ -577,6 +577,47 @@ describe('recovery output-hook dispatch (#3182)', () => {
} finally { isProgrammaticIoTaskType.mockReturnValue(true); }
});
+ it('accepts a coordinator no-op whose commit criterion was never declared', async () => {
+ isProgrammaticIoTaskType.mockReturnValue(false);
+ declaresNoCommitCriterion.mockReturnValue(true);
+ const taskOutcome = { status: 'no-action-needed', reason: 'Inventory was already drained.' };
+ const task = { id: 'reconcile-example', taskType: 'internal', metadata: { analysisType: 'branch-reconcile', app: 'app-example' } };
+ try {
+ await finalizeAgent({ agentId: 'agent-example', task, success: true, exitCode: 0, outputBuffer: '',
+ finalSummary: JSON.stringify({ summary: 'Nothing left to reconcile.', taskOutcome }) });
+ expect(completeAgent).toHaveBeenLastCalledWith('agent-example', expect.objectContaining({
+ success: true, executionSuccess: true, validationPassed: null, taskOutcome,
+ }));
+ expect(updateTask).toHaveBeenLastCalledWith(task.id, expect.objectContaining({
+ status: 'completed', metadata: expect.objectContaining({ taskOutcome }),
+ }), 'internal');
+ expect(addTask).not.toHaveBeenCalled();
+ } finally {
+ isProgrammaticIoTaskType.mockReturnValue(true);
+ declaresNoCommitCriterion.mockReturnValue(false);
+ }
+ });
+
+ it('keeps a failed delivery gate ahead of a coordinator no-op', async () => {
+ isProgrammaticIoTaskType.mockReturnValue(false);
+ declaresNoCommitCriterion.mockReturnValue(true);
+ const task = { id: 'reconcile-example', taskType: 'internal', metadata: { analysisType: 'branch-reconcile' } };
+ persistedAgent.taskId = task.id;
+ persistedAgent.result = { validationPassed: false };
+ persistedAgent.metadata.taskOutcome = { status: 'no-action-needed', reason: 'Inventory was already drained.' };
+ persistedAgent.metadata.taskOutcomeSource = 'terminal-result';
+ try {
+ await retireDeadAgent({ agent: persistedAgent, task, success: true, exitCode: 0, duration: 100 });
+ expect(completeAgent).toHaveBeenLastCalledWith(persistedAgent.id, expect.objectContaining({
+ success: false, validationPassed: false,
+ taskOutcome: { status: 'incomplete', reason: 'Delivery checks did not pass.' },
+ }));
+ } finally {
+ isProgrammaticIoTaskType.mockReturnValue(true);
+ declaresNoCommitCriterion.mockReturnValue(false);
+ }
+ });
+
it('holds an unverified no-op', async () => {
isProgrammaticIoTaskType.mockReturnValue(false);
try {
diff --git a/server/services/agentManagement.js b/server/services/agentManagement.js
index a4282ae5f1..488f5c16f6 100644
--- a/server/services/agentManagement.js
+++ b/server/services/agentManagement.js
@@ -1,3 +1,4 @@
+import { reconcileAssignmentForTask } from '../lib/claimContinuation.js';
import { hasClaimFlowContract } from '../lib/claimFlowTaskTypes.js';
import { isFalsyMeta, isTruthyMeta } from '../lib/metadataFlags.js';
import { maintenance } from '../lib/maintenanceAdmission.js';
@@ -666,6 +667,43 @@ const REPLACEMENT_RUNTIME_METADATA_KEYS = new Set([
...PAUSE_METADATA_KEYS, ...CLAIM_METADATA_KEYS,
]);
+/**
+ * A replacement queued because the original task is gone still has to be the same
+ * kind of run. Registration projects `analysisType` onto the agent as
+ * `taskAnalysisType` and does not copy it back, so a missing task became a generic
+ * commit task: the live checkout was probed, a correct no-op failed delivery, and
+ * the retry budget spawned more agents. Fill only keys the task record did not
+ * already carry. The assignment is accepted only when it still validates as this
+ * task's own snapshot — resume prose cannot supply one.
+ */
+function inheritPausedCoordinatorContract(metadata, agentMeta, { app, taskType }) {
+ if (!agentMeta) return;
+ if ((metadata.analysisType == null || metadata.analysisType === '')
+ && typeof agentMeta.taskAnalysisType === 'string' && agentMeta.taskAnalysisType.trim()) {
+ metadata.analysisType = agentMeta.taskAnalysisType;
+ }
+ // `false` and the TASKS.md string `"false"` are the load-bearing values.
+ if (metadata.worktreeChangesExpected == null && agentMeta.worktreeChangesExpected != null) {
+ metadata.worktreeChangesExpected = agentMeta.worktreeChangesExpected;
+ }
+ // Strict boolean: a string `"true"` is not the on-demand lane marker.
+ if (metadata.onDemand == null && agentMeta.taskOnDemand === true) metadata.onDemand = true;
+ if (metadata.analysisType === 'branch-reconcile' && metadata.reconcileAssignment == null) {
+ const validated = reconcileAssignmentForTask({
+ taskType,
+ metadata: {
+ // Top-level `app` overwrites a metadata seed at intake, so a dialog
+ // switch has to win here too. Otherwise the previous app's snapshot
+ // would be stored on the task the replacement actually runs.
+ app: app || metadata.app,
+ analysisType: 'branch-reconcile',
+ reconcileAssignment: agentMeta.reconcileAssignment,
+ },
+ });
+ if (validated) metadata.reconcileAssignment = validated;
+ }
+}
+
/**
* The fallback: the paused run's task is gone or completed, so queue the fresh task
* the caller described instead. Same outcome the pre-fix client always took, kept
@@ -703,11 +741,17 @@ async function replacePausedTask({ agentId, agent, task, taskType, overrides })
}
for (const key of REPLACEMENT_RUNTIME_METADATA_KEYS) delete inheritedMetadata[key];
if (agentId) inheritedMetadata.resumedFromAgentId = agentId;
+ // Validate against the app the replacement will actually run, including a
+ // dialog switch, so a snapshot for the previous app is not attached as a grant.
+ const overridesPatch = resumeOverrideMetadata(overrides, task?.metadata || agent?.metadata);
+ inheritPausedCoordinatorContract(inheritedMetadata, agent?.metadata, {
+ app: overridesPatch.app || app, taskType,
+ });
const created = await addTask({
description,
context, prompt, provider, model, effort, app,
metadata: inheritedMetadata,
- ...resumeOverrideMetadata(overrides, task?.metadata || agent?.metadata)
+ ...overridesPatch
}, taskType);
if (created?.error) {
throw new ServerError(`Failed to queue resume task: ${created.error}`, {
diff --git a/server/services/agentManagement.test.js b/server/services/agentManagement.test.js
index 42cd3b77c0..1ab7251c38 100644
--- a/server/services/agentManagement.test.js
+++ b/server/services/agentManagement.test.js
@@ -1456,6 +1456,140 @@ describe('resumeAgent — requeues the paused agent\'s own task', () => {
await expect(resumeAgent('agent-paused-1')).resolves.toMatchObject({ mode: 'new-task' });
});
+ it('keeps a missing coordinator task a coordinator when the task record is gone', async () => {
+ const assignment = {
+ appId: 'app-example',
+ repoPath: '/tmp/example-repo',
+ origin: { host: 'example.com', fullName: 'example/example' },
+ targets: [{ branch: 'claim/issue-1', merge: true, workspacePath: '/tmp/example-checkout' }],
+ };
+ getAgentRecord.mockResolvedValue({
+ ...PAUSED_AGENT,
+ metadata: {
+ ...PAUSED_AGENT.metadata,
+ configClaimFlow: false,
+ taskType: 'internal',
+ taskDescription: 'Drain finished branches',
+ taskApp: 'app-example',
+ taskAnalysisType: 'branch-reconcile',
+ worktreeChangesExpected: 'false',
+ taskOnDemand: true,
+ reconcileAssignment: assignment,
+ pauseReason: 'Paused by cleanup policy',
+ failureCount: '2',
+ },
+ });
+ getTaskById.mockResolvedValue(null);
+
+ await resumeAgent('agent-paused-1');
+
+ const [replacement, taskType] = addTask.mock.calls[0];
+ expect(taskType).toBe('internal');
+ expect(replacement.app).toBe('app-example');
+ expect(replacement.metadata).toMatchObject({
+ analysisType: 'branch-reconcile',
+ worktreeChangesExpected: 'false',
+ onDemand: true,
+ reconcileAssignment: assignment,
+ resumedFromAgentId: 'agent-paused-1',
+ taskDescription: 'Drain finished branches',
+ });
+ expect(replacement.metadata).not.toHaveProperty('pauseReason');
+ expect(replacement.metadata).not.toHaveProperty('failureCount');
+ expect(replacement.metadata).not.toHaveProperty('workspacePath');
+ });
+
+ it('drops a reconcile assignment when the resume points at a different app', async () => {
+ getTaskById.mockResolvedValue({
+ ...PAUSED_TASK,
+ status: 'completed',
+ taskType: 'internal',
+ metadata: { ...PAUSED_TASK.metadata, analysisType: 'branch-reconcile', app: 'app-example' },
+ });
+ getAgentRecord.mockResolvedValue({
+ ...PAUSED_AGENT,
+ metadata: {
+ ...PAUSED_AGENT.metadata,
+ taskType: 'internal',
+ taskApp: 'app-example',
+ taskAnalysisType: 'branch-reconcile',
+ reconcileAssignment: {
+ appId: 'app-example',
+ repoPath: '/tmp/example-repo',
+ origin: { host: 'example.com', fullName: 'example/example' },
+ targets: [{ branch: 'claim/issue-1', merge: true, workspacePath: '/tmp/example-checkout' }],
+ },
+ },
+ });
+
+ await resumeAgent('agent-paused-1', { app: 'app-other' });
+
+ const [replacement] = addTask.mock.calls[0];
+ expect(replacement.app).toBe('app-other');
+ expect(replacement.metadata.analysisType).toBe('branch-reconcile');
+ expect(replacement.metadata).not.toHaveProperty('reconcileAssignment');
+ });
+
+ it('does not attach an assignment the snapshot no longer validates', async () => {
+ getAgentRecord.mockResolvedValue({
+ ...PAUSED_AGENT,
+ metadata: {
+ ...PAUSED_AGENT.metadata,
+ configClaimFlow: false,
+ taskType: 'internal',
+ taskDescription: 'Drain finished branches',
+ taskApp: 'app-example',
+ taskAnalysisType: 'branch-reconcile',
+ taskOnDemand: 'true',
+ reconcileAssignment: {
+ appId: 'app-example',
+ repoPath: 'relative/repo',
+ origin: { host: 'example.com', fullName: 'example/example' },
+ targets: [{ branch: 'claim/issue-1', merge: true, workspacePath: '/tmp/example-checkout' }],
+ },
+ },
+ });
+ getTaskById.mockResolvedValue(null);
+
+ await resumeAgent('agent-paused-1');
+
+ const [replacement] = addTask.mock.calls[0];
+ expect(replacement.metadata.analysisType).toBe('branch-reconcile');
+ expect(replacement.metadata).not.toHaveProperty('reconcileAssignment');
+ expect(replacement.metadata).not.toHaveProperty('onDemand');
+ });
+
+ it('keeps the task record type when it still names one', async () => {
+ getTaskById.mockResolvedValue({
+ ...PAUSED_TASK,
+ status: 'completed',
+ taskType: 'internal',
+ metadata: { ...PAUSED_TASK.metadata, analysisType: 'issue-watcher', app: 'app-example' },
+ });
+ getAgentRecord.mockResolvedValue({
+ ...PAUSED_AGENT,
+ metadata: {
+ ...PAUSED_AGENT.metadata,
+ taskType: 'internal',
+ taskAnalysisType: 'branch-reconcile',
+ taskApp: 'app-example',
+ reconcileAssignment: {
+ appId: 'app-example',
+ repoPath: '/tmp/example-repo',
+ origin: { host: 'example.com', fullName: 'example/example' },
+ targets: [{ branch: 'claim/issue-1', merge: true, workspacePath: null }],
+ },
+ },
+ });
+
+ await resumeAgent('agent-paused-1');
+
+ const [replacement, taskType] = addTask.mock.calls[0];
+ expect(taskType).toBe('internal');
+ expect(replacement.metadata.analysisType).toBe('issue-watcher');
+ expect(replacement.metadata).not.toHaveProperty('reconcileAssignment');
+ });
+
it('falls back to agent metadata when the original task is missing', async () => {
getAgentRecord.mockResolvedValue({
...PAUSED_AGENT,