#10608: fix(agents): honor spawn model override in gateway and session spawn tool
app: web-ui
gateway
commands
agents
stale
Cluster:
Model Management Enhancements
## Summary
- Accept optional model override on the gateway agent method and apply it to the session before running.
- Forward sessions_spawn resolved model into the agent call when the patch succeeds.
## Root Cause
sessions_spawn only patched the session model; the agent call did not carry the model, so new subagent runs could proceed with defaults if the session entry wasn't read as expected at run start.
## Changes
- Added optional `model` to gateway agent params schema (`src/gateway/protocol/schema/agent.ts`)
- Applied/validated model overrides in `src/gateway/server-methods/agent.ts` before persisting session entry
- Forwarded resolved model to agent call when `sessions.patch` succeeds in `src/agents/tools/sessions-spawn-tool.ts`
- Added `sessionEntry` passthrough to `AgentCommandOpts` and `resolveSession` so the gateway can inject the pre-resolved entry
- Added test for model override threading in `agent.test.ts`
## Testing
- `pnpm tsgo`: ✓ clean compilation
- `vitest run src/gateway/server-methods/agent.test.ts`: ✓ 4/4 tests pass (includes new model override test)
Supersedes #9365 (which had unresolved merge conflict markers).
Closes #5369
Closes #9771
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
- Adds an optional `model` parameter to the gateway `agent` method and applies it by updating the resolved session entry before dispatch.
- Threads the resolved `sessionEntry` into `agentCommand`/`resolveSession` so model overrides take effect immediately.
- Updates `sessions_spawn` to forward the resolved model into the gateway `agent` call when the session patch succeeds.
- Extends gateway tests to cover model override threading into `agentCommand`.
<h3>Confidence Score: 5/5</h3>
- This PR appears safe to merge with minimal risk.
- Changes are scoped to threading a model override through existing session resolution paths, with explicit validation against the gateway model catalog and a new unit test covering the new behavior; no behavioral regressions were identified in the modified call paths.
- src/gateway/server-methods/agent.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#13376: fix: pass model directly to agent for sub-agent runs
by jrbobbyhansen-pixel · 2026-02-10
90.0%
#19328: Fix: preserve modelOverride in agent handler (#5369)
by CodeReclaimers · 2026-02-17
84.6%
#20712: fix(subagents): prioritize agent runtime default model over global ...
by sourcesavant · 2026-02-19
84.2%
#21556: fix(agents): graceful fallback when spawned model is not in allowlist
by irchelper · 2026-02-20
83.9%
#6603: fix: use allowAny flag instead of size check for model override val...
by gavinbmoore · 2026-02-01
82.8%
#11107: fix(models): auto-allow selected model on sessions.patch
by Mokoby · 2026-02-07
82.1%
#9583: fix(models): allow models in agents.defaults.models even if not in ...
by hotzen100 · 2026-02-05
81.6%
#17021: fix(agents): read models from gateway config first
by Limitless2023 · 2026-02-15
79.7%
#21088: fix: sessions_sspawn model override ignored for sub-agents
by Slats24 · 2026-02-19
79.7%
#11562: Fix #10883: Enforce subagent model configuration
by divol89 · 2026-02-08
79.6%