Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(updates): a failed lookup also starts the five-minute floor for Check for updates
Bugfixer 2db6c4856834e
diff --git a/server/update-check.test.ts b/server/update-check.test.tsindex 5c3fa6bf5e..b832f8d616 100644--- a/server/update-check.test.ts+++ b/server/update-check.test.ts@@ -164,6 +164,23 @@ describe("server update check", () => {expect(await check()).toMatchObject({ available: false, latest: "0.1.177" });});+ it("keeps presses of Check for updates to one lookup per five minutes after a failed one too", async () => {+ let now = 0;+ const fetch = vi.fn(async () => release("v0.1.177"));+ const check = createUpdateChecker({ current: "0.1.177", install: "docker", channel: "newest", fetch, now: () => now });+ await check();+ fetch.mockImplementation(async () => ({ ok: false, status: 403, json: async () => ({}) }) as Response);+ now = 10 * 60_000;+ await expect(check({ fresh: true })).rejects.toThrow("GitHub answered 403");+ now += 4 * 60_000;+ await expect(check({ fresh: true })).rejects.toThrow("GitHub answered 403");+ expect(fetch).toHaveBeenCalledTimes(2);+ now += 2 * 60_000;+ fetch.mockImplementation(async () => release("v0.1.178"));+ expect(await check({ fresh: true })).toMatchObject({ available: true, latest: "0.1.178" });+ expect(fetch).toHaveBeenCalledTimes(3);+ });+it("does not look anything up for a desktop or hosted server", async () => {const fetch = vi.fn();for (const install of ["desktop", "managed"] as const) {diff --git a/server/update-check.ts b/server/update-check.tsindex 48a0d2ca0d..3770d1c956 100644--- a/server/update-check.ts+++ b/server/update-check.ts@@ -122,6 +122,8 @@ export function createUpdateChecker(options: {let cached: { at: number; result: UpdateCheck } | undefined;/** The last answer that was read, kept past the hour for a channel that cannot be read for a while. */let lastGood: { at: number; result: UpdateCheck } | undefined;+ /** The last lookup, when it failed: a press of Check for updates within FRESH_MS gets this error, not a new lookup. */+ let failed: { at: number; error: unknown } | undefined;let inflight: Promise<UpdateCheck> | undefined;const base = (): UpdateCheck => ({current: options.current,@@ -156,6 +158,7 @@ export function createUpdateChecker(options: {return async function check({ fresh = false }: { fresh?: boolean } = {}): Promise<UpdateCheck> {if (options.install === "desktop" || options.install === "managed") return base();if (cached && now() - cached.at < (fresh ? FRESH_MS : CACHE_MS)) return cached.result;+ if (fresh && failed && now() - failed.at < FRESH_MS) throw failed.error;inflight ??= (async () => {try {const promoted = channel === "stable" ? await stable() : null;@@ -169,7 +172,11 @@ export function createUpdateChecker(options: {...updateCommand(options.install, { version: found.version, stable: promoted !== null }),};cached = lastGood = { at: now(), result };+ failed = undefined;return result;+ } catch (error) {+ failed = { at: now(), error };+ throw error;} finally {inflight = undefined;}