← Back to PRs

#13376: fix: pass model directly to agent for sub-agent runs

by jrbobbyhansen-pixel open 2026-02-10 12:36 View on GitHub →
app: macos app: web-ui gateway scripts commands agents stale
## Problem The `sessions_spawn` tool was setting the model via `sessions.patch` but the model override wasn't reliably persisting to the session store before the agent run started. This caused sub-agents to fall back to the default model instead of using the configured subagent model. **Evidence from investigation:** - `sessions_spawn` returns `modelApplied: true` - But the session store shows `modelOverride: null` - Sub-agents run on default model (Opus) instead of configured model ## Solution Pass the resolved model directly through the agent call chain, bypassing the session store timing issue: 1. **sessions-spawn-tool.ts**: Add `model` param to gateway agent call 2. **schema/agent.ts**: Add `model` to `AgentParamsSchema` 3. **server-methods/agent.ts**: Accept and forward `model` to `agentCommand` 4. **commands/agent.ts**: Use `opts.model` override (takes precedence over session store) 5. **commands/agent/types.ts**: Add `model` to `AgentCommandOpts` ## Changes - 5 files changed, 28 insertions - No breaking changes - the model is optional and existing behavior is preserved Fixes #13372 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR threads an optional `model` override through the gateway `agent` request path so sub-agent runs can use the intended model without relying on the session store write timing (`sessions.patch`). Concretely: `sessions_spawn` now passes `model` in the `agent` call, the gateway protocol schema accepts it, the gateway handler forwards it into `agentCommand`, and `agentCommand` prefers this per-call override over the session-stored override. The main issue is in `src/commands/agent.ts`: the new parsing logic for `opts.model` uses `split("/", 2)`, which truncates hierarchical model IDs (explicitly used in this repo for OpenRouter, e.g. `openrouter/moonshotai/kimi-k2`). That will select the wrong model key and can break allowlist enforcement or cause unexpected default-model fallback. <h3>Confidence Score: 3/5</h3> - This PR is not safe to merge as-is due to incorrect parsing of hierarchical model IDs in the new direct model override path. - While the overall wiring is small and coherent, the direct model override parsing in agentCommand will definitely truncate OpenRouter-style hierarchical model refs (which the repo already uses/tests for). That would cause incorrect model selection and may break allowlist behavior for sub-agent runs. - src/commands/agent.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs