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: check for an in-progress update before attempting the arming write (#7530)
[._.]/ Adam Eivyeb1746baa165
diff --git a/server/services/autoUpdateScheduler.js b/server/services/autoUpdateScheduler.jsindex 600ebc85a5..efb03290e0 100644--- a/server/services/autoUpdateScheduler.js+++ b/server/services/autoUpdateScheduler.js@@ -139,8 +139,8 @@ async function writeRuntime(patch, operation) {if (!failingRuntimeWrites.has(operation)) {failingRuntimeWrites.add(operation);// `err.code` (ENOSPC, EACCES, …) over `err.message`, which for an fs- // error embeds the full local path.- console.error(`❌ Auto-update runtime write failed (${operation}): ${err.code || err.message}`);+ // error embeds the full local path. Guard against a non-Error reject.+ console.error(`❌ Auto-update runtime write failed (${operation}): ${err?.code || err?.message || String(err)}`);}return false;},@@ -200,6 +200,12 @@ export async function runAutoUpdateTick({ io = ioRef } = {}) {// walks every file under client/src, and the cooldown discards the answer on// 71 of every 72 ticks at the default interval.const { runtime, lastUpdateResult, updateInProgress } = await updateChecker.getAutoUpdateGateState();+ // Checked BEFORE the arming write below: an update already running is a+ // real, useful reason to stand down on its own, and it must not be masked+ // by a coincidental persistence failure on the very tick the feature was+ // enabled (an install has both flags open only in that one window).+ if (updateInProgress) return standDown('update-in-progress', 'an update is already running');+// Stamp the arming point on the first tick after the feature goes on, so the// interval has something to measure from on an install that has never// updated. Written once — a re-stamp on every boot would move the deadline.@@ -214,8 +220,6 @@ export async function runAutoUpdateTick({ io = ioRef } = {}) {}}- if (updateInProgress) return standDown('update-in-progress', 'an update is already running');-const now = Date.now();const baselineAt = updateBaselineAt(runtime, lastUpdateResult, now);const elapsedMs = now - baselineAt;diff --git a/server/services/autoUpdateScheduler.test.js b/server/services/autoUpdateScheduler.test.jsindex c0006ed6a1..d7326a0a4c 100644--- a/server/services/autoUpdateScheduler.test.js+++ b/server/services/autoUpdateScheduler.test.js@@ -308,43 +308,64 @@ describe('runtime-write failure handling', () => {// outcome (the read never sees a persisted armedAt), not silently drift// back into a normal cooldown once the "first tick after enabling" framing// no longer applies.- it('keeps reporting persistence-unavailable across repeated ticks while the write stays broken', async () => {+ it('keeps reporting persistence-unavailable across repeated ticks while the write stays broken, without flooding the log', async () => {deps.gateState.mockResolvedValue({runtime: { armedAt: null, lastRunAt: null, repairQueuedAt: null },lastUpdateResult: null,updateInProgress: false,});deps.recordRuntime.mockRejectedValue(new Error('disk full'));+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});const first = await runAutoUpdateTick({ io: {} });const second = await runAutoUpdateTick({ io: {} });+ const third = await runAutoUpdateTick({ io: {} });expect(first).toMatchObject({ ran: false, reason: 'runtime-persistence-unavailable' });expect(second).toMatchObject({ ran: false, reason: 'runtime-persistence-unavailable' });+ expect(third).toMatchObject({ ran: false, reason: 'runtime-persistence-unavailable' });+ // One log line for the 'arm' operation, no matter how many ticks it fails+ // on — dedup is per operation, not per call.+ const armFailures = errorSpy.mock.calls.filter(([line]) => line.includes('runtime write failed (arm)'));+ expect(armFailures).toHaveLength(1);+ errorSpy.mockRestore();});// Once the write actually lands, the tick must fall through to ordinary// gating again — a transient outage must not wedge the scheduler forever.it('resumes normal cooldown behavior once the arming write recovers', async () => {- deps.gateState.mockResolvedValueOnce({+ deps.gateState.mockResolvedValue({runtime: { armedAt: null, lastRunAt: null, repairQueuedAt: null },lastUpdateResult: null,updateInProgress: false,});deps.recordRuntime.mockRejectedValueOnce(new Error('disk full'));deps.recordRuntime.mockResolvedValue({});+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});const first = await runAutoUpdateTick({ io: {} });expect(first).toMatchObject({ ran: false, reason: 'runtime-persistence-unavailable' });- // The next read reflects what a real disk read would now show: the write- // above landed, so `armedAt` is persisted from well outside the cooldown.+ // The write now lands (recovery), stamping `armedAt` at "now" — correctly+ // still a fresh cooldown, since this install has never updated before.+ const second = await runAutoUpdateTick({ io: {} });+ expect(second).toMatchObject({ ran: false, reason: 'cooldown' });+ expect(logSpy.mock.calls.some(([line]) => line.includes('runtime write recovered (arm)'))).toBe(true);+ const [{ armedAt }] = deps.recordRuntime.mock.calls.find(([patch]) => typeof patch.armedAt === 'string');+ logSpy.mockRestore();++ // A later tick reads that now-persisted `armedAt`, well outside the+ // interval — ordinary gating resumes with no lingering persistence flag.deps.gateState.mockResolvedValue({- runtime: { armedAt: iso(Date.now() - 48 * HOUR), lastRunAt: null, repairQueuedAt: null },+ runtime: { armedAt, lastRunAt: null, repairQueuedAt: null },lastUpdateResult: null,updateInProgress: false,});- const second = await runAutoUpdateTick({ io: {} });- expect(second).toMatchObject({ ran: true, channel: 'release' });+ vi.useFakeTimers();+ vi.setSystemTime(Date.parse(armedAt) + 7 * HOUR);+ const third = await runAutoUpdateTick({ io: {} });+ vi.useRealTimers();+ expect(third).toMatchObject({ ran: true, channel: 'release' });+ expect(third.persistenceWarning).toBeUndefined();});// A write failure recording an ORDINARY stand-down (cooldown, busy, …) must