[PR #11197] fix(compaction): sanitize tool messages for Copilot provider in compaction #13691

Open
opened 2026-02-16 18:18:31 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11197

State: open
Merged: No


Fixes https://github.com/anomalyco/opencode/issues/11157

What does this PR do?

Copilot provider does not support tool-related message types in the compaction context. This change adds sanitization logic that:

  • Detects when the model provider is Copilot
  • Filters out tool result messages (role: "tool")
  • Filters out assistant messages with tool_calls
  • Removes tool-call and tool-result parts from message content
  • Ensures assistant messages have valid content after filtering

This prevents errors when compacting conversations that contain tool interactions for Copilot users.

How did you verify your code works?

  1. opencode auth login > log in to Github Copilot Enterprise
  2. Set model to Claude Sonnet 4.5 by Github Copilot
  3. Install oh-my-opencode to call tools
  4. Use opencode to fill context
  5. run /compact
  6. Compaction should be successful without "Bad Request"
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11197 **State:** open **Merged:** No --- Fixes https://github.com/anomalyco/opencode/issues/11157 ### What does this PR do? Copilot provider does not support tool-related message types in the compaction context. This change adds sanitization logic that: - Detects when the model provider is Copilot - Filters out tool result messages (role: "tool") - Filters out assistant messages with tool_calls - Removes tool-call and tool-result parts from message content - Ensures assistant messages have valid content after filtering This prevents errors when compacting conversations that contain tool interactions for Copilot users. ### How did you verify your code works? 1. opencode auth login > log in to Github Copilot Enterprise 2. Set model to Claude Sonnet 4.5 by Github Copilot 3. Install oh-my-opencode to call tools 4. Use opencode to fill context 5. run `/compact` 6. Compaction should be successful without "Bad Request"
yindo added the pull-request label 2026-02-16 18:18:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13691