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: preserve terminal safety verdicts during delivery recovery
Adam Eivyeb58118d0b2b
diff --git a/server/services/agentFinalization.js b/server/services/agentFinalization.jsindex a00a0caa66..0ae51664d6 100644--- a/server/services/agentFinalization.js+++ b/server/services/agentFinalization.js@@ -1695,7 +1695,8 @@ export async function finalizeAgent({const reportedTaskOutcome = !terminatedByUser && !isPrivateSecurityTask(task)? await persistCompletionSummary(agentId, { workspacePath, finalSummary }) : null;const deliveryHeld = ['blocked', 'incomplete'].includes(reportedTaskOutcome?.status);- if (deliveryHeld && reportedTaskOutcome.recovery?.mode !== 'cleanup') {+ if (deliveryHeld && reportedTaskOutcome.recovery?.mode !== 'cleanup'+ && !reportedErrorAnalysis?.actionable && !reportedErrorAnalysis?.permanent) {reportedSuccess = false;error = reportedTaskOutcome.reason;reportedErrorAnalysis = { category: `task-${reportedTaskOutcome.status}`, message: error,@@ -1939,8 +1940,10 @@ export async function finalizeAgent({} : verdict;const cleanupOwner = taskOutcome?.recovery?.mode === 'cleanup' ? await getAgentRecord(agentId) : null;const cleanupEligible = cleanupOwner?.metadata?.isWorktree === true || isTruthyMeta(cleanupOwner?.metadata?.claimPicksOwnBranch);+ const terminalFailure = !verdict.success && (verdict.errorAnalysis?.actionable || verdict.errorAnalysis?.permanent)+ && !(verdict.source === 'reported' && verdict.errorAnalysis?.category === `task-${reportedTaskOutcome?.status}`);const taskUpdate = (deliveryHeld || (verdict.success && outcomeHeld)) && !terminatedByUser- && !executionInterruption && !isPrivateSecurityTask(task) && hookResult?.outcome?.accepted !== false+ && !terminalFailure && !executionInterruption && !isPrivateSecurityTask(task) && hookResult?.outcome?.accepted !== false? resolveUndeliveredTaskUpdate(preHookTask, (!executionSuccess || !verdict.success || validationPassed === false || !cleanupEligible) && taskOutcome.recovery?.mode === 'cleanup'? { ...taskOutcome, recovery: undefined } : taskOutcome, agentId): await resolveFinalTaskUpdate({ task, preHookTask, hookMetadata, verdict, terminatedByUser, agentId });diff --git a/server/services/agentFinalization.primaryCheckoutDrift.test.js b/server/services/agentFinalization.primaryCheckoutDrift.test.jsindex 5cecae2f56..5be76f4c06 100644--- a/server/services/agentFinalization.primaryCheckoutDrift.test.js+++ b/server/services/agentFinalization.primaryCheckoutDrift.test.js@@ -159,6 +159,27 @@ describe('checkPrimaryCheckoutDrift', () => {});describe('finalizeAgent — a worktree run that mutated the primary is not a success', () => {+ it('keeps an actionable primary drift verdict when the agent reports cleanup-only work', async () => {+ detectPrimaryCheckoutDriftMock.mockResolvedValue(DRIFT);+ await finalize({ finalSummary: JSON.stringify({ summary: 'Cleanup remains.', taskOutcome: {+ status: 'incomplete', reason: 'The checkout still exists.', recovery: { mode: 'cleanup' },+ } }) });+ expect(resolveFailedTaskUpdateMock).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({+ category: PRIMARY_CHECKOUT_MUTATED_CATEGORY, actionable: true,+ }), 'agent-1');+ expect(completeAgentMock).toHaveBeenCalledWith('agent-1', expect.objectContaining({+ success: false, errorAnalysis: expect.objectContaining({ category: PRIMARY_CHECKOUT_MUTATED_CATEGORY }),+ }));+ });++ it('preserves an existing permanent execution failure ahead of a reported blocked outcome', async () => {+ const analysis = { category: 'execution-policy', permanent: true, message: 'Explicit execution policy requires intervention.' };+ await finalize({ success: false, errorAnalysis: analysis, finalSummary: JSON.stringify({ taskOutcome: {+ status: 'blocked', reason: 'Unfinished delivery.',+ } }) });+ expect(resolveFailedTaskUpdateMock).toHaveBeenCalledWith(expect.anything(), analysis, 'agent-1');+ });+it('records the drifted run as a FAILURE naming branch, count and recovery', async () => {detectPrimaryCheckoutDriftMock.mockResolvedValue(DRIFT);await finalize();diff --git a/server/services/agentRepoStateVerification.js b/server/services/agentRepoStateVerification.jsindex 84d3bf0f27..1a263b7d6c 100644--- a/server/services/agentRepoStateVerification.js+++ b/server/services/agentRepoStateVerification.js@@ -44,7 +44,7 @@ import { PATHS } from '../lib/fileUtils.js';import { isTruthyMeta } from './agentState.js';import { RECOVERY_TASK_PREFIX } from './recoveryTasks.js';import { resolveTaskTargetBranch } from '../lib/taskTargetBranch.js';-import { leavesPrForHuman, resolvePrCompletion, PR_COMPLETIONS } from '../lib/prDisposition.js';+import { leavesPrForHuman, prStaysOpen, resolvePrCompletion, PR_COMPLETIONS } from '../lib/prDisposition.js';import { probePrForBranch, probeChangeRequestState } from './prProbe.js';import { parsePullRequestUrl } from '../lib/gitForge.js';import { ensureTaskThread } from './brainTaskThreads.js';@@ -272,7 +272,7 @@ export async function verifyAgentRepoState(input) {const run = verify().then(async result => {if (result.skipReason === 'cleanup-owner-changed' || result.skipReason === 'cleanup-task-unavailable') return result;const outcomes = result.branches || [result];- const unsupported = outcomes.find(item => [REPO_STATE_SKIPS.DISABLED, REPO_STATE_SKIPS.NOT_WORKTREE,+ const unsupported = prStaysOpen(input.task) ? { skipReason: 'leave-open-cleanup-unsupported' } : outcomes.find(item => [REPO_STATE_SKIPS.DISABLED, REPO_STATE_SKIPS.NOT_WORKTREE,REPO_STATE_SKIPS.PERSISTENT_WORKTREE, REPO_STATE_SKIPS.DISCARDED_WORKTREE,'retirement-app-unavailable', 'retirement-policy-not-legacy-completed'].includes(item.skipReason)|| (item.skipReason === 'cleanup-delivery-unverified' && (['OPEN', 'CLOSED'].includes(item.observed?.prState)diff --git a/server/services/agentRepoStateVerification.test.js b/server/services/agentRepoStateVerification.test.jsindex f3cbe2baa9..c1082802d8 100644--- a/server/services/agentRepoStateVerification.test.js+++ b/server/services/agentRepoStateVerification.test.js@@ -148,7 +148,7 @@ beforeEach(() => {findMissingCheckoutPreservation.mockResolvedValue(null);inspectOrQueueCompletedReview.mockResolvedValue({ disposition: 'held', reason: 'delivery-ci-or-review-pending' });readBranchCompletionPolicies.mockResolvedValue([]);- updateTask.mockResolvedValue({ status: 'completed' });+ updateTask.mockReset().mockResolvedValue({ status: 'completed' });getTaskById.mockResolvedValue({ ...task(), status: 'in_progress', metadata: { ...task().metadata,deliveryRecovery: 'cleanup', deliveryRecoveryAgentId: 'agent-1' } });recordBranchReconcileOutcome.mockResolvedValue({ retirementObligations: [{ ...RELEASE, createdAt: CREATED_AT }] });@@ -184,6 +184,20 @@ describe('verifyAgentRepoState — clean runs', () => {expect(recordRepoStateVerification).toHaveBeenLastCalledWith('agent-1', { status: 'completed', reasons: ['cleanup-owner-changed'] });});+ it('transfers a cleanup handoff that cannot retire a human leave-open branch', async () => {+ updateTask.mockResolvedValueOnce({ status: 'in_progress' });+ const pending = { ...task({ prCompletion: 'leave-open' }), status: 'in_progress', metadata: {+ ...task({ prCompletion: 'leave-open' }).metadata, deliveryRecovery: 'cleanup', deliveryRecoveryAgentId: 'agent-1',+ } };+ getTaskById.mockResolvedValue(pending);+ existsSync.mockReturnValue(true);+ localBranch(true);+ const state = { ...agentState(), result: { cleanupPending: true } };+ expect(await run({ success: false, agentState: state, task: pending })).toMatchObject({ skipReason: 'cleanup-transferred-to-recovery' });+ expect(retireInventoriedCheckout).not.toHaveBeenCalled();+ expect(releaseRetryHold).toHaveBeenCalledOnce();+ });+it('transfers unsupported cleanup verification back to bounded recovery', async () => {updateTask.mockResolvedValueOnce({ status: 'in_progress' });const state = { ...agentState({ isPersistentWorktree: true, repoStateVerification: { status: 'pending' } }),