Skip to content

Bad Request on Compaction only #13533

Closed as not planned
Closed as not planned

Description

@vmagalhaes

Description

Hello,

When the compaction starts, it automatically stops saying "Bad Request" but only for Claude Opus 4.5 (I'm using github copilot integration).
And now that we are here, any idea why I can't use Opus 4.6 with my github copilot integration? It's enabled for my github enterprise integration.

Any idea why?

Plugins

oh-my-opencode

OpenCode version

1.1.65

Steps to reproduce

  1. Start opencode
  2. Write a prompt
  3. Automatically starts the compaction
  4. Bad Request

Screenshot and/or share link

Image

Operating System

macOS 26

Terminal

Warp

Activity

  1. georgeharker commented on Feb 14, 2026

    @georgeharker
    Contributor

    Still occurring? I was having compaction related issues yesterday that appear to have been resolved on github's end: #13444

  2. vmagalhaes commented on Feb 14, 2026

    @vmagalhaes
    Author

    Still occurring? I was having compaction related issues yesterday that appear to have been resolved on github's end: #13444

    Yes, the issue still persist, at least until 2h ago.

  3. dotned commented on Mar 5, 2026

    @dotned

    I keep getting this after a compaction, maybe the same issue. No logs tell me why and it is getting quite frustrating as it leaves the session unrecoverable.

    Image

    Update:

    Spent hours on this, trying older versions, even pulled the code and tried to get more insight. Got nowhere. I'm not even over quota...

    Image

    I'm starting to think it's on the GH side at this stage.

    Update 2:

    I think there may be two issues here. @danriedl is showing a workaround to a >100% context usage issue, where it appears compaction overflows the models context window. My situation is different as I'm around 80% context usage and hitting errors.

    I have managed to step past my issue by setting the compact agent to a non Anthropic model, GPT-5.2, which would suggest there is something in the way Claude models are called. I'm using GitHub Copilot Enterprise, specificity the GHE.com version.

    I need to verify but some AI assisted analysis seems to point to packages/opencode/src/provider/transform.ts and specifically the code used to set the headers etc for Claude models, with GH rejecting with a 400.

  4. danriedl commented on Mar 5, 2026

    @danriedl

    I do have the exact same issue. Was deleting .local/share/opencode but did not help.
    Im on the newest release 1.2.17
    Only way around this is to export the session after the context exceeded and compaction failed and continue in a new session.
    Problem exists since 3 weeks, as @vmagalhaes also described.

    Is it something hardcoded when the session should be compacted and it might changed?

    Image Image

    Update:

    This is what Opus4.6 reported for the opencode repository itself:

    The Actual Bug in opencode
    There are two bugs in the codebase:

    1. compaction.ts sends all messages without checking if they fit the compaction model's context window. It should either truncate older messages or use a smarter strategy (e.g., summarize in chunks).
    2. isOverflow doesn't apply the reserved buffer when limit.input is undefined (packages/opencode/src/session/compaction.ts:44-46). The else branch should be context - maxOutputTokens - reserved to ensure there's enough headroom for the compaction call itself.

    Temporary Fix:
    In your opencode.json, configure the compaction agent to use a smaller/cheaper model with a large context window:

    {
      "agent": {
        "compaction": {
          "model": "github-copilot-enterprise/claude-sonnet-4"
        }
      }
    }
  5. BleTib commented on Mar 10, 2026

    @BleTib

    I also have the same issue with GHE on v1.2.22

  6. zwarag commented on Mar 11, 2026

    @zwarag

    i also run into this issue

    Temporary Fix: In your opencode.json, configure the compaction agent to use a smaller/cheaper model with a large context window:

    {
    "agent": {
    "compaction": {
    "model": "github-copilot-enterprise/claude-sonnet-4"
    }
    }
    }

    I'm using with github-copilot-enterprise/gpt-5.2-codex for compaction because I had the same issue with sonnet.

  7. tlaukkanen commented on Mar 11, 2026

    @tlaukkanen

    Having the same issue with GHE on v1.2.24 and Claude Opus 4.6. Switching to GPT-5.4 works and it does the compaction after saying "continue". Probably could then switch back to Opus 4.6 after compaction.

  8. vmagalhaes commented on Mar 11, 2026

    @vmagalhaes
    Author

    I'm closing the issue, looks like a common issue, for GHE it's preferred to use Copilot CLI (mainly because opencode doesn't manage copilot requests, only tokens).

  9. danriedl commented on Mar 11, 2026

    @danriedl

    @vmagalhaes, opening an issue only to close it because you've ditched for another tool?
    That's not how open source rolls. It's collaborative efforts and not a drive-by.
    We've already nailed down the problem (check my response above), so this should stay open for someone with the guts to fix it.

  10. BleTib commented on Mar 11, 2026

    @BleTib

    @vmagalhaes, opening an issue only to close it because you've ditched for another tool? That's not how open source rolls. It's collaborative efforts and not a drive-by. We've already nailed down the problem (check my response above), so this should stay open for someone with the guts to fix it.

    agree

    the workaround from above seems to work with gpt.

    in ~/.config/opencode/opencode.json

    {
      "agent": {
        "compaction": {
          "model": "github-copilot-enterprise/gpt-5.4"
        }
      }
    }
    
  11. georgeharker commented on Mar 11, 2026

    @georgeharker
    Contributor

    That helps but you still pay a premium request on resuming after compaction

  12. vmagalhaes commented on Mar 12, 2026

    @vmagalhaes
    Author

    @vmagalhaes, opening an issue only to close it because you've ditched for another tool? That's not how open source rolls. It's collaborative efforts and not a drive-by. We've already nailed down the problem (check my response above), so this should stay open for someone with the guts to fix it.

    I closed it because that are already open issues with the same discussion. But then I’m reopening this one and you can discuss in here too.

  13. dezren39 commented on Mar 31, 2026

    @dezren39

    in the mean time i fixed this another way..
    https://github.com/developing-today/opencode-auto-continue

  14. removed
    bugSomething isn't working
    on May 3, 2026
  15. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions