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: prevent empty catalog audit PRs (#5074)

[._.]/ Adam Eivy4830d78ebb37
diff --git a/server/lib/prDisposition.js b/server/lib/prDisposition.js
index 8acf471a06..bd30790888 100644
--- a/server/lib/prDisposition.js
+++ b/server/lib/prDisposition.js
@@ -100,10 +100,12 @@ export const PR_CREATION = Object.freeze({
* @param {boolean} opts.agentOwnsPr - the prompt told the agent to open it
* @param {boolean} opts.prClaimVerified - finalize ran `verifyPrClaim` for this
* run (i.e. `prExpected` was true), so cleanup must not ask a second time
+ * @param {boolean} [opts.noChangesToShip] - finalize verified an opted-in audit
+ * left no commits and no change request, so cleanup must not create an empty PR
* @returns {string} a `PR_CREATION` value
*/
-export function resolvePrCreation({ taskOpenPR, agentOwnsPr, prClaimVerified }) {
- if (!taskOpenPR) return PR_CREATION.NEVER;
+export function resolvePrCreation({ taskOpenPR, agentOwnsPr, prClaimVerified, noChangesToShip = false }) {
+ if (!taskOpenPR || noChangesToShip) return PR_CREATION.NEVER;
if (!agentOwnsPr) return PR_CREATION.ALWAYS;
return prClaimVerified ? PR_CREATION.NEVER : PR_CREATION.IF_MISSING;
}
diff --git a/server/lib/prDisposition.test.js b/server/lib/prDisposition.test.js
index d676e655d8..45b7d01b00 100644
--- a/server/lib/prDisposition.test.js
+++ b/server/lib/prDisposition.test.js
@@ -33,6 +33,15 @@ describe('resolvePrCreation (#3733)', () => {
expect(resolvePrCreation({ taskOpenPR: true, agentOwnsPr: false, prClaimVerified: false })).toBe(PR_CREATION.ALWAYS);
});
+ it('never creates an empty PR after finalize proves an opted-in audit is a no-op', () => {
+ expect(resolvePrCreation({
+ taskOpenPR: true,
+ agentOwnsPr: false,
+ prClaimVerified: false,
+ noChangesToShip: true,
+ })).toBe(PR_CREATION.NEVER);
+ });
+
it('backstops an owner finalize did NOT verify — the slashdo-free harnesses', () => {
expect(resolvePrCreation({ taskOpenPR: true, agentOwnsPr: true, prClaimVerified: false })).toBe(PR_CREATION.IF_MISSING);
});
diff --git a/server/services/agentCliSpawning.js b/server/services/agentCliSpawning.js
index 347d6a1f17..fc237ede3d 100644
--- a/server/services/agentCliSpawning.js
+++ b/server/services/agentCliSpawning.js
@@ -821,6 +821,7 @@ export async function spawnDirectly({
// that threw, and a throw from finalize skips the assignment entirely; in all
// three cases nothing was verified, so cleanup must ask rather than stand down.
let directPrClaimVerified = false;
+ let noChangesToShip = false;
// try/finally so a throw from finalizeAgent still runs the local
// cleanup (worktree, pid unregister, activeAgents delete). Mirrors the
@@ -850,6 +851,7 @@ export async function spawnDirectly({
});
if (finalized && typeof finalized.success === 'boolean') cleanupSuccess = finalized.success;
directPrClaimVerified = prClaimWasVerified(finalized?.prVerdict);
+ noChangesToShip = finalized?.prVerdict?.noChangesToShip === true;
} finally {
const directPrCompletion = resolvePrCompletion(task.metadata);
const directReviewLoopFollowUp = isTruthyMetaFn(task.metadata?.reviewLoopFollowUp);
@@ -859,6 +861,7 @@ export async function spawnDirectly({
taskOpenPR: directOpenPR,
agentOwnsPr: directAgentOwnsPR,
prClaimVerified: directPrClaimVerified,
+ noChangesToShip,
}),
prCompletion: directPrCompletion,
...reviewOptions,
diff --git a/server/services/agentCompletionCleanup.js b/server/services/agentCompletionCleanup.js
index 9479e1e808..7864ff7e9c 100644
--- a/server/services/agentCompletionCleanup.js
+++ b/server/services/agentCompletionCleanup.js
@@ -182,9 +182,9 @@ export async function handlePipelineProgression(task, agentId, success) {
* be skipped by a throw from the JIRA/pipeline/Creative Director steps — either
* would leave the task held until the orphan sweep noticed.
*
- * @param {{ agentId: string, task: object, agent: object, effectiveSuccess: boolean, outputBuffer: string }} params
+ * @param {{ agentId: string, task: object, agent: object, effectiveSuccess: boolean, outputBuffer: string, noChangesToShip?: boolean }} params
*/
-export async function runAgentCompletionCleanup({ agentId, task, agent, effectiveSuccess, outputBuffer, prClaimVerified = false }) {
+export async function runAgentCompletionCleanup({ agentId, task, agent, effectiveSuccess, outputBuffer, prClaimVerified = false, noChangesToShip = false }) {
// Fetch agent state once for JIRA, plan-question, and the resume pointer. Its
// worktree fields are stamped once at registerAgent and never mutated, so passing
// it to the release spares a re-read that would re-split the whole output.txt.
@@ -192,7 +192,7 @@ export async function runAgentCompletionCleanup({ agentId, task, agent, effectiv
const agentState = await getAgentState(agentId).catch(() => null);
try {
- await runCompletionCleanupSteps({ agentId, task, agent, agentState, effectiveSuccess, outputBuffer, prClaimVerified });
+ await runCompletionCleanupSteps({ agentId, task, agent, agentState, effectiveSuccess, outputBuffer, prClaimVerified, noChangesToShip });
} finally {
await releaseRetryHold({
agentId,
@@ -207,7 +207,7 @@ export async function runAgentCompletionCleanup({ agentId, task, agent, effectiv
* The cleanup steps themselves. Split from the public entry point above only so
* the retry-hold release can wrap them in a `finally` without re-indenting them.
*/
-async function runCompletionCleanupSteps({ agentId, task, agent, agentState, effectiveSuccess, outputBuffer, prClaimVerified = false }) {
+async function runCompletionCleanupSteps({ agentId, task, agent, agentState, effectiveSuccess, outputBuffer, prClaimVerified = false, noChangesToShip = false }) {
// JIRA integration: push branch, create PR, comment on ticket
const jiraTicketId = task?.metadata?.jiraTicketId;
const jiraBranch = task?.metadata?.jiraBranch;
@@ -361,7 +361,7 @@ async function runCompletionCleanupSteps({ agentId, task, agent, agentState, eff
// `if-missing` for an agent-owned PR that finalize did NOT verify: cleanup
// asks the forge once and only stands down when a PR actually exists, so a
// harness that skipped its completion workflow can't strand the branch.
- prCreation: resolvePrCreation({ taskOpenPR, agentOwnsPr: agentOwnsPR, prClaimVerified }),
+ prCreation: resolvePrCreation({ taskOpenPR, agentOwnsPr: agentOwnsPR, prClaimVerified, noChangesToShip }),
prCompletion: taskPrCompletion,
...reviewOptions,
skipMerge: taskReviewLoopFollowUp || agentOwnsPR,
diff --git a/server/services/agentCompletionCleanup.test.js b/server/services/agentCompletionCleanup.test.js
index 4348429f6f..873a0bf334 100644
--- a/server/services/agentCompletionCleanup.test.js
+++ b/server/services/agentCompletionCleanup.test.js
@@ -143,9 +143,9 @@ describe('runAgentCompletionCleanup — agentOwnsPR mirrors the prompt gate', ()
// `prClaimVerified` is the caller's answer to "did finalize's PR-claim check
// actually produce a forge verdict for this run?" — threaded in, never
// re-derived here (see the note at its use site).
- const cleanupCallFor = async (agent, { prClaimVerified = false } = {}) => {
+ const cleanupCallFor = async (agent, { prClaimVerified = false, noChangesToShip = false } = {}) => {
await runAgentCompletionCleanup({
- agentId: 'a1', task: prTask, agent, effectiveSuccess: true, outputBuffer: '', prClaimVerified,
+ agentId: 'a1', task: prTask, agent, effectiveSuccess: true, outputBuffer: '', prClaimVerified, noChangesToShip,
});
// cleanupAgentWorktree(agentId, success, options) — options is the 3rd arg.
return cleanupAgentWorktree.mock.calls.at(-1)[2];
@@ -192,6 +192,14 @@ describe('runAgentCompletionCleanup — agentOwnsPR mirrors the prompt gate', ()
expect(opts.skipMerge).toBe(false);
});
+ it('does not create an empty PR after finalize proves a no-change audit', async () => {
+ const opts = await cleanupCallFor(
+ { providerId: 'claude-ollama', providerCommand: 'claude', leanMode: true, ownsPrWorkflow: false },
+ { noChangesToShip: true },
+ );
+ expect(opts.prCreation).toBe('never');
+ });
+
it('a task that asked for no PR never creates one', async () => {
await runAgentCompletionCleanup({
agentId: 'a1', task: { id: 't', taskType: 'user', metadata: {} },
diff --git a/server/services/agentFinalization.js b/server/services/agentFinalization.js
index 2f2f366679..e250feb8df 100644
--- a/server/services/agentFinalization.js
+++ b/server/services/agentFinalization.js
@@ -702,7 +702,7 @@ export async function finalizeAgent({
: null;
const effectivePrVerdict = typeof prVerdict.branch === 'string'
? prVerdict
- : (noChangeProof || prVerdict);
+ : (noChangeProof?.noChangesToShip === true ? noChangeProof : prVerdict);
const noChangesToShip = prVerdict.noChangesToShip === true || noChangeProof?.noChangesToShip === true;
// Record the verdict in the lifecycle ledger (#4540) — but ONLY when the
diff --git a/server/services/agentFinalization.prVerification.test.js b/server/services/agentFinalization.prVerification.test.js
index a3f1826a87..eb07a2290c 100644
--- a/server/services/agentFinalization.prVerification.test.js
+++ b/server/services/agentFinalization.prVerification.test.js
@@ -550,6 +550,24 @@ describe('finalizeAgent — records the PR verdict in the lifecycle ledger', ()
expect(finalized.prVerdict).toMatchObject({ branch: 'cos/sys-1/agent-1', noChangesToShip: true });
});
+ it('does not record a premature miss while cleanup can still create a PR', async () => {
+ onBranch('cos/sys-1/agent-1');
+ git.ahead = 3;
+ findPullRequestForBranchMock.mockResolvedValue({ status: 'none', number: null, url: null, detail: null });
+ const finalized = await finalize({
+ prExpected: false,
+ task: {
+ ...prTask(),
+ metadata: { ...prTask().metadata, autonomousJob: true, noChangeSuccess: true }
+ }
+ });
+
+ 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 });
+ });
+
it('writes NOTHING when the check itself threw', async () => {
// A throw is not a verdict — the finalize path already falls back to the
// reported outcome, and the ledger must not claim a forge confirmed anything.
diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.js
index 5364c728eb..cd37582425 100644
--- a/server/services/agentLifecycle.js
+++ b/server/services/agentLifecycle.js
@@ -1299,6 +1299,7 @@ export async function handleAgentCompletion(agentId, exitCode, success, duration
// user-terminated, or whose finalize threw outright verified nothing, and
// cleanup must ask the forge itself rather than assume the PR exists.
let runnerPrClaimVerified = false;
+ let runnerNoChangesToShip = false;
try {
const finalized = await finalizeAgent({
agentId,
@@ -1318,6 +1319,7 @@ export async function handleAgentCompletion(agentId, exitCode, success, duration
});
if (finalized && typeof finalized.success === 'boolean') cleanupSuccess = finalized.success;
runnerPrClaimVerified = prClaimWasVerified(finalized?.prVerdict);
+ runnerNoChangesToShip = finalized?.prVerdict?.noChangesToShip === true;
} catch (err) {
finalizeError = err;
emitLog('error', `finalizeAgent threw for ${agentId} (continuing cleanup): ${err.message}`, { agentId, error: err.message });
@@ -1327,7 +1329,7 @@ export async function handleAgentCompletion(agentId, exitCode, success, duration
// pipeline progression, the Creative Director chain hook, and worktree
// cleanup (+ cleanup-warning notification and merge-recovery task). Runs
// inside this try so a throw still hits the finally below.
- await runAgentCompletionCleanup({ agentId, task, agent, effectiveSuccess: cleanupSuccess, outputBuffer, prClaimVerified: runnerPrClaimVerified });
+ await runAgentCompletionCleanup({ agentId, task, agent, effectiveSuccess: cleanupSuccess, outputBuffer, prClaimVerified: runnerPrClaimVerified, noChangesToShip: runnerNoChangesToShip });
// Surface a finalizeAgent throw to the caller after best-effort
// cleanup completed — without this the runner harness would never see
diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.js
index f1f7dbcf8f..abbb091517 100644
--- a/server/services/agentPromptBuilder.test.js
+++ b/server/services/agentPromptBuilder.test.js
@@ -1181,9 +1181,27 @@ describe('buildLightContextPrompt', () => {
{ isTui: true, providerId: 'claude-code-tui', providerCommand: 'claude' },
);
- expect(prompt).toMatch(/`\/do:pr/);
- expect(prompt).toMatch(/<PR URL, or "No change needed; no PR opened\." if the audit made no change>/);
- });
+ expect(prompt).toMatch(/`\/do:pr/);
+ expect(prompt).toMatch(/<PR URL, or "No change needed; no PR opened\." if the audit made no change>/);
+ });
+
+ it('keeps a lean TUI no-change handoff on the branch sentinel', () => {
+ const prompt = buildLightContextPrompt(
+ makeTask({ metadata: {
+ autonomousJob: true,
+ noChangeSuccess: true,
+ useWorktree: true,
+ openPR: true,
+ } }),
+ '/r',
+ { branchName: 'b', worktreePath: '/tmp/wt' },
+ isTruthyMeta,
+ { isTui: true, providerId: 'claude-ollama-tui', providerCommand: 'claude', leanMode: true },
+ );
+
+ expect(prompt).toMatch(/## Branch\n\s+<branch name>/);
+ expect(prompt).not.toMatch(/<PR URL/);
+ });
// #3114 — the gates now derive from `resolveSlashdoStyle` with the spawners'
// blank-command posture, so a CLI provider with NO id and NO command reads as
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.js
index 34ac60ddcb..d850c7fc42 100644
--- a/server/services/agentTuiSpawning.js
+++ b/server/services/agentTuiSpawning.js
@@ -851,6 +851,7 @@ export async function spawnTuiAgent({
// throw from finalize itself skips the assignment entirely — in all three
// cases nothing was verified, so cleanup must ask rather than stand down.
let prClaimVerified = false;
+ let noChangesToShip = false;
// try/finally so a throw from finalizeAgent (e.g. processAgentCompletion
// hook crash) still runs the local cleanup — sentinel removal, worktree
@@ -885,12 +886,13 @@ export async function spawnTuiAgent({
});
if (finalized && typeof finalized.success === 'boolean') cleanupSuccess = finalized.success;
prClaimVerified = prClaimWasVerified(finalized?.prVerdict);
+ noChangesToShip = finalized?.prVerdict?.noChangesToShip === true;
} finally {
// This run's sentinel only — a sibling agent sharing this workspace owns
// its own file and may still be running.
if (doneSentinelPath) await rm(doneSentinelPath).catch(() => {});
- const prCreation = resolvePrCreation({ taskOpenPR, agentOwnsPr: agentOwnsPR, prClaimVerified });
+ const prCreation = resolvePrCreation({ taskOpenPR, agentOwnsPr: agentOwnsPR, prClaimVerified, noChangesToShip });
// Only the two modes that can still open a PR (and thus spawn a follow-up
// that needs these) pay for the resolve. `never` — the dominant path, an
// agent that opened and landed its own PR — discards them.
diff --git a/server/services/promptSections/completion.js b/server/services/promptSections/completion.js
index 570d9e95d5..423b3f2ea0 100644
--- a/server/services/promptSections/completion.js
+++ b/server/services/promptSections/completion.js
@@ -574,7 +574,7 @@ function buildManualTuiCompletionSection({ willOpenPR, prCompletion = PR_COMPLET
const simplifyStep = simplifyEnabled
? `1. Before committing, ${SIMPLIFY_INLINE_REVIEW} and fix any findings.`
: '1. (simplify disabled — skip)';
- const sentinelTail = (drivesOwnPr || willOpenPR)
+ const sentinelTail = drivesOwnPr
? (noChangeSuccess
? ' ## PR\n <PR URL, or "No change needed; no PR opened." if the audit made no change>'
: ' ## PR\n <PR URL>')