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: report retained work and incomplete reconciliation scans (#12274)

[._.]/ Adam Eivyb241f32c167f
diff --git a/server/services/branchReconcileCompletion.js b/server/services/branchReconcileCompletion.js
index 0dcf1da6ef..e23da08913 100644
--- a/server/services/branchReconcileCompletion.js
+++ b/server/services/branchReconcileCompletion.js
@@ -26,12 +26,17 @@ export async function settleBranchReconcileRun(agent) {
claimOwners: { agents, readAgents: readClaimOwnershipAgents },
forgeAccount: app.forgeAccount || null
});
+ const inFlightBranches = new Set((result.inFlight || []).map(branch => branch.branch));
const holds = describeIdleReconcilePark(result.skipped || [], [], {
wip: result.wip, detachedWorktrees: result.detachedWorktrees,
- superseded: result.superseded, claimMarkersHeld: result.claimMarkersHeld
+ superseded: result.superseded, claimMarkersHeld: result.claimMarkersHeld,
+ // Actionable branches are counted separately; the helper deduplicates all
+ // remaining checkout projections and includes retained claim reservations.
+ worktreeInventory: result.worktreeInventory?.filter(tree => !inFlightBranches.has(tree.branch)) ?? null,
});
- const uncertain = result.forgeUnavailable || result.prStateUnavailable;
- const remaining = (result.inFlight?.length || 0) + (holds.counts?.heldBranches || 0) + (holds.counts?.heldDetached || 0);
+ const uncertain = result.forgeUnavailable || result.prStateUnavailable
+ || result.worktreeInventory == null || result.orphanRemotes?.remoteUnavailable;
+ const remaining = inFlightBranches.size + holds.remaining.length;
emitLog(uncertain || remaining ? 'warn' : 'info',
`Branch reconciliation completion: cleaned ${result.cleaned.length}, superseded ${result.reapedSuperseded?.length || 0}, remaining ${remaining}${uncertain ? '; scan incomplete' : ''}`,
{ appId: app.id, analysisType: type, counts: holds.counts, skipCauses: holds.skipCauses });
diff --git a/server/services/branchReconcileCompletion.test.js b/server/services/branchReconcileCompletion.test.js
index 88b1667905..8e548a6c66 100644
--- a/server/services/branchReconcileCompletion.test.js
+++ b/server/services/branchReconcileCompletion.test.js
@@ -3,9 +3,9 @@ vi.mock('./apps.js', () => ({ getAppById: vi.fn() }));
vi.mock('./cosTaskStore.js', () => ({ getTaskById: vi.fn() }));
vi.mock('./agentState.js', () => ({ getActiveAgentIds: vi.fn(() => new Set(['active'])) }));
vi.mock('./cosClaimOwnership.js', () => ({ readClaimOwnershipAgents: vi.fn() }));
-vi.mock('./branchReconcile.js', () => ({
+vi.mock('./branchReconcile.js', async (importOriginal) => ({
+ ...await importOriginal(),
reconcile: vi.fn(), buildActiveOwnerIds: vi.fn(() => new Set(['active'])),
- describeIdleReconcilePark: vi.fn(() => ({ counts: null, skipCauses: null }))
}));
vi.mock('./cosEvents.js', () => ({ emitLog: vi.fn() }));
vi.mock('./prWatcher.js', () => ({ readPendingMergePrs: vi.fn(() => [{ prBranch: 'claim/queued' }]) }));
@@ -13,6 +13,7 @@ import { getAppById } from './apps.js';
import { getTaskById } from './cosTaskStore.js';
import { readClaimOwnershipAgents } from './cosClaimOwnership.js';
import { reconcile } from './branchReconcile.js';
+import { emitLog } from './cosEvents.js';
import { settleBranchReconcileRun } from './branchReconcileCompletion.js';
const agent = { taskId: 'task-example', metadata: { taskAnalysisType: 'branch-reconcile', taskApp: 'example' } };
@@ -22,7 +23,7 @@ describe('branch reconciliation completion', () => {
getTaskById.mockResolvedValue({ metadata: { perpetual: false } });
getAppById.mockResolvedValue({ id: 'example', repoPath: '/example/repo', forgeAccount: 'example-account' });
readClaimOwnershipAgents.mockResolvedValue([]);
- reconcile.mockResolvedValue({ cleaned: ['merged'], reapedSuperseded: ['superseded'], inFlight: [], skipped: [] });
+ reconcile.mockResolvedValue({ cleaned: ['merged'], reapedSuperseded: ['superseded'], inFlight: [], skipped: [], worktreeInventory: [], orphanRemotes: { reported: [] } });
});
it('settles a non-perpetual run immediately using fresh ownership and its target account', async () => {
expect(await settleBranchReconcileRun(agent)).toMatchObject({ cleaned: ['merged'], reapedSuperseded: ['superseded'] });
@@ -31,6 +32,53 @@ describe('branch reconciliation completion', () => {
claimOwners: { agents: [], readAgents: readClaimOwnershipAgents }, forgeAccount: 'example-account'
});
});
+ it('reports inventory-only protected and detached worktrees plus retained claims', async () => {
+ reconcile.mockResolvedValue({
+ cleaned: ['claim/issue-42'], inFlight: [], skipped: [],
+ worktreeInventory: [
+ { branch: 'release', path: '/example/release', reason: 'worktree-locked', locked: true },
+ { path: '/example/detached', detached: true, reason: 'checkout-retained' },
+ ],
+ claimMarkersHeld: [{ branch: 'claim/issue-42', issue: 42, reason: 'claim-reservation-owner-unverified' }],
+ });
+ await settleBranchReconcileRun(agent);
+ expect(emitLog).toHaveBeenLastCalledWith('warn', expect.stringContaining('remaining 3'), expect.objectContaining({
+ counts: { heldBranches: 1, heldDetached: 1, heldClaims: 1 },
+ skipCauses: { 'worktree-locked': 1, 'checkout-retained': 1, 'claim-reservation-owner-unverified': 1 },
+ }));
+ });
+ it('counts repeated branch and inventory projections once, including actionable branches', async () => {
+ reconcile.mockResolvedValue({
+ cleaned: [], inFlight: [{ branch: 'fix/active', worktreePath: '/example/active' }],
+ skipped: [{ branch: 'fix/held', path: '/example/held', reason: 'worktree-locked' }],
+ wip: [{ branch: 'fix/held', worktreePath: '/example/held', liveOwnerReason: 'worktree-locked' }],
+ worktreeInventory: [
+ { branch: 'fix/active', path: '/example/active', reason: 'checkout-retained' },
+ { branch: 'fix/held', path: '/example/held', reason: 'worktree-locked' },
+ ],
+ });
+ await settleBranchReconcileRun(agent);
+ expect(emitLog).toHaveBeenLastCalledWith('warn', expect.stringContaining('remaining 2'), expect.objectContaining({
+ counts: { heldBranches: 1, heldDetached: 0, heldBackMerged: 1 },
+ skipCauses: { 'worktree-locked': 1 },
+ }));
+ });
+ it.each([
+ { worktreeInventory: null },
+ { orphanRemotes: { remoteUnavailable: true } },
+ { forgeUnavailable: true },
+ { prStateUnavailable: true },
+ ])('warns when the completion scan is incomplete: %j', async (incomplete) => {
+ reconcile.mockResolvedValue({ cleaned: [], inFlight: [], skipped: [], worktreeInventory: [], ...incomplete });
+ await settleBranchReconcileRun(agent);
+ expect(emitLog).toHaveBeenLastCalledWith('warn', expect.stringContaining('; scan incomplete'), expect.any(Object));
+ });
+ it('reports a known empty inventory as complete', async () => {
+ await settleBranchReconcileRun(agent);
+ expect(emitLog).toHaveBeenLastCalledWith('info',
+ 'Branch reconciliation completion: cleaned 1, superseded 1, remaining 0',
+ expect.objectContaining({ counts: null, skipCauses: null }));
+ });
it('cleans verified work even when the coordinator failed after making progress', async () => {
await settleBranchReconcileRun({ ...agent, result: { success: false } });
expect(reconcile).toHaveBeenCalledOnce();