opencode
opencode copied to clipboard
fix(task): update model initialization to use runtime session data
Problem
When a user switches models at runtime using /model, subtasks spawned via the Task tool ignored the runtime selection and used the agent's configured model from config instead. Fixes #6928
For example:
- User switches to a cheaper model (e.g., GLM 4.7)
- User runs a command that spawns a subtask
- Subtask uses the expensive model from agent config (e.g.,
github-copilot/claude-sonnet-4.5)
This caused unexpected usage of premium API requests.
Root Cause
In task.ts, the model priority was:
const model = agent.model ?? { modelID: msg.info.modelID, ... }
Agent config model took priority over the parent session's runtime selection.
Fix
Always use the parent session's model (stored in msg.info.modelID), which reflects the user's runtime selection:
const model = { modelID: msg.info.modelID, providerID: msg.info.providerID }
The model is then passed explicitly to SessionPrompt.prompt(), ensuring the subtask respects the user's choice.