Skip to content

fix(opencode): preserve subagent model variants#29066

Open
sdip15fa wants to merge 1 commit into
anomalyco:devfrom
sdip15fa:fix/subagent-variant-preservation
Open

fix(opencode): preserve subagent model variants#29066
sdip15fa wants to merge 1 commit into
anomalyco:devfrom
sdip15fa:fix/subagent-variant-preservation

Conversation

@sdip15fa
Copy link
Copy Markdown

@sdip15fa sdip15fa commented May 24, 2026

Issue for this PR

Closes #29067

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Preserves the selected model variant/thinking level when a same-model subagent is created without its own configured variant.

The fix passes the parent assistant variant into the child prompt only when the child uses the same provider/model and has no configured variant. It also lets inherited-model agents apply their configured variant when the provider supports it, and prevents explicit different subtask models from copying the parent variant.

How did you verify your code works?

  • CI=true bun test test/tool/task.test.ts
  • CI=true bun test test/session/prompt.test.ts
  • CI=true bun typecheck
  • pre-push: bun turbo typecheck

Screenshots / recordings

Not applicable; backend prompt/session state fix for a TUI-observed bug.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings May 24, 2026 05:06
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found several related PRs that address similar concerns about model variants and subagent inheritance:

Potential Related PRs

  1. PR feat(task): pass variant to subagent so it inherits parent's thinking level #12567 - feat(task): pass variant to subagent so it inherits parent's thinking level

    • Directly related: addresses passing model variants from parent agents to subagents
  2. PR fix(opencode): apply agent variant when no explicit model is configured #24962 - fix(opencode): apply agent variant when no explicit model is configured

    • Related: handles agent variant application in similar scenarios
  3. PR feat: add agent default variant handling in TUI and desktop #7156 - feat: add agent default variant handling in TUI and desktop

    • Related: covers agent variant handling broadly
  4. PR feat(agent): implement model tier selection with variant support for subagents #11377 - feat(agent): implement model tier selection with variant support for subagents

    • Related: implements variant support for subagents

These PRs appear to address the same or overlapping concerns about preserving and inheriting model variants for subagents. PR #12567 seems most directly related as it also deals with passing variants from parent to subagent prompts.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds and verifies variant inheritance behavior across parent/child agent prompts, ensuring variants are only propagated when the child uses the same model (and no explicit child variant/model is configured).

Changes:

  • Extend test seeding to support setting an assistant variant/model and add new TaskTool variant inheritance tests.
  • Update TaskTool to inherit the parent assistant variant for same-model subagents when the subagent has no configured variant.
  • Update SessionPrompt variant application logic and add tests for agent-variant application and variant non-propagation on explicit model overrides.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/opencode/test/tool/task.test.ts Adds seed options and new TaskTool tests covering variant inheritance and persistence.
packages/opencode/test/session/prompt.test.ts Adds SessionPrompt tests for applying agent variant to inherited models and avoiding variant propagation across explicit model changes.
packages/opencode/src/tool/task.ts Implements parent-variant inheritance for same-model subagent execution when no child variant is configured.
packages/opencode/src/session/prompt.ts Restricts variant propagation to same-model scenarios and broadens when agent variant can apply to inherited/default models.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)
const model = input.model ?? ag.model ?? (yield* currentModel(input.sessionID))
const same = ag.model && model.providerID === ag.model.providerID && model.modelID === ag.model.modelID
const same = !ag.model || (model.providerID === ag.model.providerID && model.modelID === ag.model.modelID)
Comment on lines +57 to +60
const seed = Effect.fn("TaskToolTest.seed")(function* (
title = "Pinned",
opts?: { assistantVariant?: string; assistantModel?: typeof ref },
) {
@github-actions github-actions Bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI drops model variant after entering subagent

2 participants