Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
fix: reserve update backoff time after cache startup (#759)
outlier27-cellbb6e95c4c13d
diff --git a/archify.zip b/archify.zipindex 4de4295b..e78edcd1 100644Binary files a/archify.zip and b/archify.zip differdiff --git a/archify/scripts/check-update.mjs b/archify/scripts/check-update.mjsindex 369eeac0..053d866b 100644--- a/archify/scripts/check-update.mjs+++ b/archify/scripts/check-update.mjs@@ -1473,6 +1473,7 @@ export async function checkForUpdate({now = Date.now,random = Math.random,timeoutMs = DEFAULT_TIMEOUT_MS,+ fetchDeadlineNs,} = {}) {if (updatesDisabled()) return silent('disabled');if (typeof fetchImpl !== 'function') return silent('runtime-unavailable');@@ -1529,10 +1530,13 @@ export async function checkForUpdate({}let fetched;try {+ const remainingFetchMs = fetchDeadlineNs === undefined ? timeoutMs+ : Math.min(timeoutMs, Number(fetchDeadlineNs - process.hrtime.bigint()) / 1_000_000);+ if (remainingFetchMs <= 0) throw new Error('update fetch deadline expired during cache preparation');fetched = await fetchCandidate({fetchImpl,manifestUrl: localRelease.updateManifestUrl,- timeoutMs,+ timeoutMs: remainingFetchMs,});} catch (error) {const withdrawn = error instanceof ManifestWithdrawnError;diff --git a/archify/scripts/delivery-update-child.mjs b/archify/scripts/delivery-update-child.mjsindex dfe6ad84..7c998f0a 100644--- a/archify/scripts/delivery-update-child.mjs+++ b/archify/scripts/delivery-update-child.mjs@@ -19,5 +19,8 @@ const result = await checkForUpdate({// Leave time to record a failed fetch, so a slow network backs off instead// of being killed before its result reaches the cache.timeoutMs: Math.max(1, Math.floor(remainingMs - 150)),+ // Recompute the remaining fetch budget after cache preparation, so that+ // startup work cannot consume the failure-recording reserve unnoticed.+ fetchDeadlineNs: deadlineAt - 150_000_000n,});process.stdout.write(`${JSON.stringify(result)}\n`);diff --git a/test/delivery-update.test.mjs b/test/delivery-update.test.mjsindex a7a02bd9..1c859459 100644--- a/test/delivery-update.test.mjs+++ b/test/delivery-update.test.mjs@@ -102,6 +102,40 @@ globalThis.fetch = (_url, { signal }) => {assert.equal(fs.readFileSync(calls, 'utf8'), 'x');});+test('cache startup time is deducted before the update fetch timeout starts', async (t) => {+ const testFixture = fixture(t);+ const calls = path.join(testFixture.root, 'fetch-calls');+ const startup = path.join(testFixture.root, 'startup-delay');+ const preload = path.join(testFixture.root, 'delayed-cache.mjs');+ fs.writeFileSync(preload, `import fs from 'node:fs/promises';+import syncFs from 'node:fs';+const open = fs.open;+let delayed = false;+fs.open = async (...args) => {+ if (!delayed && String(args[0]) === ${JSON.stringify(testFixture.releasePath)}) {+ delayed = true;+ await new Promise(resolve => setTimeout(resolve, 300));+ syncFs.appendFileSync(${JSON.stringify(startup)}, 'delayed');+ }+ return open.apply(fs, args);+};+globalThis.fetch = (_url, { signal }) => {+ syncFs.appendFileSync(${JSON.stringify(calls)}, 'x');+ return new Promise((_resolve, reject) => signal.addEventListener('abort', () => reject(signal.reason)));+};+`);+ const slowEnv = { ...env(testFixture), NODE_OPTIONS: `--import=${pathToFileURL(preload).href}` };+ const first = await startDeliveryUpdateCheck({ env: slowEnv, deadlineMs: 800 });+ assert.equal(fs.readFileSync(startup, 'utf8'), 'delayed');+ assert.equal(first.reason, 'check-failed');+ const firstCalls = fs.existsSync(calls) ? fs.readFileSync(calls, 'utf8') : '';+ assert.ok(firstCalls === '' || firstCalls === 'x', 'an expired budget may skip the fetch');+ let retryCalls = 0;+ const second = await checkForUpdate({ ...testFixture, fetchImpl: async () => { retryCalls += 1; throw new Error('unexpected retry'); } });+ assert.equal(second.status, 'silent');+ assert.equal(retryCalls, 0, 'the failed check must persist backoff');+});+test('a synchronous renderer delay does not turn a completed check into a timeout', async (t) => {const testFixture = fixture(t);await seed(testFixture);