Skip to content

feat(opencode): runtime subagent model selection#1

Merged
CreatorGhost merged 2 commits into
devfrom
subagent-model-selection
Jul 11, 2026
Merged

feat(opencode): runtime subagent model selection#1
CreatorGhost merged 2 commits into
devfrom
subagent-model-selection

Conversation

@CreatorGhost

@CreatorGhost CreatorGhost commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Summary

Implements specs/subagent-model-selection.md: a parent agent can now choose the model for each subagent invocation at runtime instead of requiring one statically configured agent per model.

  • Task tool gains optional model and variant fields. model accepts a canonical provider/model reference or a natural model name ("Fable five", "GPT 5.6 Sol Pro").
  • New Provider.resolveModel resolves natural names via normalized token matching (number words normalize to digits, version tokens must match in order) and only selects when exactly one usable route matches. Duplicate routes (e.g. an OpenAI subscription and AWS Bedrock exposing the same model) fail with AmbiguousModelSelectorError listing the canonical choices instead of silently picking one.
  • Omitted model preserves the existing default chain for new children: agent-configured model, then the parent turn's exact provider/model. Resumed children now keep their own stored model instead of drifting to the parent's current model; an explicit model on resume switches it.
  • variant is validated against the resolved model (case-insensitive). Explicit invalid variants fail with the available options; inherited variants from agent config or the parent turn silently drop, matching the legacy prompt path.
  • Child sessions persist their resolved model; Task permission and result metadata expose the canonical route plus safe auth provenance (account/env/custom, never credentials).
  • TUI Task rows display the route: General Task [direct/claude-fable-5 · high · account] — description.

Behavior notes

  • Permission ask now happens after agent/model validation rather than before.
  • Both new fields are optional; existing Task calls are unaffected for new children.

Testing

  • packages/opencode: bun test test/tool/task.test.ts (25 pass, incl. ambiguity, transposed-version rejection, disabled-provider filtering, resume preservation, explicit switch, parallel mixed-model children, strict vs lenient variant handling) and bun test test/provider/provider.test.ts (96 pass)
  • packages/tui: bun test test/cli/tui/inline-tool-wrap-snapshot.test.tsx (17 pass)
  • bun turbo typecheck across all 30 packages passes (pre-push hook)

Summary by CodeRabbit

  • New Features

    • Select a specific model and reasoning variant when running subagents.
    • Use provider-qualified model names or natural-language model selectors.
    • Subagent sessions now retain their selected model, variant, and authentication route.
    • Parallel and resumed subagent tasks preserve independent model selections.
  • UI

    • Subagent titles now display the selected provider, model, variant, and authentication route when available.
  • Bug Fixes

    • Ambiguous or unavailable model selections now provide clear errors and suggestions.
  • Documentation

    • Added guidance for model selection, variants, and resolving ambiguous model names.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@CreatorGhost, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7a6cde1b-0f1a-49c9-afe7-377284a63639

📥 Commits

Reviewing files that changed from the base of the PR and between 211535b and f6e75bb.

📒 Files selected for processing (1)
  • packages/tui/test/cli/tui/inline-tool-wrap-snapshot.test.tsx
📝 Walkthrough

Walkthrough

Adds runtime subagent model selection with provider selector resolution, variant handling, child-session persistence, route metadata, UI display, and tests for ambiguity, resumption, disabled routes, and concurrent selections.

Changes

Subagent model selection

Layer / File(s) Summary
Provider selector resolution
packages/opencode/src/provider/provider.ts
Adds selector-specific errors, resolveModel, normalized alias matching, suggestions, and service wiring.
Task model and variant routing
packages/opencode/src/tool/task.ts
Adds optional model and variant inputs, resolves effective routing and authentication provenance, persists child-session state, and passes the selected route to prompts.
Runtime wiring and model-selection validation
packages/opencode/src/tool/registry.ts, packages/opencode/test/...
Wires authentication dependencies and validates model resolution, variants, resumed children, disabled routes, and concurrent executions.
Route metadata presentation and specification
packages/tui/src/routes/session/index.tsx, packages/tui/test/..., packages/opencode/src/tool/task.txt, specs/subagent-model-selection.md
Documents selection semantics and displays provider/model, variant, and authentication provenance in subagent titles.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TaskTool
  participant Provider
  participant Auth
  participant Sessions
  participant PromptOps
  TaskTool->>Provider: resolve requested model
  TaskTool->>Auth: load provider authentication
  TaskTool->>Sessions: persist child model and variant
  TaskTool->>PromptOps: execute with effective route
  PromptOps-->>Sessions: store route metadata
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description has useful details, but it misses required template sections like Issue, Type of change, screenshots, and the checklist. Add the missing template sections: issue reference, change type, screenshots if applicable, and checklist items, or note why each is not applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: runtime subagent model selection.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch subagent-model-selection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/tui/test/cli/tui/inline-tool-wrap-snapshot.test.tsx (1)

288-290: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test verifies the full-parameter case correctly.

The assertion matches the formatSubagentTitle output. Consider adding a case with only model (no variant/authVia) to verify the filter(Boolean) path produces [openai/gpt-5.6-sol] rather than [openai/gpt-5.6-sol · · ] — low risk given the simple join logic, but it would lock in the partial-metadata contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/tui/test/cli/tui/inline-tool-wrap-snapshot.test.tsx` around lines
288 - 290, Add a test case for formatSubagentTitle that provides only the model
while omitting variant and authVia, and assert the title metadata is formatted
as [openai/gpt-5.6-sol] without empty separators. Keep the existing
full-parameter assertion unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/tui/test/cli/tui/inline-tool-wrap-snapshot.test.tsx`:
- Around line 288-290: Add a test case for formatSubagentTitle that provides
only the model while omitting variant and authVia, and assert the title metadata
is formatted as [openai/gpt-5.6-sol] without empty separators. Keep the existing
full-parameter assertion unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 78b794ed-68fb-44dc-ab7b-4a92607f0aa9

📥 Commits

Reviewing files that changed from the base of the PR and between 9976269 and 211535b.

📒 Files selected for processing (9)
  • packages/opencode/src/provider/provider.ts
  • packages/opencode/src/tool/registry.ts
  • packages/opencode/src/tool/task.ts
  • packages/opencode/src/tool/task.txt
  • packages/opencode/test/fake/provider.ts
  • packages/opencode/test/tool/task.test.ts
  • packages/tui/src/routes/session/index.tsx
  • packages/tui/test/cli/tui/inline-tool-wrap-snapshot.test.tsx
  • specs/subagent-model-selection.md

@CreatorGhost CreatorGhost merged commit bfdb607 into dev Jul 11, 2026
1 check passed
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.

1 participant