Skip to content

[Bug] Compaction fails: "No prefix that can be compacted" followed by APIContextOverflowError in v0.15.0 (0% context size displayed - brand new session) #794

Open

Description

@creatiVision

What version of Kimi Code is running?

0.15.0 (Upgraded from 0.14.3 mid-session)

Which open platform/subscription were you using?

https://platform.kimi.ai/

Which model were you using?

openrouter/owl-alpha

What platform is your computer?

Linux 6.8.0-124-generic x86_64 x86_64

What issue are you seeing?

When running an explore agent with multiple MCP servers connected, a context compaction loop fails completely. (Brand new Session with 0% context size though, and getting auto compacted, while micro compaction option is set to false)

First, Kimi throws:
Error: [compaction.unable] No prefix that can be compacted in current history.

Then, it repeatedly attempts to send the request to OpenRouter but fails with:
Error: [compaction.failed] APIContextOverflowError: 400 This endpoint's maximum context length is 1048756 tokens. However, you requested about 1087438 tokens (4999 of text input, 33863 of tool input, 1048576 in the output). Please reduce the length of either one, or use the context-compression plugin to compress your prompt automatically.

Note: This seems highly related to existing issues #476 and #2439, but confirms the bug is still present in v0.15.0.

What steps can reproduce the bug?

  1. Have a heavy tool context (e.g., 9 MCP servers connected). (Though in the old Kimi CLI this setup was working) Context Size shown is 0% though, with a brnad new session throwing the same error.
  2. Run /agent create --type explore --goal "Setup n8n MCP connection for Hermes agent."
  3. Enter prompt: make n8n mcp (probably a docker container on xchg) available for hermes, also make sure n8n docker container or native runs on this system
  4. Context overflows, and compaction fails repeatedly.

What is the expected behavior?

Auto Compact shouldnt turn on immediately with first prompt and 0% Context size and
context compaction should successfully reduce the tool/history context or cleanly reject the prompt before sending an out-of-bounds request that crashes the loop.

Additional information

I have an exported session_47c955fa-5d5e-433e-81bc-8dfe5ea1ef2a.zip file available for the developers if needed for diagnosis.

Activity

  1. added
    bug
    on Jun 15, 2026
  2. mikkihugo commented on Jun 22, 2026

    @mikkihugo

    For anyone hitting this: there are several open PRs addressing the compaction output-cap path that triggers this APIContextOverflowError (compaction requesting a token budget above the model's output limit):

    Might be worth consolidating these against this issue.

  3. creatiVision commented on Aug 24, 2026

    @creatiVision
    Author

    Just to add some color to my original report: this specifically happens because openrouter/owl-alpha advertises a massive maximum output length (1,048,576 tokens).

    Kimi Code takes this and asks for the maximum output tokens for the generation. However, because OpenRouter strictly checks input_tokens + requested_output_tokens <= absolute_context_window upfront, the 38,000 tokens of MCP tool schemas push the total requested size to 1,087,438 — exceeding the model's total context limit of 1,048,756.

    The API instantly rejects the request with a 400 APIContextOverflowError. Because it receives this error, Kimi Code assumes the history is too long and triggers the compaction loop. But since this is a brand new session with just tool definitions and no chat history, compaction fails with No prefix that can be compacted and crashes.

    Workaround: For anyone else stuck on this with OpenRouter models, you can manually override maxTokens (e.g. to 8000) for the specific model in your configuration to prevent it from reserving the entire 1M context window for output!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions