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: surface auto-update runtime write failures instead of a normal cooldown (#7530)

[._.]/ Adam Eivy8c52b0471de8
diff --git a/client/src/components/apps/tabs/AutoUpdatePanel.jsx b/client/src/components/apps/tabs/AutoUpdatePanel.jsx
index 111d8d3266..ca6b85bf99 100644
--- a/client/src/components/apps/tabs/AutoUpdatePanel.jsx
+++ b/client/src/components/apps/tabs/AutoUpdatePanel.jsx
@@ -17,6 +17,7 @@ const SKIP_LABELS = {
'status-unavailable': 'Could not read the update status',
'activity-unknown': 'Could not read the activity snapshot',
'launch-failed': 'The last launch was refused',
+ 'runtime-persistence-unavailable': 'Could not save the updater state',
};
const CHANNELS = [
diff --git a/server/services/autoUpdateScheduler.js b/server/services/autoUpdateScheduler.js
index 9804acdafc..600ebc85a5 100644
--- a/server/services/autoUpdateScheduler.js
+++ b/server/services/autoUpdateScheduler.js
@@ -106,6 +106,47 @@ export function repairDispatchDue(runtime, minIntervalMs, now = Date.now()) {
*/
const isRepairableOnly = (verdict) => verdict.reasons.length === 0 && verdict.repairable.length > 0;
+/**
+ * Runtime-write failure tracking (bounded, transition-based).
+ *
+ * `recordAutoUpdateRuntime` persists to the same `update.json` every write
+ * below lands in, so it fails for reasons that have nothing to do with what
+ * the update pipeline is waiting on (a full disk, a permissions change under
+ * `data/`, a corrupted state file). Every call site here used to discard that
+ * rejection with `.catch(() => undefined)`, which made a real persistence
+ * outage indistinguishable from "nothing to report" — the defect this module
+ * exists to close. Tracked per OPERATION so one stuck write doesn't drown a
+ * healthy one, and logged only on the transition into/out of failure so a
+ * broken disk doesn't flood the log every five-minute tick.
+ */
+const failingRuntimeWrites = new Set();
+
+/**
+ * Write a patch to the auto-update runtime record. Never throws — logs (once
+ * per operation, not per tick) on failure and on recovery.
+ *
+ * @returns {Promise<boolean>} whether the write landed.
+ */
+async function writeRuntime(patch, operation) {
+ return updateChecker.recordAutoUpdateRuntime(patch).then(
+ () => {
+ if (failingRuntimeWrites.delete(operation)) {
+ console.log(`✅ Auto-update runtime write recovered (${operation})`);
+ }
+ return true;
+ },
+ (err) => {
+ 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}`);
+ }
+ return false;
+ },
+ );
+}
+
/** Record the skip and log it once per distinct reason, not once per tick. */
let lastLoggedSkip = null;
async function standDown(reason, detail) {
@@ -114,9 +155,9 @@ async function standDown(reason, detail) {
console.log(`🕒 Auto-update standing by — ${line}`);
lastLoggedSkip = line;
}
- await updateChecker.recordAutoUpdateRuntime({
+ await writeRuntime({
lastSkip: { reason, detail: detail || null, at: new Date().toISOString() },
- }).catch(() => undefined);
+ }, 'skip');
return { ran: false, reason, detail: detail || null };
}
@@ -163,7 +204,14 @@ export async function runAutoUpdateTick({ io = ioRef } = {}) {
// 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.
if (!runtime.armedAt) {
- await updateChecker.recordAutoUpdateRuntime({ armedAt: new Date().toISOString() }).catch(() => undefined);
+ const armed = await writeRuntime({ armedAt: new Date().toISOString() }, 'arm');
+ // Without a persisted arming point, `updateBaselineAt` falls back to `now`
+ // on every tick (see its own doc comment) — a broken write here would
+ // otherwise report the full configured cooldown, indistinguishable from a
+ // freshly-armed install, on every tick forever. Stop outright instead.
+ if (!armed) {
+ return standDown('runtime-persistence-unavailable', 'could not persist the arming timestamp');
+ }
}
if (updateInProgress) return standDown('update-in-progress', 'an update is already running');
@@ -202,7 +250,7 @@ export async function runAutoUpdateTick({ io = ioRef } = {}) {
// where `task` is null) would lock out every retry for the same
// window while nothing was actually queued.
if (task?.id) {
- await updateChecker.recordAutoUpdateRuntime({ repairQueuedAt: new Date().toISOString() }).catch(() => undefined);
+ await writeRuntime({ repairQueuedAt: new Date().toISOString() }, 'repair-queued');
}
}
return standDown('repo-not-ready', read.summary);
@@ -234,15 +282,15 @@ export async function runAutoUpdateTick({ io = ioRef } = {}) {
lastLoggedSkip = null;
console.log(`⬆️ Auto-update starting (${config.channel} channel) — ${availability.detail}`);
- await updateChecker.recordAutoUpdateRuntime({
+ await writeRuntime({
lastAttemptAt: new Date().toISOString(),
lastSkip: null,
- }).catch(() => undefined);
+ }, 'attempt');
const outcome = await launchUpdateFor(config.channel, io).catch((err) => ({ ok: false, message: err.message }));
if (!outcome.ok) {
console.error(`❌ Auto-update could not start: ${outcome.message}`);
- await updateChecker.recordAutoUpdateRuntime({ lastOutcome: `failed: ${outcome.message}` }).catch(() => undefined);
+ await writeRuntime({ lastOutcome: `failed: ${outcome.message}` }, 'outcome');
return { ran: false, reason: 'launch-failed', detail: outcome.message, channel: config.channel };
}
@@ -250,11 +298,23 @@ export async function runAutoUpdateTick({ io = ioRef } = {}) {
// not live to see: update.sh pm2-deletes this server partway through. Without
// it, a restart that lands before the update result is recorded would find
// the interval already elapsed and immediately launch a second update.
- await updateChecker.recordAutoUpdateRuntime({
+ //
+ // The launch has already happened by this point — `setUpdateInProgress`'s
+ // persisted lock (acquired inside `launchUpdateFor`, not here) is what
+ // actually prevents a second dispatch, not this bookkeeping write. If IT
+ // fails, the launch itself must not be undone or retried; the tick result
+ // just carries a degradation flag so callers know the runtime record may be
+ // stale until a later write succeeds.
+ const recorded = await writeRuntime({
lastRunAt: new Date().toISOString(),
lastOutcome: `started (${config.channel})`,
- }).catch(() => undefined);
- return { ran: true, channel: config.channel, detail: availability.detail };
+ }, 'launch-record');
+ return {
+ ran: true,
+ channel: config.channel,
+ detail: availability.detail,
+ ...(recorded ? {} : { persistenceWarning: 'launched, but could not record it — cooldown timing may be stale until the next successful write' }),
+ };
}
/**
@@ -332,4 +392,5 @@ export function __resetAutoUpdateSchedulerForTests() {
registrationSignature = null;
lastLoggedSkip = null;
ioRef = null;
+ failingRuntimeWrites.clear();
}
diff --git a/server/services/autoUpdateScheduler.test.js b/server/services/autoUpdateScheduler.test.js
index 772952ee71..c0006ed6a1 100644
--- a/server/services/autoUpdateScheduler.test.js
+++ b/server/services/autoUpdateScheduler.test.js
@@ -283,6 +283,104 @@ describe('checkout readiness gate', () => {
});
});
+describe('runtime-write failure handling', () => {
+ // The core regression (#7530): a persistence outage on the FIRST tick
+ // after enabling was reported as an ordinary, freshly-armed cooldown
+ // (`updateBaselineAt` falls back to `now` with no `armedAt`), forever —
+ // indistinguishable from nothing to report. It must surface as its own
+ // reason and never fall through to the update/repair checks.
+ it('reports a persistence-unavailable outcome when the initial arming write fails, without reaching the update gates', async () => {
+ deps.gateState.mockResolvedValue({
+ runtime: { armedAt: null, lastRunAt: null, repairQueuedAt: null },
+ lastUpdateResult: null,
+ updateInProgress: false,
+ });
+ deps.recordRuntime.mockRejectedValue(Object.assign(new Error('disk full'), { code: 'ENOSPC' }));
+
+ const result = await runAutoUpdateTick({ io: {} });
+ expect(result).toMatchObject({ ran: false, reason: 'runtime-persistence-unavailable' });
+ expect(deps.status).not.toHaveBeenCalled();
+ expect(deps.selfUpdate).not.toHaveBeenCalled();
+ expect(deps.appUpdate).not.toHaveBeenCalled();
+ });
+
+ // Repeated ticks against a still-broken write must keep reporting the same
+ // 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 () => {
+ deps.gateState.mockResolvedValue({
+ runtime: { armedAt: null, lastRunAt: null, repairQueuedAt: null },
+ lastUpdateResult: null,
+ updateInProgress: false,
+ });
+ deps.recordRuntime.mockRejectedValue(new Error('disk full'));
+
+ const first = await runAutoUpdateTick({ io: {} });
+ const second = await runAutoUpdateTick({ io: {} });
+ expect(first).toMatchObject({ ran: false, reason: 'runtime-persistence-unavailable' });
+ expect(second).toMatchObject({ ran: false, reason: 'runtime-persistence-unavailable' });
+ });
+
+ // 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({
+ runtime: { armedAt: null, lastRunAt: null, repairQueuedAt: null },
+ lastUpdateResult: null,
+ updateInProgress: false,
+ });
+ deps.recordRuntime.mockRejectedValueOnce(new Error('disk full'));
+ deps.recordRuntime.mockResolvedValue({});
+
+ 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.
+ deps.gateState.mockResolvedValue({
+ runtime: { armedAt: iso(Date.now() - 48 * HOUR), lastRunAt: null, repairQueuedAt: null },
+ lastUpdateResult: null,
+ updateInProgress: false,
+ });
+ const second = await runAutoUpdateTick({ io: {} });
+ expect(second).toMatchObject({ ran: true, channel: 'release' });
+ });
+
+ // A write failure recording an ORDINARY stand-down (cooldown, busy, …) must
+ // not be discarded silently — it still has to log something a person can
+ // find, distinct from the tick's own reported reason.
+ it('logs, but does not otherwise change, a runtime write failure while recording an ordinary skip', async () => {
+ deps.gateState.mockResolvedValue({
+ runtime: { armedAt: iso(Date.now() - 2 * HOUR), lastRunAt: null, repairQueuedAt: null },
+ lastUpdateResult: null,
+ updateInProgress: false,
+ });
+ deps.recordRuntime.mockRejectedValue(new Error('disk full'));
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+
+ const result = await runAutoUpdateTick({ io: {} });
+ expect(result).toMatchObject({ ran: false, reason: 'cooldown' });
+ expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('runtime write failed (skip)'));
+ errorSpy.mockRestore();
+ });
+
+ // The launch itself must never be treated as undone or retried because its
+ // OWN bookkeeping write failed afterward — `setUpdateInProgress`'s
+ // persisted lock, not this write, is what guards against a second launch.
+ // The caller instead gets an explicit degradation flag.
+ it('preserves the launched outcome and flags a post-launch record failure without retrying', async () => {
+ deps.recordRuntime.mockImplementation((patch) => {
+ if (patch && typeof patch.lastRunAt === 'string') return Promise.reject(new Error('disk full'));
+ return Promise.resolve({});
+ });
+
+ const result = await runAutoUpdateTick({ io: {} });
+ expect(result).toMatchObject({ ran: true, channel: 'release', persistenceWarning: expect.any(String) });
+ expect(deps.selfUpdate).toHaveBeenCalledTimes(1);
+ });
+});
+
describe('poll registration', () => {
it('registers nothing while the feature is off, and cancels a live poll', async () => {
deps.settings.mockResolvedValue({ autoUpdate: { enabled: false } });