Skip to content

fix(agent): skip parseModel when model is "inherit", trim whitespace#33202

Open
yjlc-pc wants to merge 1 commit into
anomalyco:devfrom
yjlc-pc:fix/subagent-inherit-model
Open

fix(agent): skip parseModel when model is "inherit", trim whitespace#33202
yjlc-pc wants to merge 1 commit into
anomalyco:devfrom
yjlc-pc:fix/subagent-inherit-model

Conversation

@yjlc-pc

@yjlc-pc yjlc-pc commented Jun 21, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #17890, #31141, #5623, #8896, #23908

Type of change

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

What does this PR do?

Custom .md subagents with model: inherit (the default when no model is specified in frontmatter) crash with ProviderModelNotFoundError. The string "inherit" is passed directly to Provider.parseModel(), which splits on / and produces {providerID: "inherit", modelID: ""}. Since no provider named "inherit" exists, Provider.getModel() throws ProviderModelNotFoundError on every subagent invocation.

Additionally, some YAML frontmatter parsers (e.g. gray-matter) may leave trailing
on model strings, which also causes Provider.parseModel() to fail on otherwise valid model IDs.

Fix:

  1. packages/opencode/src/agent/agent.ts: Skip Provider.parseModel when value.model === "inherit", leaving item.model undefined. The task.ts fallback (next.model ?? { modelID: msg.info.modelID, providerID: msg.info.providerID }) then correctly inherits the parent session model. Also .trim() the model string for trailing whitespace.
  2. packages/opencode/src/provider/provider.ts: Add .trim() in parseModel for defense-in-depth against trailing whitespace.

How did you verify your code works?

  • The agent.ts fix matches the approach in PR fix(agent): honor model:inherit in subagent frontmatter #17888 (same change, confirmed working by the original author)
  • The provider.ts .trim() is a standard defensive programming practice for string inputs
  • Both changes are minimal (2 lines total) and the logic is straightforward: skip parseModel when the value is the literal string "inherit", and strip surrounding whitespace

Screenshots / recordings

N/A - backend logic fix.

Checklist

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

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 21, 2026
@yjlc-pc yjlc-pc force-pushed the fix/subagent-inherit-model branch from f90ebf9 to 93bd1c1 Compare June 21, 2026 04:33
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@yjlc-pc

yjlc-pc commented Jun 21, 2026

Copy link
Copy Markdown
Author

Can you approve the workflows,dear developers?

Signed-off-by: yjlc-pc <yjlc.18979607766@outlook.com>
@yjlc-pc yjlc-pc force-pushed the fix/subagent-inherit-model branch from 93bd1c1 to ceef9a9 Compare June 21, 2026 05:52
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.

model: inherit in agent frontmatter causes ProviderModelNotFoundError; subagents hidden from /agents dialog

1 participant