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

refactor: return explicit verification and branch outcomes from finalizeAgent (#9648)

Adam Eivy06e70b7c8f37
diff --git a/server/services/agentCliSpawning.js b/server/services/agentCliSpawning.js
index 7dc6c0b19a..d252b9a338 100644
--- a/server/services/agentCliSpawning.js
+++ b/server/services/agentCliSpawning.js
@@ -43,7 +43,6 @@ import { resolveAgentCliCwd } from '../lib/spawnCwd.js';
import { prepareCliSpawn, killProcessTree, guardChildStdin, deliverChildStdin } from '../lib/bufferedSpawn.js';
import { buildCliChildEnv } from '../lib/cliChildEnv.js';
import { applyCredentialBootstrap, needsProcessGroup, trackDetachedGroup } from '../lib/credentialBootstrap.js';
-import { prClaimWasVerified } from '../lib/prDisposition.js';
import { resolvePrOwnership } from '../lib/slashdoInvocation.js';
import { doneSentinelPath } from '../lib/agentSentinel.js';
import { isHostShuttingDown, HOST_SHUTDOWN_REASON } from '../lib/hostShutdown.js';
@@ -812,8 +811,8 @@ export async function spawnDirectly({
startedAt: agentData?.startedAt ?? null,
});
if (finalized && typeof finalized.success === 'boolean') cleanupSuccess = finalized.success;
- prClaimVerified = prClaimWasVerified(finalized?.prVerdict);
- branchProvenEmpty = finalized?.prVerdict?.branchProvenEmpty === true;
+ if (finalized?.prClaimVerified === true) prClaimVerified = true;
+ if (finalized?.branchProvenEmpty === true) branchProvenEmpty = true;
} finally {
// Pipeline progression → worktree cleanup with the PR disposition →
// retry-hold release, in the one owner both in-process spawners share.
diff --git a/server/services/agentFinalization.js b/server/services/agentFinalization.js
index f1a8f47f95..e9860d3833 100644
--- a/server/services/agentFinalization.js
+++ b/server/services/agentFinalization.js
@@ -1,4 +1,4 @@
-import { PR_MISSING_CATEGORY } from '../lib/prDisposition.js';
+import { PR_MISSING_CATEGORY, prClaimWasVerified } from '../lib/prDisposition.js';
import { isAuditTaskType } from '../lib/auditCatalog.js';
import { isPrivateSecurityTask } from '../lib/privateSecurityPolicy.js';
/**
@@ -1846,7 +1846,12 @@ export async function finalizeAgent({
// downgraded to `pr-missing` would still be cleaned up as a success — worktree
// removed, local branch deleted, and no resume pointer recorded — destroying
// the state the retry needs to open the PR that is missing.
- return { success: verdict.success, prVerdict: prEvidence.cleanupEvidence };
+ return {
+ success: verdict.success,
+ prClaimVerified: prClaimWasVerified(prEvidence.cleanupEvidence),
+ branchProvenEmpty: prEvidence.branchProvenEmpty,
+ cleanupEvidence: prEvidence.cleanupEvidence,
+ };
}
// Tail of the agent's transcript scanned by the rescue. The deliverable, when
diff --git a/server/services/agentFinalization.prVerification.test.js b/server/services/agentFinalization.prVerification.test.js
index 96dc49f9bd..1518afa72a 100644
--- a/server/services/agentFinalization.prVerification.test.js
+++ b/server/services/agentFinalization.prVerification.test.js
@@ -549,7 +549,7 @@ describe('finalizeAgent — a PR-shaped run with no PR is not a success (#3358)'
expect(findPullRequestForBranchMock).toHaveBeenCalledWith('cos/sys-1/agent-1', { cwd: '/w', env: null });
const [, result] = completeAgentMock.mock.calls[0];
expect(result).toMatchObject({ success: true, validationPassed: true });
- expect(finalized.prVerdict).toMatchObject({ ok: true, branch: 'cos/sys-1/agent-1', branchProvenEmpty: true });
+ expect(finalized.cleanupEvidence).toMatchObject({ ok: true, branch: 'cos/sys-1/agent-1', branchProvenEmpty: true });
});
it('leaves validation undeclared when a marked no-op audit cannot reach the forge', async () => {
@@ -735,7 +735,7 @@ describe('finalizeAgent — records the PR verdict in the lifecycle ledger', ()
branchProvenEmpty: true,
})
})]);
- expect(finalized.prVerdict).toMatchObject({ branch: 'cos/sys-1/agent-1', branchProvenEmpty: true });
+ expect(finalized.cleanupEvidence).toMatchObject({ branch: 'cos/sys-1/agent-1', branchProvenEmpty: true });
});
it('does not record a premature miss while cleanup can still create a PR', async () => {
@@ -753,7 +753,7 @@ describe('finalizeAgent — records the PR verdict in the lifecycle ledger', ()
expect(prVerified()).toHaveLength(0);
// The auxiliary proof is deliberately not returned for a non-empty branch:
// cleanup still owns the backstop PR creation and must be free to ask again.
- expect(finalized.prVerdict).toEqual({ ok: true });
+ expect(finalized.cleanupEvidence).toEqual({ ok: true });
});
it('writes NOTHING when the check itself threw', async () => {
@@ -988,7 +988,7 @@ describe('finalizeAgent — completion, ledger and cleanup evidence agree per ou
const [, completion] = completeAgentMock.mock.calls[0];
expect(completion.success).toBe(success);
if (completionReason) expect(completion.completionReason).toBe(completionReason);
- expect(finalized.prVerdict).toEqual(cleanupEvidence);
+ expect(finalized.cleanupEvidence).toEqual(cleanupEvidence);
expect(prVerified().map((e) => e.data)).toEqual(ledger ? [ledger] : []);
});
@@ -1005,7 +1005,7 @@ describe('finalizeAgent — completion, ledger and cleanup evidence agree per ou
git.ahead = 0;
findPullRequestForBranchMock.mockResolvedValue(noPr);
const proven = await finalize({ prExpected: false, task: auditTask() });
- expect(proven.prVerdict).toEqual({ ok: true, branch: 'cos/sys-1/agent-1', branchProvenEmpty: true });
+ expect(proven.cleanupEvidence).toEqual({ ok: true, branch: 'cos/sys-1/agent-1', branchProvenEmpty: true });
expect(prVerified().map((e) => e.data)).toEqual([
{ verified: true, branch: 'cos/sys-1/agent-1', category: null, branchProvenEmpty: true },
]);
@@ -1015,7 +1015,7 @@ describe('finalizeAgent — completion, ledger and cleanup evidence agree per ou
const unproven = await finalize({ prExpected: false, task: auditTask() });
const [, completion] = completeAgentMock.mock.calls[0];
expect(completion.success).toBe(true);
- expect(unproven.prVerdict).toEqual({ ok: true });
+ expect(unproven.cleanupEvidence).toEqual({ ok: true });
expect(prVerified()).toHaveLength(0);
});
});
diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.js
index 04cc1bf322..df0a1eecd3 100644
--- a/server/services/agentLifecycle.js
+++ b/server/services/agentLifecycle.js
@@ -42,7 +42,6 @@ import { appendRunEvent } from './agentRunEventLog.js';
import { committedDuringRun, toEpochMs } from '../lib/gitCommitProbe.js';
import { providerSuppliesGithubToken } from '../lib/providerModels.js';
import { canTypeSlashCommands } from '../lib/slashdoInvocation.js';
-import { prClaimWasVerified } from '../lib/prDisposition.js';
import { composeProviderEnv } from '../lib/cliChildEnv.js';
import { cliProviderAuthDescriptor } from '../lib/processEnv.js';
import { isClaudeCliProvider, getClaudeSettingsEnv } from './agentCliSpawning.js';
@@ -665,8 +664,8 @@ export async function handleAgentCompletion(agentId, exitCode, success, duration
startedAt: Number.isFinite(runStartedAt) ? runStartedAt : null,
});
if (finalized && typeof finalized.success === 'boolean') cleanupSuccess = finalized.success;
- runnerPrClaimVerified = prClaimWasVerified(finalized?.prVerdict);
- runnerNoChangesToShip = finalized?.prVerdict?.branchProvenEmpty === true;
+ if (finalized?.prClaimVerified === true) runnerPrClaimVerified = true;
+ if (finalized?.branchProvenEmpty === true) runnerNoChangesToShip = true;
} catch (err) {
finalizeError = err;
emitLog('error', `finalizeAgent threw for ${agentId} (continuing cleanup): ${err.message}`, { agentId, error: err.message });
diff --git a/server/services/agentTuiSpawning/sessionController.js b/server/services/agentTuiSpawning/sessionController.js
index a48da425b4..b5c04b8396 100644
--- a/server/services/agentTuiSpawning/sessionController.js
+++ b/server/services/agentTuiSpawning/sessionController.js
@@ -34,7 +34,6 @@ import { emitLog } from '../cosEvents.js';
import { HOST_SHUTDOWN_REASON } from '../../lib/hostShutdown.js';
import { missingSentinelLogMessage, parseSentinelPayload } from '../../lib/agentSentinel.js';
import { SENTINEL_COMPLETION_MARKER } from '../../lib/agentOutputMarkers.js';
-import { prClaimWasVerified } from '../../lib/prDisposition.js';
import { resolveMergeGateVerdict, buildMergeGateReprompt } from '../../lib/mergeGateContract.js';
import { createStreamingAnsiStripper, stripAnsi } from '../../lib/ansiStrip.js';
import { createClaudeSessionLimitBannerDetector, createImmediateFallbackSignalDetector, createLocalRuntimeOomDetector, createTruncatedResponseDetector } from '../../lib/aiToolkit/errorDetection.js';
@@ -1150,8 +1149,8 @@ export function createTuiSessionController({
startedAt: agentData?.startedAt ?? null,
});
if (finalizeVerdict && typeof finalizeVerdict.success === 'boolean') cleanupSuccess = finalizeVerdict.success;
- prClaimVerified = prClaimWasVerified(finalizeVerdict?.prVerdict);
- branchProvenEmpty = finalizeVerdict?.prVerdict?.branchProvenEmpty === true;
+ if (finalizeVerdict?.prClaimVerified === true) prClaimVerified = true;
+ if (finalizeVerdict?.branchProvenEmpty === true) branchProvenEmpty = true;
} finally {
await releaseRunResources({ agentData, cleanupSuccess, prClaimVerified, branchProvenEmpty });
}