Skip to content

fix(opencode): sanitize history and gate options on target model switch#16630

Draft
tobwen wants to merge 1 commit intoanomalyco:devfrom
tobwen:fix/target-model-capabilities
Draft

fix(opencode): sanitize history and gate options on target model switch#16630
tobwen wants to merge 1 commit intoanomalyco:devfrom
tobwen:fix/target-model-capabilities

Conversation

@tobwen
Copy link
Contributor

@tobwen tobwen commented Mar 8, 2026

Issue for this PR

Fixes #16154

Also covers the same bug class as closed issue #11571 and overlaps with #11572 and #14783.

Type of change

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

What does this PR do?

When a session switches to a different target model, it now sanitizes history and request options against that target model's capabilities.

  • Strips incompatible reasoning/tool history for targets that do not support those features
  • Preserves field-based reasoning metadata for interleaved targets
  • Filters unsupported reasoning/thinking options
  • Gates tool resolution plus toolChoice on target model toolcall

Added regression tests for GPT reasoning history -> non-reasoning OpenAI-compatible Mistral.

How did you verify your code works?

Ran from packages/opencode:

  • bun test test/provider/transform.test.ts test/session/llm.test.ts
  • bunx tsc --noEmit

Screenshots / recordings

Not a UI change.

Checklist

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

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

Based on my search, I found one potentially related PR that overlaps with the current PR:

Related PR:

This PR (16630) explicitly mentions in its description that it "overlaps with #11572" as part of covering the same bug class. The current PR appears to be a more comprehensive fix that also addresses issues #16154, #11571, and #14783 in a unified way, likely superseding or extending the earlier approach in PR #11572.

When a session switches to a different target model, it now sanitizes history and request options against that target model's capabilities.

- Strips incompatible reasoning/tool history for targets that do not support those features
- Preserves field-based reasoning metadata for interleaved targets
- Filters unsupported reasoning/thinking options
- Gates tool resolution plus toolChoice on target model toolcall

Added regression tests for GPT reasoning history -> non-reasoning OpenAI-compatible Mistral.
@tobwen tobwen force-pushed the fix/target-model-capabilities branch from 64e8056 to d25510b Compare March 9, 2026 18:20
@tobwen tobwen marked this pull request as draft March 9, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: gpt-5 defaults + @ai-sdk/openai-compatible path sends incompatible reasoning params

1 participant