Compaction fails with 400 Bad Request when using GitHub Copilot Enterprise #7960

Open
opened 2026-02-16 18:08:47 -05:00 by yindo · 7 comments
Owner

Originally created by @unimun on GitHub (Jan 29, 2026).

Originally assigned to: @thdxr on GitHub.

Description

Problem

Compaction (conversation summarization) fails with 400 Bad Request when using GitHub Copilot Enterprise provider with Claude models.

Root Cause

GitHub Copilot API's /chat/completions endpoint rejects messages with role: "tool" during summarization requests.

API Validation

Test Case Request Contains Response Status
Test 1 Simple user message only Success (200) PASS
Test 2 Assistant message with tool_calls Success (200) PASS
Test 3 Tool result message (role: "tool") Bad Request (400) FAIL
Test 4 Both tool_calls + tool result Bad Request (400) FAIL

Solution

Provider-specific filtering in packages/opencode/src/session/compaction.ts:

  • Check model.providerID for "copilot"
  • Only sanitize tool messages for GitHub Copilot
  • Other providers pass messages unchanged

Verification

  • Compaction works for GitHub Copilot
  • Regular chat with tools still works
  • API behavior validated with curl tests
  • Build passes

Plugins

No response

OpenCode version

dev build

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @unimun on GitHub (Jan 29, 2026). Originally assigned to: @thdxr on GitHub. ### Description ## Problem Compaction (conversation summarization) fails with 400 Bad Request when using GitHub Copilot Enterprise provider with Claude models. ## Root Cause GitHub Copilot API's /chat/completions endpoint rejects messages with `role: "tool"` during summarization requests. ## API Validation | Test Case | Request Contains | Response | Status | | ---------- | ------------------------------------ | ----------------- | ------- | | **Test 1** | Simple user message only | Success (200) | ✅ PASS | | **Test 2** | Assistant message with `tool_calls` | Success (200) | ✅ PASS | | **Test 3** | Tool result message (`role: "tool"`) | Bad Request (400) | ❌ FAIL | | **Test 4** | Both `tool_calls` + tool result | Bad Request (400) | ❌ FAIL | ## Solution Provider-specific filtering in `packages/opencode/src/session/compaction.ts`: - Check `model.providerID` for "copilot" - Only sanitize tool messages for GitHub Copilot - Other providers pass messages unchanged ## Verification - [x] Compaction works for GitHub Copilot - [x] Regular chat with tools still works - [x] API behavior validated with curl tests - [x] Build passes ### Plugins _No response_ ### OpenCode version dev build ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 18:08:47 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 29, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #10650: GitHub Copilot GPT-5 throwing invalid_request_body on requests after compaction - Similar provider/compaction issue with GitHub Copilot
  • #11105: Anthropic models fail with 404 on GitHub Enterprise (GHE.com) - Related to GitHub Enterprise Copilot endpoint issues
  • #9416: Perplexity Sonar models return 400 error with consecutive user messages - Similar 400 error with provider-specific message handling

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 29, 2026): This issue might be a duplicate of existing issues. Please check: - #10650: GitHub Copilot GPT-5 throwing `invalid_request_body` on requests after compaction - Similar provider/compaction issue with GitHub Copilot - #11105: Anthropic models fail with 404 on GitHub Enterprise (GHE.com) - Related to GitHub Enterprise Copilot endpoint issues - #9416: Perplexity Sonar models return 400 error with consecutive user messages - Similar 400 error with provider-specific message handling Feel free to ignore if none of these address your specific case.
Author
Owner

@unimun commented on GitHub (Jan 30, 2026):

Root Cause (Confirmed)

The issue is not about tool messages being rejected by GitHub Copilot Enterprise API itself. The actual problem is:

Empty tools: {} parameter + message history with tool calls = 400 Bad Request

Why This Happens

During compaction:

  1. Tools are intentionally removed to prevent execution during compaction
  2. This leaves tools: {} (empty object)
  3. GitHub Copilot Enterprise validates: "If message history contains tool calls, tools parameter must not be empty"
  4. Validation fails → 400 Bad Request
@unimun commented on GitHub (Jan 30, 2026): ## Root Cause (Confirmed) The issue is not about tool messages being rejected by GitHub Copilot Enterprise API itself. The actual problem is: Empty `tools: {}` parameter + message history with tool calls = 400 Bad Request ## Why This Happens During compaction: 1. Tools are intentionally removed to prevent execution during compaction 2. This leaves `tools: {}` (empty object) 3. GitHub Copilot Enterprise validates: "If message history contains tool calls, tools parameter must not be empty" 4. Validation fails → 400 Bad Request
Author
Owner

@amarjandu commented on GitHub (Feb 2, 2026):

I don't mean to thread-hijack (and can start a new issue if needed I just searched for the error response), but these 400 errors occur for me outside of compaction. I notice that this frequently happens to me w/ models that are provided through github.

Image

After this the session is effectively dead, I have to start a new session :(

@amarjandu commented on GitHub (Feb 2, 2026): I don't mean to thread-hijack (and can start a new issue if needed I just searched for the error response), but these 400 errors occur for me outside of compaction. I notice that this frequently happens to me w/ models that are provided through github. <img width="964" height="419" alt="Image" src="https://github.com/user-attachments/assets/d7e85e98-81f9-447a-8553-522536cb4c08" /> After this the session is effectively dead, I have to start a new session :(
Author
Owner

@nmf commented on GitHub (Feb 12, 2026):

I'm seeing the same using GHE and sonnet 5.

@nmf commented on GitHub (Feb 12, 2026): I'm seeing the same using GHE and sonnet 5.
Author
Owner

@unimun commented on GitHub (Feb 12, 2026):

I'm seeing the same using GHE and sonnet 5.

please check if my pr #11197 works

@unimun commented on GitHub (Feb 12, 2026): > I'm seeing the same using GHE and sonnet 5. please check if my pr #11197 works
Author
Owner

@unimun commented on GitHub (Feb 12, 2026):

I don't mean to thread-hijack (and can start a new issue if needed I just searched for the error response), but these 400 errors occur for me outside of compaction. I notice that this frequently happens to me w/ models that are provided through github.

Image

After this the session is effectively dead, I have to start a new session :(

Could you add how to reproduce it?

@unimun commented on GitHub (Feb 12, 2026): > I don't mean to thread-hijack (and can start a new issue if needed I just searched for the error response), but these 400 errors occur for me outside of compaction. I notice that this frequently happens to me w/ models that are provided through github. > > <img width="964" height="419" alt="Image" src="https://github.com/user-attachments/assets/d7e85e98-81f9-447a-8553-522536cb4c08" /> > > After this the session is effectively dead, I have to start a new session :( Could you add how to reproduce it?
Author
Owner

@amarjandu commented on GitHub (Feb 12, 2026):

I don't mean to thread-hijack (and can start a new issue if needed I just searched for the error response), but these 400 errors occur for me outside of compaction. I notice that this frequently happens to me w/ models that are provided through github.

Image

After this the session is effectively dead, I have to start a new session :(

Could you add how to reproduce it?

Nothing specific, it just occurred w/ usage.

I reinstalled with 'brew install anomalyco/tap/opencode', did a logout/login and no longer have the issue. 🤔

@amarjandu commented on GitHub (Feb 12, 2026): > > I don't mean to thread-hijack (and can start a new issue if needed I just searched for the error response), but these 400 errors occur for me outside of compaction. I notice that this frequently happens to me w/ models that are provided through github. > > > > <img width="964" height="419" alt="Image" src="https://github.com/user-attachments/assets/d7e85e98-81f9-447a-8553-522536cb4c08" /> > > > > After this the session is effectively dead, I have to start a new session :( > > Could you add how to reproduce it? Nothing specific, it just occurred w/ usage. I reinstalled with 'brew install anomalyco/tap/opencode', did a logout/login and no longer have the issue. 🤔
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7960