Hydrate the OpenRouter catalog on cold runtime resolution - #678
Merged
Conversation
An approved dynamic OpenRouter model (e.g. stealth/ox-alpha) only exists in a process after the catalog has been fetched. #656 pre-warmed the catalog on the API turn entrypoint, but the harness router's own resolution path (wiring.ts) had no such warm-up, so a run landing on a cold worker rejected the selection with "runtime pi/<model> is not approved". resolveRuntimeChoiceDurable now accepts an optional catalog hydrator and invokes it before resolving whenever any candidate model is unknown to the local registry; wiring passes one that fetches the OpenRouter catalog when an OpenRouter key is available. A warm registry never triggers a fetch. Co-Authored-By: QM <qm@ycombinator.com>
Co-Authored-By: QM <qm@ycombinator.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Selecting a dynamic OpenRouter catalog model (e.g.
stealth/ox-alpha) intermittently fails a turn with:The selection is approved and present in the catalog; the failure is timing-dependent.
Cause
Dynamic OpenRouter models are registered into the process-local model registry only after
selectableModelCatalog()fetches the catalog. #656 added a pre-warm on the API turn entrypoint (app-turn.ts), but the harness router's resolution path inwiring.tsresolves the runtime again at run execution time with no warm-up. On a cold process (fresh worker start, or one that never served the picker),resolveModel()returns undefined,modelSupportedByHarness()fails, andharness-router.tsthrows — so the same selection works when the process is warm and fails when it isn't, which is why it looked fixed and regressed.Fix
resolveRuntimeChoiceDurableaccepts an optionalhydrateModelCatalogcallback and awaits it before resolving whenever any candidate model (requested, scope, or org selection) is unknown to the local registry.wiring.tspasses a hydrator that fetches the OpenRouter catalog when an OpenRouter key is available, so the harness router path self-heals on cold processes.Testing
test/runtime-selection.test.ts: cold resolution without a hydrator falls back; with a hydrator it resolves the dynamic model (both via stored selection and explicit request); warm registry skips hydrationtest/runtime-selection.test.ts+test/dynamic-openrouter-model.test.ts: 8/8 passtsc --noEmit, oxlint, prettier clean on touched filesNeed help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.