Repository navigation
fix(runtime): unify background model_invoke model selection and loading - #644
Conversation
There was a problem hiding this comment.
Approve with nits (1 P2)
Scope: base main, merge base a3b6f44b, 1 commit, 37 files reviewed at f1786d41. Helper skills loaded: coderbook (sections 2, 3, 5). ponytail-review and karpathy-guidelines were not loaded; I applied their checklists from the review instructions. Ran in a separate session.
Findings
P2
apps/node-services/src/runtime-model-call.ts:434-445: a second hard-coded list of legacy default model IDs, and a test double that hides it.
The real catalog already handles legacy defaults.runtimeModelCatalogForComputer(apps/node-services/src/agent/runner-gateway/local-computer-management.ts:590-602) setsruntimeModel: model.idon every discovered model except the legacy defaults it reads fromDEFAULT_LOCAL_RUNTIME_MODELS.run.startrelies on only that field (agent-runner-lifecycle.ts:465). Through the real gateway,wireModelFortherefore always takes themodel.runtimeModelbranch or returnsundefined. TheLEGACY_DEFAULT_MODEL_IDSset and thereturn model.idfallback only run for test catalogs that leave outruntimeModel, andtests/runtime-model-call.test.tsis one of them: the new test passes"gpt-large"only through that fallback. The result is a second copy of the legacy-ID rule (it also listsantigravity-default) that can drift from the catalog's, and a test that doesn't exercise the field production uses.
Fix: reducewireModelFortomodel?.runtimeModel, deleteLEGACY_DEFAULT_MODEL_IDS, and setruntimeModelin the test catalog fixtures the wayruntimeModelCatalogForComputerdoes. The Daemon's own"codex-default"/"claude-default"filters incodexInvokeModel/claudeInvokeModel(provider/model_invoke.go:531,751) guard against input that Node never sends for the same reason, so they can go too.
Verified as fine
- Rollout gating.
modelgoes on the wire only whensupportsModelInvokeModelconfirms Computer >= 0.62.0 on the same connection epoch (runner-model-invocation.ts:267-271,runner-connections.ts:874-884).@linger/computeris bumped to0.62.0, andmainhas no other 0.62.0 claim. Older Daemons keep their strict decoding without seeing the field. The new public test covers both 0.61.0 and 0.62.0. - TeamHub.
runtime_modelisNOT NULLwith length 1..120 (migrations/00852_baseline.sql:2229,2263), so a placement always carries one. The contract field is optional, and older Node Services ignore it. - No model ID crosses Runtimes.
resolveTargetuses the configured model only whenruntimeType === placement.runtimeType(runtime-model-call.ts:833-842). The chain rebuilds its placement with the target Runtime's model (:1441-1453). The breaker fingerprint includes the wire model (:947). - Pi loading.
ensureLocalModelreturns at once for an empty model or a model outside the library (daemon/local_models.go:66-69,localmodels/library.go:1003-1016). Explicit Pi calls now load on demand, the same asrun.start, and a legacy call that names no model still gets themodelInvokeUnreadyrefusal (daemon/model_invoke.go:119). Covered byTestModelInvokeLoadsNamedPiLocalModelOnDemand. - Codex, Claude, Pi argv. An explicit model wins over
config.tomlincodex execand inCodexSessions(provider/model_invoke.go:377,497). Claude passes--modeland Pi passes--modelunless it ispi-default. Reasoning-effort normalization and endpoint reachability now use the requested model (daemon/model_invoke.go:264-273,provider/model_endpoints.go:34). - Generated contracts. The generated Go and TS outputs match the edits to
envelope.schema.jsonandagent-runtime-state.yaml, and the docs are updated inapps/computer/AGENTS.md,local-daemon/README.mdandsrc/agent/AGENTS.md. - Repository rules. No CJK in added lines or in the commit message, and no merge commits.
- Unverified. I did not check how a reused
CodexSessionssession behaves if a later call names a different model. One chain keeps one model, so this probably can't happen.
Process notes
- The branch is 2 commits behind
main(df3fc360,4657e442). It needs a rebase before it can merge.
CI
8 checks pass. 7 are still running: check (computer-go), check (desktop), check (packages), check (teamhub), web tests (1/2), web tests (2/2) and web-static. I ran no tests locally.
Automated review by Claude Code
Automated review of f1786d4 by Claude Code.
Background model_invoke calls (Wiki, Memory, Agent Memory, Daily Brief, Approval, Profile, Insight, and Voice Ask) previously omitted the model on the Runner Gateway wire and deferred to each Runtime's local CLI default. That diverged from interactive and Routine runs (run.start), causing Codex background calls to fail with runtime_incompatible when ~/.codex/config.toml named an unsupported model, Claude calls to ignore the Agent's model, and Pi calls to fail when a downloaded local model had not been loaded yet. Unify background model_invoke with the Agent's configured (runtime, model) and local model loading path: - Expose optional runtime_model on TeamHub AnotherMePlacement and pass ghost.runtime.model from Agent Memory coordinator calls. - Add optional model to Runner Gateway ModelInvoke (gated on @linger/computer >= 0.62.0 for strict-decoder backward compatibility) and bump @linger/computer to 0.62.0. - Resolve the wire model in runtime-model-call: use the Agent's configured model on the same Runtime, fall back to the target Runtime catalog default on cross-Runtime fallback or legacy/unconfigured placements, and include the wire model in background circuit-breaker fingerprints. - Forward explicit model in Local Computer Daemon across Codex (-m / CodexSessions --config model=), Claude (--model), and Pi (--model), run ensureLocalModel on Pi model_invoke calls just like run.start, and thread the target model into reasoning-effort normalization and endpoint checks.
f1786d4 to
f60ac78
Compare
There was a problem hiding this comment.
Approve with nits (1 P2)
Scope: base main at merge-base 41a3e2a8; 1 commit, 37 files reviewed. This is a follow-up on f1786d4. The PR was rebased since then, so I compared the old and new patches with git range-diff and also re-checked the full merge-base diff. Helper skills loaded: coderbook. I applied the ponytail-review and karpathy-guidelines checklists as the review skill describes them, without loading those two skills. Ran in a separate session.
Previous findings
- Resolved: legacy default model ID list duplicated in
runtime-model-call.ts.LEGACY_DEFAULT_MODEL_IDSandwireModelForare gone.resolveTargetnow usesconfigured?.runtimeModelanddefaultRuntimeModel(models)?.runtimeModeldirectly (apps/node-services/src/runtime-model-call.ts:820-829,:928-931). The test catalog now setsruntimeModel, and a legacycodex-defaultcase was added (tests/runtime-model-call.test.ts). On the Daemon side, thecodex-defaultandclaude-defaultsentinels were also dropped, because the Agent Service never sends them.
Findings
P2
apps/computer/local-daemon/internal/provider/native/codex_model_session.go:192: the Codex session server keeps a single app-server per Daemon, and that server's identity includesruntime.Model. When a call arrives with a different identity,retireLocked()runs, and its own comment says "a turn still running on it fails" (:211). Before this PR, every background session call on a Computer resolved to the samenamedmodel (config.toml or the catalog default), so the identity never changed. NowsessionInvokepassescodexInvokeModel(request.Model, …)(internal/provider/model_invoke.go:377,:389), so the model varies by caller.- Failure scenario: one Computer hosts the Another Me placements of two tenants (the unique index is per tenant and human,
agent_registrations_one_another_me_per_human), both on Codex with different configured models. Their Memory session calls (memory-agent.ts:385setssessionKey) interleave. Each switch kills the other tenant's in-flight turn and cold-starts a new app-server, which costs retries and breaker strikes. The same happens when a Claude placement falls back to Codex (it gets the catalog default) while a Codex placement on that Computer uses a non-default model. - Fix: keep one server per model identity (for example, a small map keyed by identity, with the same idle timer). At minimum, add a test covering two models alternating on
CodexSessions.
- Failure scenario: one Computer hosts the Another Me placements of two tenants (the unique index is per tenant and human,
Verified as fine
- Wire model resolution matches
run.start:resolveTargetsendsruntimeModelfrom the catalog built byruntimeModelCatalogForComputer. That function setsruntimeModelonly for IDs that are not legacy defaults (agent-runner-lifecycle.ts:465,local-computer-management.ts:602).- On cross-Runtime fallback, the target Runtime's catalog default is sent, never the placement's model ID (
runtime-model-call.ts:928-931).
- Rollout gating:
modelis sent only whensupportsModelInvokeModel(>= 0.62.0, checked against the connection epoch) holds (runner-model-invocation.ts:267-284).@linger/computerwas bumped from 0.61.0 to 0.62.0. A new Daemon receiving nomodelkeeps the old behavior:codexInvokeModelfalls back to config.toml or the catalog default (model_invoke.go:529-537), Claude adds no--model, and Pi falls back to its default model. - Pi:
ensureLocalModeldoes nothing when the model is empty or not in the library (daemon/local_models.go:66-69,localmodels/library.go:1015-1018).- The
modelInvokeUnreadyrefusal still applies when no model is named. That covers the legacypi-defaultentry, which has noruntimeModel. InvokePiModelskips thepi-defaultsentinel (native/pi_model_invoke.go:20).
- TeamHub:
runtime_modelisNOT NULLwith length 1-120 (migrations/00852_baseline.sql:2229,:2263), so thestringscan inanother_me.sql.gois safe. The optional pointer is set only when the value is non-blank (runtime_config.go:162-165). - Breaker fingerprint and effort clamping: the breaker fingerprint now includes the wire model, so a model switch re-admits the call (
runtime-model-call.ts:934). Effort is clamped against the requested model, falling back to the default model (daemon/model_invoke.go:264-273). - Docs:
apps/computer/AGENTS.md, the local-daemon README andnode-services/src/agent/AGENTS.mdare updated. The user message →provider_readypath is untouched. - Repository rules: no CJK in added lines or the commit message, and no merge commits.
Process notes
- None. The branch is on current
main(merge-base equalsorigin/main).
CI
- All checks pass, including computer-go, computer-go-windows, contracts, packages, teamhub and repository-gate.
- CI runs the Daemon Go tests without
-race. This PR adds no new locking, so I ran no local tests. I did not test the session-restart issue above; it comes from reading the code.
Automated review by Claude Code
Automated review of f60ac78 by Claude Code.
|
Heads-up: since this landed, the Pi case in I ran the file on d60d104 (this PR on main) and on its parent 94ada67, both with #646 applied, so that the file's Codex cases pass and only this case differs (on main, their fake Codex reports a version below the Daemon's minimum). The case fails on d60d104 and passes on 94ada67; on 54c7a37 without #646 it fails the same way. CI doesn't run this file. Repro from the repo root: I haven't looked into the cause, or into whether the test or the code should change. |
Summary
Unifies background
runner.model.invokeexecution (Wiki, Memory, Agent Memory, Daily Brief, Approval, Profile, Insight, and Voice Ask) with the interactive/Routine (run.start) model selection and local-model loading path across Codex, Claude, and Pi.Refs WHI-985
Problem
run.startexplicitly passes the Agent's configured(runtime_type, runtime_model)and runsensureLocalModelfor Pi.model_invokeomittedmodelon the Runner Gateway wire and deferred to each Runtime's local CLI default:~/.codex/config.toml, repeatedly failing withruntime_incompatiblewhen the user's globalconfig.tomlnamed a model unsupported by the signed-in account even though interactive chat worked.--modeland ignored the Agent's configured model.ensureLocalModeland failed when a downloaded local model had not yet been loaded.Changes
runtime_modeltoAnotherMePlacement(contracts/openapi/components/agent-runtime-state.yaml,ListAnotherMePlacementsSQL query,agentregistry/runtime_config.go).modelto Runner GatewayModelInvoke(contracts/runner-gateway/envelope.schema.json,asyncapi.yaml) and regenerated Go/TypeScript contracts.ghost.runtime.modelinagent-memory/coordinator.tsand mappedruntime_modelfrom TeamHub placements inruntime-model-call.ts.runtime-model-call.ts: use the Agent's configured model on the same Runtime, and fall back to the target Runtime catalog's default on cross-Runtime fallback or legacy/unconfigured placements (never leaking a model ID across Runtimes).modelon@linger/computer >= 0.62.0(FIRST_MODEL_INVOKE_MODEL_COMPUTER_VERSION) because older Daemons decode envelopes withDisallowUnknownFields().@linger/computer0.62.0)modelto Codex (-mforcodex execand--config model=forCodexSessions), Claude (--model), and Pi (--model).ensureLocalModel(ctx, runtimeType, request.Model)on Pimodel_invokecalls (matchingrun.start), restrictingmodelInvokeUnreadyrefusal to calls that omitmodel.request.Modelinto reasoning-effort normalization and endpoint reachability checks (ModelEndpoints).apps/computer/AGENTS.md,apps/computer/local-daemon/README.md, andapps/node-services/src/agent/AGENTS.md.scripts/runner-gateway-contract.test.ts.Compatibility & Rollout
< 0.62.0) never receivemodelonModelInvokeand keep legacy behavior.>= 0.62.0) talking to older Agent Services accept omittedmodeland fall back to local CLI defaults.AnotherMePlacement.runtime_modelis optional so mixed TeamHub / Node Services versions interoperate cleanly.provider_readycritical path.Verification
pnpm contracts:verify(pass)make check-repository&commitlint&check-docs&check-contracts(pass)make -C apps/teamhub fmt-check && make -C apps/teamhub lint-go BASE=origin/main && go test ./internal/agentregistry ./internal/app ./tests/integration/layout -count=1(pass)make check-node-services(272 test files / 2,833 tests pass, typecheck + lint clean)pnpm --filter @linger/computer typecheck && lint && test,make -C apps/teamhub lint-go-daemon,make check-computer-go(pass)~/.codex/config.tomlset to an unsupported model:runner.model.invokelogged explicitmodel=gpt-5.6-sol, invokedcodex exec ... -m gpt-5.6-sol, and completed (phase=completed).