Skip to content

fix(task): preserve command-selected models for command-triggered subtasks#26117

Open
gmnstr wants to merge 1 commit intoanomalyco:devfrom
gmnstr:fix/subagent-model-routing
Open

fix(task): preserve command-selected models for command-triggered subtasks#26117
gmnstr wants to merge 1 commit intoanomalyco:devfrom
gmnstr:fix/subagent-model-routing

Conversation

@gmnstr
Copy link
Copy Markdown

@gmnstr gmnstr commented May 7, 2026

Issue for this PR

Closes #18615
Related to #17870

Type of change

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

What does this PR do?

This fixes the command/subtask delegation path so a command-selected model is preserved when the task tool spawns a child subagent session.

The bug was that a command-triggered subtask could lose its already-resolved model and fall back to the target subagent model or the parent model instead.

This change keeps the fix narrowly scoped:

  • it only forwards the internal delegated model for command-triggered subtasks
  • ordinary/manual subtasks keep the existing fallback behavior
  • child sessions are not pre-seeded with agent/model, so switch-event and history behavior stay aligned with existing prompt-time resolution

Why this works:

  • command-triggered subtasks now carry the resolved model through the subtask path into the child prompt call
  • when no delegated model is present, the task tool still falls back through subagent configured model and then parent assistant model
  • regression tests cover the command path, fallback behavior, stale state bleed, and session metadata not becoming authoritative

How did you verify your code works?

From packages/opencode:

  • bun test --timeout 30000 test/tool/task.test.ts
  • bun test --timeout 30000 test/session/prompt.test.ts

Also ran:

  • git diff --check

Screenshots / recordings

N/A — no UI changes.

Checklist

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

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 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

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

Potential Duplicate Found

PR #18752: "fix: preserve explicit model selection in command subtasks"
#18752

This appears to be addressing the exact same issue as the current PR #26117. Both PRs aim to preserve command-selected models for command-triggered subtasks and prevent them from losing their model selection when spawning child subagent sessions.

Why they're related:

  • Same core problem: command-triggered subtasks losing their explicit model selection
  • Same solution domain: preserving model routing for command-triggered subtasks vs ordinary subtasks
  • Both involve task tool spawning behavior and model precedence/fallback logic

@gmnstr
Copy link
Copy Markdown
Author

gmnstr commented May 7, 2026

While reviewing upstream history after opening this, I found that #18752 is already open and overlaps heavily with this PR. Both changes preserve command/subtask model selection through the delegation path and touch the same routing/test files.\n\nThe reason I’m leaving this open for now is that this version tries to keep the fix narrowly scoped to command-triggered subtasks and preserve existing behavior for ordinary/manual subtasks:\n- only forwards the internal delegated model for command-triggered subtasks\n- keeps ordinary/manual task-tool fallback behavior unchanged\n- avoids pre-seeding child session agent/model so switch/history behavior stays aligned with existing prompt-time resolution\n- includes regression coverage for fallback behavior and non-authoritative session metadata\n\nIf maintainers would prefer to converge on #18752 instead of reviewing two overlapping fixes, I’m happy to close this and upstream any useful guardrails/tests there.

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

github-actions Bot commented May 7, 2026

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.

[Bug] Model parameter ignored when launching subagent with agent name

1 participant