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: reap malformed empty issue claim branches

[._.]/ Adam Eivy529c9d32128f
diff --git a/server/services/branchReconcile.js b/server/services/branchReconcile.js
index c824497f39..f9641704fb 100644
--- a/server/services/branchReconcile.js
+++ b/server/services/branchReconcile.js
@@ -117,6 +117,17 @@ export const STALE_CLAIM_IDLE_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
// teardown and still turns a week-long park into a single recheck.
export const SHIPPED_CLAIM_IDLE_MS = 60 * 60 * 1000; // 1 hour
+/**
+ * A claim branch without an issue number is never a valid /claim deliverable.
+ * It can be left behind when a scheduled claim run creates its worktree before
+ * target selection completes; unlike a real claim, there is no issue session
+ * that could resume it. Keep this narrow so ordinary human claim branches
+ * retain their liveness grace period.
+ */
+export function isMalformedClaimBranch(branch) {
+ return branch === 'claim/issue-';
+}
+
// Bound the gh query (single-user repos never realistically truncate at 200).
const PR_LIST_LIMIT = 200;
@@ -931,7 +942,9 @@ export async function cleanupMerged(repoPath, defaultBranch, merged, { activeAge
// dirty gate is still ahead of the removal.
const retired = await retireBranch(repoPath, b, {
activeAgentIds,
- staleClaimIdleMs: b.upstreamGone ? SHIPPED_CLAIM_IDLE_MS : STALE_CLAIM_IDLE_MS,
+ staleClaimIdleMs: isMalformedClaimBranch(b.branch)
+ ? 0
+ : b.upstreamGone ? SHIPPED_CLAIM_IDLE_MS : STALE_CLAIM_IDLE_MS,
label: `🔀 branch-reconcile: remove worktree for ${b.branch}`,
});
if (!retired.ok) {
diff --git a/server/services/branchReconcile.test.js b/server/services/branchReconcile.test.js
index 7bfdbe969d..9c37da9170 100644
--- a/server/services/branchReconcile.test.js
+++ b/server/services/branchReconcile.test.js
@@ -105,6 +105,7 @@ import {
limitBranchesForAgent,
branchPriorityRank, prioritizeBranches, worktreeProtectionExpiresAt, describeIdleReconcilePark,
SHIPPED_CLAIM_IDLE_MS, STALE_CLAIM_IDLE_MS,
+ isMalformedClaimBranch,
listRemoteHeads, upstreamBranchName, parseRemoteHeads, partitionRemoteOrphans, reapOrphanedRemotes
} from './branchReconcile.js';
import * as git from './git.js';
@@ -338,6 +339,21 @@ describe('cleanupMerged', () => {
expect(git.deleteBranch).toHaveBeenCalledWith('/repo', 'claim/issue-1933', { local: true });
});
+ it('reaps the invalid empty-issue claim immediately when merged and clean', async () => {
+ expect(isMalformedClaimBranch('claim/issue-')).toBe(true);
+ expect(isMalformedClaimBranch('claim/issue-42')).toBe(false);
+ git.hasBranchMergeEvidence.mockResolvedValue(true);
+ execGit.mockResolvedValue({ stdout: '', exitCode: 0 });
+
+ const res = await cleanupMerged('/repo', 'main', [
+ { branch: 'claim/issue-', worktreePath: '/repo/data/cos/worktrees/claim-issue-', worktreeAgeMs: 60 * 1000 }
+ ]);
+
+ expect(res.cleaned).toEqual(['claim/issue-']);
+ expect(wt.forceRemoveWorktreeDir).toHaveBeenCalledWith('/repo', '/repo/data/cos/worktrees/claim-issue-', expect.any(Object));
+ expect(git.deleteBranch).toHaveBeenCalledWith('/repo', 'claim/issue-', { local: true });
+ });
+
it('still protects a RECENT claim worktree even when merged + clean, and says when the hold lifts', async () => {
git.hasBranchMergeEvidence.mockResolvedValue(true);
execGit.mockResolvedValue({ stdout: '', exitCode: 0 }); // clean