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
fix auto-update repair agent re-queuing every tick forever (#7468)
[._.]/ Adam Eivy65f383c20a0a
diff --git a/server/services/autoUpdateScheduler.js b/server/services/autoUpdateScheduler.jsindex 02f3dcbf37..842e529e35 100644--- a/server/services/autoUpdateScheduler.js+++ b/server/services/autoUpdateScheduler.js@@ -65,12 +65,16 @@ let ioRef = null;* `lastRunAt` first (this scheduler's own last launch), then the last recorded* update result — which covers an update the USER ran, so a manual update also* resets the interval rather than leaving an automatic one queued behind it.- * `armedAt` is the fallback for an install that has never updated: without it- * the interval would be measured from the epoch and the first tick after- * enabling would fire immediately.+ * `repairQueuedAt` covers the OTHER thing this scheduler dispatches: a repo+ * repair agent that stands down without fixing anything never produces a+ * `lastRunAt`, so without this the cooldown would never re-arm and the next+ * tick would queue a second agent immediately — repeating every 5 minutes+ * forever (#7468). `armedAt` is the fallback for an install that has never+ * updated: without it the interval would be measured from the epoch and the+ * first tick after enabling would fire immediately.*/export function updateBaselineAt(runtime, lastUpdateResult, now = Date.now()) {- const candidates = [runtime?.lastRunAt, lastUpdateResult?.completedAt, runtime?.armedAt]+ const candidates = [runtime?.lastRunAt, runtime?.repairQueuedAt, lastUpdateResult?.completedAt, runtime?.armedAt].map((value) => (typeof value === 'string' ? Date.parse(value) : NaN)).filter((value) => Number.isFinite(value));return candidates.length ? Math.max(...candidates) : now;@@ -169,10 +173,15 @@ export async function runAutoUpdateTick({ io = ioRef } = {}) {.catch((err) => ({ ready: false, needsAgent: false, reasons: ['git-unreadable'], summary: err.message, repairable: [] }));if (!read.ready && !isRepairableOnly(read)) {if (read.needsAgent && config.resolveBlockersWithAgent) {- const task = await queueRepoRepairTask(read);- if (task?.id && task.id !== runtime.repairTaskId) {- await updateChecker.recordAutoUpdateRuntime({ repairTaskId: task.id }).catch(() => undefined);- }+ await queueRepoRepairTask(read);+ // Stamp the cooldown baseline at DISPATCH, not only when an update+ // itself runs. `addTask`'s dedup (cosTaskStore.js) only collapses+ // repeat ticks onto one task while that task stays open — once the+ // agent completes (fixed or not), the task flips to `completed` and the+ // very next tick would queue a fresh one with nothing else to stop it.+ // This makes a stand-down cost one dispatch per cooldown window instead+ // of one per 5-minute tick.+ await updateChecker.recordAutoUpdateRuntime({ repairQueuedAt: new Date().toISOString() }).catch(() => undefined);}return standDown('repo-not-ready', read.summary);}diff --git a/server/services/autoUpdateScheduler.test.js b/server/services/autoUpdateScheduler.test.jsindex a99b8bc53d..6d838df5c5 100644--- a/server/services/autoUpdateScheduler.test.js+++ b/server/services/autoUpdateScheduler.test.js@@ -48,7 +48,7 @@ beforeEach(() => {__resetAutoUpdateSchedulerForTests();deps.settings.mockResolvedValue({ autoUpdate: { enabled: true, channel: 'release', minIntervalHours: 6 } });deps.gateState.mockResolvedValue({- runtime: { armedAt: iso(Date.now() - 48 * HOUR), lastRunAt: null, repairTaskId: null },+ runtime: { armedAt: iso(Date.now() - 48 * HOUR), lastRunAt: null, repairQueuedAt: null },lastUpdateResult: null,updateInProgress: false,});@@ -221,6 +221,37 @@ describe('checkout readiness gate', () => {await expect(runAutoUpdateTick({ io: {} })).resolves.toMatchObject({ reason: 'repo-not-ready' });expect(deps.queueRepair).not.toHaveBeenCalled();});++ // The core regression (#7468): a repair agent that stands down without+ // fixing the tree must not be re-queued every 5-minute tick forever.+ // `addTask`'s dedup only holds while that task stays open, and+ // `agentFinalization` marks it `completed` regardless of whether the+ // checkout ended up clean — so nothing but the cooldown baseline can bound+ // the re-dispatch.+ it('does not queue a second repair agent on the tick after the first one completed', async () => {+ deps.readRepo.mockResolvedValue(notReady);+ deps.queueRepair.mockResolvedValue({ id: 'task-1' });++ await runAutoUpdateTick({ io: {} });+ expect(deps.queueRepair).toHaveBeenCalledTimes(1);+ const stampCalls = deps.recordRuntime.mock.calls.filter(([patch]) => typeof patch.repairQueuedAt === 'string');+ expect(stampCalls).toHaveLength(1);+ const [[{ repairQueuedAt }]] = stampCalls;++ // The repair task is done by the next tick (whether or not it fixed+ // anything, same as agentFinalization marking it `completed` either way),+ // but the baseline stamped above is what the cooldown reads now.+ deps.queueRepair.mockClear();+ deps.gateState.mockResolvedValue({+ runtime: { armedAt: iso(Date.now() - 48 * HOUR), lastRunAt: null, repairQueuedAt },+ lastUpdateResult: null,+ updateInProgress: false,+ });++ const result = await runAutoUpdateTick({ io: {} });+ expect(result).toMatchObject({ ran: false, reason: 'cooldown' });+ expect(deps.queueRepair).not.toHaveBeenCalled();+ });});describe('poll registration', () => {@@ -258,4 +289,16 @@ describe('interval baseline', () => {const now = 1_000_000;expect(updateBaselineAt({}, null, now)).toBe(now);});++ // A repair-agent DISPATCH also resets the clock (#7468) — without this, a+ // stand-down agent (no lastRunAt, since no update ever ran) would leave the+ // baseline stuck at armedAt forever and every tick would re-queue.+ it('also measures the interval from a repair-agent dispatch', () => {+ const now = Date.parse('2026-01-02T00:00:00Z');+ expect(updateBaselineAt(+ { repairQueuedAt: '2026-01-01T18:00:00Z', armedAt: '2025-12-01T00:00:00Z' },+ null,+ now,+ )).toBe(Date.parse('2026-01-01T18:00:00Z'));+ });});diff --git a/server/services/updateChecker.js b/server/services/updateChecker.jsindex 4f09c00536..849e2343a6 100644--- a/server/services/updateChecker.js+++ b/server/services/updateChecker.js@@ -372,7 +372,12 @@ function normalizeAutoUpdateRuntime(raw) {lastRunAt: typeof source.lastRunAt === 'string' ? source.lastRunAt : null,lastOutcome: typeof source.lastOutcome === 'string' ? source.lastOutcome : null,lastSkip: isPlainObject(source.lastSkip) ? source.lastSkip : null,- repairTaskId: typeof source.repairTaskId === 'string' ? source.repairTaskId : null,+ // When a repo-repair agent was last DISPATCHED (queued), not when it+ // finished — `autoUpdateScheduler.updateBaselineAt` folds this into the+ // cooldown baseline so a repair agent that stands down without fixing+ // anything costs one dispatch per cooldown window, not one per 5-minute+ // tick. See root AGENTS.md "AI Provider Usage Policy".+ repairQueuedAt: typeof source.repairQueuedAt === 'string' ? source.repairQueuedAt : null,};}diff --git a/server/services/updateRepoReadiness.js b/server/services/updateRepoReadiness.jsindex 854783eb0d..06b7c21c84 100644--- a/server/services/updateRepoReadiness.js+++ b/server/services/updateRepoReadiness.js@@ -241,10 +241,15 @@ export async function prepareUpdateRepo({ repoPath = PATHS.root } = {}) {* unpushed commit, an interrupted rebase, conflict markers.** The first line is constant, so `addTask`'s description+app dedup collapses- * every subsequent tick onto the one open task instead of queueing an agent per- * poll. The task store is imported lazily — this module is on the update path,- * the repair branch is rare, and a static import would pull the whole CoS state- * graph into that closure.+ * every subsequent tick onto the one open task ONLY WHILE THAT TASK STAYS+ * OPEN — once the agent finishes (fixed or not) the task flips to `completed`+ * and the dedup no longer matches. What actually bounds re-dispatch after that+ * is the caller: `autoUpdateScheduler.runAutoUpdateTick` stamps the cooldown+ * baseline (`repairQueuedAt`) right after this call returns, so a stand-down+ * agent costs one dispatch per cooldown window rather than one per poll+ * (#7468). The task store is imported lazily — this module is on the update+ * path, the repair branch is rare, and a static import would pull the whole+ * CoS state graph into that closure.** Never rejects: a failed enqueue must not mask the readiness refusal itself.*