Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(opencode): publish refresh prices after overlapping status reads
leonongoing9ff76455fba5
diff --git a/server/drivers/acp/opencode-go.ts b/server/drivers/acp/opencode-go.tsindex 881036d152..4d3d45de4a 100644--- a/server/drivers/acp/opencode-go.ts+++ b/server/drivers/acp/opencode-go.ts@@ -726,11 +726,17 @@ const support = (resolveModels: async (environment, config, instanceId, fresh) => {priceCatalog = undefined;generation++;- if (fresh) markOpenCodeCatalogRefreshed(instanceId, (sources.now ?? Date.now)());- await refreshLiveModelLists(environment, { lists: sources.liveLists, fetch: sources.fetch, now: sources.now });- declareLiveOpenCodeModels(environment, sources.liveLists);- const catalog = await discover(environment, config.cli, { refresh: fresh === true });- return mergeLocalInject(catalog, environment);+ let catalog: ModelCatalog | undefined;+ try {+ if (fresh) markOpenCodeCatalogRefreshed(instanceId, (sources.now ?? Date.now)());+ await refreshLiveModelLists(environment, { lists: sources.liveLists, fetch: sources.fetch, now: sources.now });+ declareLiveOpenCodeModels(environment, sources.liveLists);+ catalog = await loadCatalog(environment, config.cli, { refresh: fresh === true });+ return mergeLocalInject(catalog, environment);+ } finally {+ generation++;+ priceCatalog = catalog;+ }},buildPromptText: (turn) => turn.system ? `${turn.system}\n\n${turn.text}` : turn.text,};diff --git a/server/drivers/acp/opencode-price-holds.test.ts b/server/drivers/acp/opencode-price-holds.test.tsindex 07e2ebe59d..67185c1a1d 100644--- a/server/drivers/acp/opencode-price-holds.test.ts+++ b/server/drivers/acp/opencode-price-holds.test.ts@@ -142,6 +142,53 @@ it("does not restore old status prices after a refresh invalidates them", async} finally { pending.resolve(prices("free")); await status; }});+it.each([+ { outcome: "paid", statusFirst: false },+ { outcome: "paid", statusFirst: true },+ { outcome: "failed", statusFirst: false },+ { outcome: "failed", statusFirst: true },+])("keeps the final $outcome refresh facts with an overlapping status read (status first: $statusFirst)", async ({ outcome, statusFirst }) => {+ const dir = mkdtempSync(join(tmpdir(), "omb-price-refresh-status-"));+ dirs.push(dir);+ const id = `refresh-status-${outcome}-${statusFirst}`;+ savedListing(id);+ const refreshStarted = deferred<void>();+ const refreshGate = deferred<void>();+ const statusStarted = deferred<void>();+ const statusGate = deferred<ModelCatalog>();+ let first = true;+ const driver = createOpenCodeDriver(async () => {+ if (first) {+ first = false;+ refreshStarted.resolve();+ await refreshGate.promise;+ if (outcome === "failed") throw new Error("fixture refresh unavailable");+ return prices("paid");+ }+ statusStarted.resolve();+ return statusGate.promise;+ }, { everyMs: Infinity, liveLists: [] });+ const instance = await driver.create(lifecycleInput(id, dir, "current", ""));+ instances.push(instance);+ const refresh = instance.refreshModels!();+ let status: Promise<unknown> = Promise.resolve();+ try {+ await refreshStarted.promise;+ status = instance.snapshot();+ await statusStarted.promise;+ if (statusFirst) { statusGate.resolve(prices("free")); await status; }+ refreshGate.resolve();+ await refresh;+ if (!statusFirst) statusGate.resolve(prices("free"));+ await status;+ expect(await otherHeld(instance, dir)).toBeNull();+ } finally {+ refreshGate.resolve();+ statusGate.resolve(prices("free"));+ await Promise.all([refresh, status]);+ }+});+it("uses retained prices when the catalog default is absent from the live session", async () => {const dir = mkdtempSync(join(tmpdir(), "omb-price-fallback-"));dirs.push(dir);