Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(cli): cache a failed update check, and bound it to 5 s

KageBinary226ca018127a
diff --git a/ix-cli/src/cli/__tests__/update-check-cache.test.ts b/ix-cli/src/cli/__tests__/update-check-cache.test.ts
new file mode 100644
index 00000000..83642829
--- /dev/null
+++ b/ix-cli/src/cli/__tests__/update-check-cache.test.ts
@@ -0,0 +1,40 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+// A failed background update check wrote no cache, so every later command
+// fetched again: three requests per command against GitHub's 60/hour
+// unauthenticated limit, which kept a rate-limited user rate-limited.
+describe("checkForUpdate when GitHub does not answer", () => {
+ let home: string;
+
+ beforeEach(() => {
+ // upgrade.ts binds IX_HOME at load time, so load it fresh under a temp home.
+ vi.resetModules();
+ home = mkdtempSync(join(tmpdir(), "ix-update-check-"));
+ process.env.IX_HOME = home;
+ });
+
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ delete process.env.IX_HOME;
+ rmSync(home, { recursive: true, force: true });
+ });
+
+ it("records the attempt, so the next command does not ask again within the hour", async () => {
+ const fetch = vi.fn(async () => new Response("rate limited", { status: 403 }));
+ vi.stubGlobal("fetch", fetch);
+ const { checkForUpdate } = await import("../commands/upgrade.js");
+
+ await checkForUpdate();
+ expect(fetch).toHaveBeenCalledTimes(3);
+ const cache = JSON.parse(readFileSync(join(home, ".version-check.json"), "utf8")) as { checkedAt: number };
+ expect(Date.now() - cache.checkedAt).toBeLessThan(60_000);
+
+ await checkForUpdate();
+ expect(fetch, "answered from the cache").toHaveBeenCalledTimes(3);
+ });
+});
diff --git a/ix-cli/src/cli/commands/upgrade.ts b/ix-cli/src/cli/commands/upgrade.ts
index 00dc136d..b0f95b1b 100644
--- a/ix-cli/src/cli/commands/upgrade.ts
+++ b/ix-cli/src/cli/commands/upgrade.ts
@@ -1282,6 +1282,9 @@ function requestedFormat(argv: readonly string[]): string | undefined {
return undefined;
}
+/** Per-request bound for the background check on ordinary commands. */
+const BACKGROUND_CHECK_TIMEOUT_MS = 5_000;
+
export async function checkForUpdate(): Promise<void> {
const current = getCurrentVersion();
const cache = readCache();
@@ -1299,12 +1302,23 @@ export async function checkForUpdate(): Promise<void> {
return;
}
- Promise.all([
- fetchLatestRelease(GITHUB_REPO),
- fetchLatestRelease(COMPASS_DIST_REPO),
- fetchLatestRelease(MEMORY_LAYER_DIST_REPO),
+ // Returned so a caller (or a test) can wait for it; main.ts does not. The
+ // fetches are short: nothing awaits them, but an open request still keeps
+ // the process alive after the command's output, and 30 s of that on every
+ // command behind a stalling proxy is a hang.
+ return Promise.all([
+ fetchLatestRelease(GITHUB_REPO, BACKGROUND_CHECK_TIMEOUT_MS),
+ fetchLatestRelease(COMPASS_DIST_REPO, BACKGROUND_CHECK_TIMEOUT_MS),
+ fetchLatestRelease(MEMORY_LAYER_DIST_REPO, BACKGROUND_CHECK_TIMEOUT_MS),
]).then(([latest, compassLatest, backendLatest]) => {
- if (!latest) return;
+ if (!latest) {
+ // Record the attempt anyway, keeping whatever was known. Without it a
+ // failed check (GitHub blocked, rate-limited, offline) was retried by
+ // every command: three more requests against a 60/hour unauthenticated
+ // limit each time, which kept a rate-limited user rate-limited.
+ writeCache(cache?.latest ?? current, cache?.compassLatest, cache?.backendLatest);
+ return;
+ }
writeCache(latest, compassLatest ?? undefined, backendLatest ?? undefined);
const hasCliUpdate = isNewer(latest, current);
const hasCompassUpdate = shouldOfferCompassUpgrade(compassLatest ?? undefined);