Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Hydrate the OpenRouter catalog on cold runtime resolution (#678)

Joshua France96b32bbdca24
diff --git a/src/harness/harness-router.ts b/src/harness/harness-router.ts
index 280896272..6ee75fd4b 100644
--- a/src/harness/harness-router.ts
+++ b/src/harness/harness-router.ts
@@ -1,5 +1,11 @@
import type { ScopedConfigStore } from "../resolution/config-store.ts";
-import { defaultModelForHarness, isHarnessId, modelSupportedByHarness, type HarnessId } from "../model/pi-models.ts";
+import {
+ defaultModelForHarness,
+ isHarnessId,
+ modelSupportedByHarness,
+ resolveModel,
+ type HarnessId,
+} from "../model/pi-models.ts";
import type { ScopeId } from "../types.ts";
import type { Harness, HarnessTurnInput } from "./harness.ts";
import { NonRetryableTurnError } from "../core/turn-error.ts";
@@ -59,6 +65,7 @@ export async function resolveRuntimeChoiceDurable(
scope: ScopeId,
fallback: RuntimeChoice,
requested?: Partial<RuntimeChoice>,
+ hydrateModelCatalog?: () => Promise<unknown>,
): Promise<RuntimeChoice> {
const approved = (await config.getApprovedHarnessesDurable()) ?? [fallback.harnessId];
const [orgStored, scopedStored, orgLegacy, scopedLegacy] = await Promise.all([
@@ -67,6 +74,10 @@ export async function resolveRuntimeChoiceDurable(
config.getBaseModelOwnDurable(orgScopeId),
scope === orgScopeId ? null : config.getBaseModelOwnDurable(scope),
]);
+ if (hydrateModelCatalog) {
+ const candidates = [requested?.modelId, scopedStored?.modelId, orgStored?.modelId];
+ if (candidates.some((modelId) => modelId && !resolveModel(modelId))) await hydrateModelCatalog();
+ }
const view: Pick<ScopedConfigStore, "getApprovedHarnesses" | "getRuntimeSelection" | "getBaseModel"> = {
getApprovedHarnesses: () => approved,
getRuntimeSelection: (id: ScopeId) => {
diff --git a/src/wiring.ts b/src/wiring.ts
index fb4c2764d..f37513cea 100644
--- a/src/wiring.ts
+++ b/src/wiring.ts
@@ -182,6 +182,7 @@ import { createCodexHarness, codexHarnessConfigOptions } from "./harness/codex-h
import { createClaudeHarness, claudeHarnessConfigOptions } from "./harness/claude-harness.ts";
import { createPiHarness, piHarnessConfigOptions } from "./harness/pi-harness.ts";
import { createHarnessRouter, resolveRuntimeChoiceDurable } from "./harness/harness-router.ts";
+import { selectableModelCatalog } from "./model/model-catalog.ts";
import type { Harness } from "./harness/harness.ts";
import { createSecurityScreenProxy, type SecurityScreener } from "./security/security-screener.ts";
import { createMemoryTaskStore } from "./tasks/memory-task-store.ts";
@@ -822,11 +823,22 @@ export function buildApp(
},
};
const judgeModelId = (): string => config.judgeModelId ?? auxiliaryModelFor(orgBaseModelId() ?? fallback.modelId);
+ const hydrateModelCatalog = async (): Promise<unknown> => {
+ if (!(await modelCredentials.availability()).openrouter) return undefined;
+ return selectableModelCatalog(overrides.modelCredentialFetch);
+ };
const harness = createHarnessRouter(adapters, adapters.get(fallbackHarness)!, (input) =>
- resolveRuntimeChoiceDurable(configStore, runtimeOrgScope, input.scopeLabel, fallback, {
- ...(input.harness ? { harnessId: input.harness as HarnessId } : {}),
- ...(input.model ? { modelId: input.model } : {}),
- }),
+ resolveRuntimeChoiceDurable(
+ configStore,
+ runtimeOrgScope,
+ input.scopeLabel,
+ fallback,
+ {
+ ...(input.harness ? { harnessId: input.harness as HarnessId } : {}),
+ ...(input.model ? { modelId: input.model } : {}),
+ },
+ hydrateModelCatalog,
+ ),
);
const leaseTtlMs = config.leaseTtlMs;
diff --git a/test/runtime-selection.test.ts b/test/runtime-selection.test.ts
index 81d92c91a..151bd003a 100644
--- a/test/runtime-selection.test.ts
+++ b/test/runtime-selection.test.ts
@@ -6,6 +6,7 @@ import {
type PersistedBaseModel,
} from "../src/resolution/config-store.ts";
import { resolveRuntimeChoice, resolveRuntimeChoiceDurable } from "../src/harness/harness-router.ts";
+import { registerOpenRouterCatalogModel } from "../src/model/pi-models.ts";
import { createMemoryMap } from "../src/persistence/durable-map.ts";
const ORG = "org:default-org" as const;
@@ -108,3 +109,48 @@ test("a listener that throws cannot break the write that notified it", async ()
await config.setRuntimeSelectionLatest(ORG, { harnessId: "pi", modelId: "claude-opus-4-8" });
assert.equal((await config.getRuntimeSelectionDurable(ORG))?.modelId, "claude-opus-4-8");
});
+
+test("durable runtime resolution hydrates the model catalog before rejecting an unknown dynamic model", async () => {
+ const config = createMemoryConfigStore("default-org");
+ config.setApprovedHarnesses(["pi"]);
+ await config.setRuntimeSelectionLatest(PERSONAL, { harnessId: "pi", modelId: "testvendor/cold-router-model" });
+ await config.flushScope(PERSONAL);
+ const fallback = { harnessId: "pi" as const, modelId: "claude-opus-4-8" };
+
+ assert.deepEqual(await resolveRuntimeChoiceDurable(config, ORG, PERSONAL, fallback), fallback);
+
+ let hydrations = 0;
+ const hydrate = async () => {
+ hydrations += 1;
+ registerOpenRouterCatalogModel({
+ id: "testvendor/cold-router-model",
+ name: "Cold Router Model",
+ contextWindow: 1_048_576,
+ maxTokens: 131_072,
+ input: ["text"],
+ reasoning: true,
+ cost: { input: 0, output: 0 },
+ });
+ };
+ assert.deepEqual(await resolveRuntimeChoiceDurable(config, ORG, PERSONAL, fallback, undefined, hydrate), {
+ harnessId: "pi",
+ modelId: "testvendor/cold-router-model",
+ });
+ assert.equal(hydrations, 1);
+
+ assert.deepEqual(
+ await resolveRuntimeChoiceDurable(
+ config,
+ ORG,
+ PERSONAL,
+ fallback,
+ { modelId: "testvendor/cold-router-model" },
+ hydrate,
+ ),
+ { harnessId: "pi", modelId: "testvendor/cold-router-model" },
+ );
+
+ const before = hydrations;
+ await resolveRuntimeChoiceDurable(config, ORG, PERSONAL, fallback, undefined, hydrate);
+ assert.equal(hydrations, before);
+});