[PR #6937] fix(task): update model initialization to use runtime session data #12166

Closed
opened 2026-02-16 18:17:05 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6937

State: closed
Merged: No


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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6937 **State:** closed **Merged:** No --- ## 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: ```typescript 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: ```typescript 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.
yindo added the pull-request label 2026-02-16 18:17:05 -05:00
yindo closed this issue 2026-02-16 18:17:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12166