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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
Stop app-less branch-reconcile runs from looping: refuse without a managed app, skip refill, record incomplete outcome (#12854)
[._.]/ Adam Eivy6aacc86a85ae
diff --git a/server/lib/taskTargetScope.js b/server/lib/taskTargetScope.jsindex 24eed98c38..27faab03c7 100644--- a/server/lib/taskTargetScope.js+++ b/server/lib/taskTargetScope.js@@ -28,7 +28,7 @@ export const INSTALL_WIDE_TASK_TYPES = new Set(['repo-sync', 'user-action-review// alongside the install-wide registry gives both the on-demand request gate// and the global generator one target-scope contract; neither has to infer// scope from a task name or from which generator happened to receive a call.-export const MANAGED_APP_TARGET_TASK_TYPES = new Set(['private-security-assessment', 'pr-reviewer', 'issue-watcher', 'pr-watcher', 'issue-reconcile']);+export const MANAGED_APP_TARGET_TASK_TYPES = new Set(['private-security-assessment', 'pr-reviewer', 'issue-watcher', 'pr-watcher', 'issue-reconcile', 'branch-reconcile']);export function requiresManagedAppTarget(taskType) {return MANAGED_APP_TARGET_TASK_TYPES.has(taskType);diff --git a/server/services/branchReconcileCompletion.js b/server/services/branchReconcileCompletion.jsindex 915ce2aff2..2c1d66efd2 100644--- a/server/services/branchReconcileCompletion.js+++ b/server/services/branchReconcileCompletion.js@@ -13,8 +13,17 @@ export async function settleBranchReconcileRun(agent) {const task = await getTaskById(agent.taskId);// The task holds the resolved per-app toggles. Missing records cannot grant cleanup.if (!task?.metadata || task.metadata.cleanupMerged === false) return null;- const app = await getAppById(agent.metadata.taskApp);- if (!app?.repoPath) throw new Error('Branch reconciliation completion target unavailable');+ const app = agent.metadata.taskApp ? await getAppById(agent.metadata.taskApp) : null;+ if (!app?.repoPath) {+ // A missing target is an explained refusal, not a defect: record it and stop.+ const { recordBranchReconcileOutcome } = await import('./taskSchedule.js');+ await recordBranchReconcileOutcome(agent.metadata.taskApp || null, {+ status: 'incomplete', reason: 'no-managed-app-target',+ nextAction: 'Run branch reconciliation against a managed app.',+ });+ emitLog('warn', 'Branch reconciliation skipped: no managed app target', { taskId: agent.taskId });+ return null;+ }const agents = await readClaimOwnershipAgents();if (!Array.isArray(agents)) throw new Error('Branch reconciliation ownership state unavailable');// Branches queued for the pr-watcher merge coordinator count as owned (#12258).diff --git a/server/services/branchReconcileCompletion.test.js b/server/services/branchReconcileCompletion.test.jsindex 21f124ded3..6458d1dc4f 100644--- a/server/services/branchReconcileCompletion.test.js+++ b/server/services/branchReconcileCompletion.test.js@@ -37,6 +37,13 @@ describe('branch reconciliation completion', () => {claimOwners: { agents: [], readAgents: readClaimOwnershipAgents }, forgeAccount: 'example-account'});});+ it('records an incomplete outcome instead of throwing when the run has no managed app', async () => {+ const appless = { ...agent, metadata: { ...agent.metadata, taskApp: null } };+ expect(await settleBranchReconcileRun(appless)).toBeNull();+ expect(getAppById).not.toHaveBeenCalled();+ expect(reconcile).not.toHaveBeenCalled();+ expect(recordBranchReconcileOutcome).toHaveBeenCalledWith(null, expect.objectContaining({ status: 'incomplete', reason: 'no-managed-app-target' }));+ });it('requires an exact persisted archive receipt after the review task reports success', async () => {const release = { branch: 'claim/issue-42', path: '/example/checkout', head: 'a'.repeat(40) };getTaskById.mockResolvedValue({ id: 'task-example', metadata: { reconcileRetirements: [{ release, cognition: { ownerAgentId: 'original-owner', observation: 'exact-observation' }, createdAt: '2026-10-20T00:00:00Z', prUrl: 'https://github.com/example/repo/pull/42' }] } });@@ -108,11 +115,12 @@ describe('branch reconciliation completion', () => {await settleBranchReconcileRun(agent);expect(reconcile).not.toHaveBeenCalled();});- it('fails closed on unreadable ownership or a missing target', async () => {+ it('fails closed on unreadable ownership and records an unresolvable app target', async () => {readClaimOwnershipAgents.mockRejectedValueOnce(new Error('unreadable'));await expect(settleBranchReconcileRun(agent)).rejects.toThrow('unreadable');getAppById.mockResolvedValueOnce(null);- await expect(settleBranchReconcileRun(agent)).rejects.toThrow('target unavailable');+ expect(await settleBranchReconcileRun(agent)).toBeNull();+ expect(recordBranchReconcileOutcome).toHaveBeenCalledWith('example', expect.objectContaining({ reason: 'no-managed-app-target' }));expect(reconcile).not.toHaveBeenCalled();});it('ignores other completed task types', async () => {diff --git a/server/services/cos.js b/server/services/cos.jsindex 9142311b5e..704dfd133d 100644--- a/server/services/cos.js+++ b/server/services/cos.js@@ -1444,6 +1444,8 @@ export function perpetualRefillPlan(agent, schedule) {// a task queued before the field existed is.const origin = agent?.metadata?.taskOnDemandOrigin || ON_DEMAND_ORIGINS.USER;if (!DRAINABLE_ON_DEMAND_ORIGINS.has(origin)) return { lane: 'skip' };+ // Reconciliation is per-repository: an app-less legacy run would re-issue itself forever.+ if (agentScheduledType(agent) === 'branch-reconcile' && !agent?.metadata?.taskApp) return { lane: 'skip' };return { lane: 'onDemand', taskType: agentScheduledType(agent), appId: agent?.metadata?.taskApp || null };}return { lane: 'queue' };diff --git a/server/services/cos.test.js b/server/services/cos.test.jsindex 40da17534f..b08a0d408c 100644--- a/server/services/cos.test.js+++ b/server/services/cos.test.js@@ -2330,6 +2330,11 @@ describe('perpetualRefillPlan — manual vs scheduled drain lane', () => {)).toEqual({ lane: 'onDemand', taskType: 'claim-issue', appId: 'app-42' });});+ it('does not refill an app-less branch-reconcile drain (its completion has no repository target)', () => {+ expect(perpetualRefillPlan(agent({ taskAnalysisType: 'branch-reconcile', taskOnDemand: true, taskApp: null }), schedule))+ .toEqual({ lane: 'skip' });+ });+it('routes a cron-scheduled perpetual drain to the on-demand lane when the run was manual', () => {expect(perpetualRefillPlan(agent({ taskAnalysisType: 'branch-reconcile', taskOnDemand: true, taskApp: 'app-1' }),diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 0351f609c7..55f7b56092 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -311,7 +311,7 @@ describe('taskSchedule', () => {describe('managed-app target task types', () => {it('keeps app-required scope explicit and separate from install-wide scope', () => {- expect([...MANAGED_APP_TARGET_TASK_TYPES]).toEqual(['private-security-assessment', 'pr-reviewer', 'issue-watcher', 'pr-watcher', 'issue-reconcile'])+ expect([...MANAGED_APP_TARGET_TASK_TYPES]).toEqual(['private-security-assessment', 'pr-reviewer', 'issue-watcher', 'pr-watcher', 'issue-reconcile', 'branch-reconcile'])expect(requiresManagedAppTarget('pr-reviewer')).toBe(true)expect(requiresManagedAppTarget('security')).toBe(false)expect(requiresManagedAppTarget('repo-sync')).toBe(false)