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: release the review-then-merge hold on a finished agent branch with no PR and no unique commits (#12905)

Adam Eivy3a15f9082d3f
diff --git a/server/services/branchCompletionPolicy.js b/server/services/branchCompletionPolicy.js
index d26e940c90..94d49a2d19 100644
--- a/server/services/branchCompletionPolicy.js
+++ b/server/services/branchCompletionPolicy.js
@@ -233,9 +233,30 @@ export async function readBranchCompletionHold(input, deps = {}) {
if (input.retirement === true && decision.obligation?.prUrl
&& await verifiedPolicyTip(input.repoPath, input.branch, decision.obligation.prUrl, { requireMerged: true, expectedTip: input.tip }).catch(() => null) === tip) return null;
if (decision.release && await verifiedPolicyTip(input.repoPath, input.branch, decision.release.prUrl).catch(() => null) === tip) return null;
+ if (input.retirement === true && await isVacuousReviewObligation(input, decision, tip)) return null;
return decision.reason;
}
+/** A review-then-merge run that never opened a PR and left no commit the default
+ * branch lacks has nothing to review or merge, and no later receipt can name a
+ * PR to release it. Every other hold (leave-open, a recorded PR, unmerged
+ * commits, an unresolvable default branch) is kept.
+ */
+async function isVacuousReviewObligation(input, decision, tip) {
+ if (decision.reason !== 'pr-completion-review-required' || input.prUrl
+ || !/^[a-f0-9]{40,64}$/i.test(tip || '')
+ || decision.policies.some(policy => policy.completion === PR_COMPLETIONS.LEAVE_OPEN || retirementPr(policy))) return false;
+ const { getDefaultBranch, hasBranchMergeEvidence } = await import('./git.js');
+ const base = await getDefaultBranch(input.repoPath, { strict: true }).catch(() => null);
+ if (!base) return false;
+ // A stale origin/<default> only makes the ancestry check stricter: whatever it
+ // contains the current default contains too.
+ const { execGit } = await import('../lib/execGit.js');
+ const remote = await execGit(['rev-parse', '--verify', `origin/${base}^{commit}`], input.repoPath, { ignoreExitCode: true })
+ .then(result => (result.exitCode === 0 ? `origin/${base}` : null), () => null);
+ return hasBranchMergeEvidence(input.repoPath, tip, remote || base).catch(() => false);
+}
+
/** Called with task policy and forge-observed identity, never provider prose.
* A receipt is a policy scope, not evidence that review or CI passed.
*/
diff --git a/server/services/branchCompletionPolicy.test.js b/server/services/branchCompletionPolicy.test.js
index 81f39bca87..3cebc08918 100644
--- a/server/services/branchCompletionPolicy.test.js
+++ b/server/services/branchCompletionPolicy.test.js
@@ -37,7 +37,7 @@ vi.mock('./github.js', () => ({
vi.mock('./cos.js', () => ({ addTask: async task => ({ ...parseTasksMarkdown(generateTasksMarkdown([task]))[0], taskType: 'internal' }), forceSpawnTask: vi.fn(), getAgents: async () => [], updateTask: vi.fn() }));
vi.mock('./cosEvents.js', () => ({ emitLog: vi.fn() }));
vi.mock('./cosAgentIndex.js', () => ({ removeDanglingAgentIndexEntries: vi.fn(async ids => ids.length) }));
-vi.mock('./git.js', () => ({ parsePullRequestUrl, getBranches: async () => [{ name: 'feature/handoff', tracking: 'origin/feature/handoff' }], hasBranchMergeEvidence: async () => runtime.merged }));
+vi.mock('./git.js', () => ({ parsePullRequestUrl, getBranches: async () => [{ name: 'feature/handoff', tracking: 'origin/feature/handoff' }], getDefaultBranch: async () => 'main', hasBranchMergeEvidence: async () => runtime.merged }));
vi.mock('./worktreeManager.js', () => ({ listWorktrees: async () => [], classifyWorktreeDirt: () => ({ hasRealChanges: false, realChangePaths: [] }) }));
import { spawnReviewLoopFollowUp } from './agentWorktreeCleanup.js';
@@ -135,6 +135,32 @@ describe('completion policy across lifecycle and reconciliation boundaries', ()
expect(await recheck()).toEqual({ admitted: false, reason: 'pr-completion-review-required' });
});
+ describe('retirement of a review-then-merge branch that never opened a PR', () => {
+ const retire = () => readBranchCompletionHold({ repoPath, branch, retirement: true });
+
+ it('releases the vacuous obligation only when the branch tip is already on the default branch', async () => {
+ register('agent-audit', 'review-then-merge');
+ runtime.merged = true;
+ expect(await retire()).toBeNull();
+ // Outside retirement the obligation still holds.
+ expect(await readBranchCompletionHold({ repoPath, branch })).toBe('pr-completion-review-required');
+ runtime.merged = false;
+ expect(await retire()).toBe('pr-completion-review-required');
+ });
+
+ it('keeps a leave-open handoff and a recorded PR held even when the tip is merged', async () => {
+ runtime.merged = true;
+ const handoff = register('agent-human', 'leave-open');
+ await recordBranchCompletionPolicy({ agentId: 'agent-human', task: handoff, repoPath, branch, prUrl });
+ expect(await retire()).toBe('pr-completion-human-handoff');
+ runtime.agents = {};
+ register('agent-review', 'review-then-merge');
+ expect(await retire()).toBeNull();
+ runtime.agents['agent-review'].metadata.branchCompletionPolicy = { branch, prUrl, completion: 'review-then-merge', tip: null };
+ expect(await retire()).toBe('pr-completion-review-required');
+ });
+ });
+
it.each(['claimBranches', 'claimReleasedBranches'])('holds malformed archived %s instead of losing a known policy scope', async field => {
register('agent-human', 'leave-open');
runtime.agents['agent-human'].metadata[field] = branch;