Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Fixes milind-soni/OpenMausBot#5581

handsomestWeib0e72dbe67f0
diff --git a/server/drivers/acp/model-catalog.ts b/server/drivers/acp/model-catalog.ts
index de25ce4896..643dbdc857 100644
--- a/server/drivers/acp/model-catalog.ts
+++ b/server/drivers/acp/model-catalog.ts
@@ -5,7 +5,8 @@ export interface AcpModelCatalog {
models: ModelCatalog;
/** The models the signed-in account offers, once the engine has listed them. */
accountModels: ReadonlySet<string> | null;
- /** True while the list is the driver's fixed one or a failed read's leftover, not one the engine gave. */
+ /** True while this process has not been given the list by the engine: the driver's fixed one, a saved stand-in,
+ * or a failed read's leftover. */
readonly unconfirmed: boolean;
/** A read already under way is shared; a fresh one waits for a cached one under way, then reads again. */
refresh(fresh?: boolean): Promise<void>;
@@ -20,7 +21,8 @@ export function acpModelCatalog(input: {
const { instanceId, resolve } = input;
const saved = resolve ? readStartupModelCacheEntry(instanceId) : null;
let models = input.startFromSaved ? saved?.catalog ?? input.fixed : input.fixed;
- let readFromEngine = Boolean(saved?.checkedAt);
+ // A previous run's checkedAt only lets the file stand in. This process confirms the ids when its own read returns them.
+ let readFromEngine = false;
let accountModels: ReadonlySet<string> | null = saved?.checkedAt ? idsOf(saved.catalog) : null;
let current: { fresh: boolean; done: Promise<void> } | null = null;
diff --git a/server/startup-model-catalog.test.ts b/server/startup-model-catalog.test.ts
index 12f38220cd..f2c02abc18 100644
--- a/server/startup-model-catalog.test.ts
+++ b/server/startup-model-catalog.test.ts
@@ -84,7 +84,7 @@ function slowDriver(gate: Promise<ModelCatalog>): {
return { driver, seenByTurn: () => seen };
}
-const acpSupport = (resolveModels: () => Promise<ModelCatalog>): AcpSupport => ({
+const acpSupport = (resolveModels: NonNullable<AcpSupport["resolveModels"]>): AcpSupport => ({
driverKind: "startup-catalog-test",
displayName: "Startup catalog",
models: { default: "static-model", options: [{ id: "static-model", label: "Static" }] },
@@ -266,6 +266,44 @@ describe("startup model catalogs", () => {
expect(seenByTurn()).toEqual(FRESH);
});
+ it("a saved catalog stands in without counting as confirmed, and Refresh drops ids the engine no longer returns", async () => {
+ writeStartupModelCache("saved-gone", {
+ default: "gone-model",
+ options: [{ id: "gone-model", label: "Gone" }, { id: "kept-model", label: "Kept" }],
+ });
+ let reads = 0;
+ const freshSeen: boolean[] = [];
+ const driver = createAcpDriver({
+ ...acpSupport((_env, _config, _id, fresh) => {
+ reads += 1;
+ freshSeen.push(fresh === true);
+ return { default: "kept-model", options: [{ id: "kept-model", label: "Kept" }] };
+ }),
+ // Not probed at startup, so a recent file is the only list until Refresh.
+ resolveModelsOnCreate: false,
+ });
+ const instance = await driver.create({
+ instanceId: "saved-gone",
+ displayName: "Saved gone",
+ environment: {},
+ enabled: true,
+ config: driver.defaultConfig(),
+ });
+ try {
+ expect(instance.models.options.map((option) => option.id)).toEqual(["gone-model", "kept-model"]);
+ expect(instance.modelsUnconfirmed).toBe(true);
+ expect(reads).toBe(0);
+ await instance.refreshModels?.();
+ expect(reads).toBe(1);
+ expect(freshSeen).toEqual([true]);
+ expect(instance.models).toEqual({ default: "kept-model", options: [{ id: "kept-model", label: "Kept" }] });
+ expect(instance.modelsUnconfirmed).toBe(false);
+ expect(readStartupModelCache("saved-gone")?.options.map((option) => option.id)).toEqual(["kept-model"]);
+ } finally {
+ await instance.dispose();
+ }
+ });
+
it("an ACP engine serves a saved catalog and lets the turn wait for the refresh", async () => {
seedBots();
writeStartupModelCache("cursor", CACHED, STALE);