opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix(task): update model initialization to use runtime session data

Open Ipriyankrajai opened this issue 1 week ago • 2 comments

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:

  1. User switches to a cheaper model (e.g., GLM 4.7)
  2. User runs a command that spawns a subtask
  3. 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.

Ipriyankrajai avatar Jan 05 '26 11:01 Ipriyankrajai