Skip to content

fix(agent-core): cap compaction output at 128k by default - #1156

Merged
wbxl2000 merged 1 commit into
mainfrom
fix/compaction-default-output-cap
Jun 27, 2026
Merged

fix(agent-core): cap compaction output at 128k by default#1156
wbxl2000 merged 1 commit into
mainfrom
fix/compaction-default-output-cap

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

Follow-up to #1129 and #1131.

Problem

After #1129, compaction reads maxOutputSize from the model config. But when maxOutputSize is not configured, compaction still falls back to the full context window size (max_context_tokens, often 1M+), which can exceed the max_tokens ceiling enforced by OpenAI-compatible providers (e.g. [1, 393216]), triggering 400 Invalid max_tokens errors.

#1131 added a 128k ceiling to the OpenAI Legacy provider, but the Kimi provider has no such ceiling, and compaction was intentionally left uncapped so it can always produce a summary. This leaves Kimi and any future chat-completions provider without a safe default.

What changed

  • When maxOutputSize is not set and the model's context window is known, compaction now caps its output at min(max_context_tokens, 128k) instead of the full context window. This keeps compaction uncapped enough to produce a summary while staying below common provider ceilings.
  • When the context window is unknown (max_context_tokens === 0), the existing conservative fallback (32k or reservedContextSize) is preserved, so the unknown-context behavior is unchanged.
  • When maxOutputSize is explicitly configured, it still takes precedence — this only changes the default.
  • Added a test verifying the default 128k cap is applied when maxOutputSize is not configured.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aa0bd5d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 27, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@aa0bd5d
npx https://pkg.pr.new/@moonshot-ai/kimi-code@aa0bd5d

commit: aa0bd5d

@wbxl2000
wbxl2000 merged commit 794db55 into main Jun 27, 2026
10 checks passed
@wbxl2000
wbxl2000 deleted the fix/compaction-default-output-cap branch June 27, 2026 15:24
@github-actions github-actions Bot mentioned this pull request Jun 27, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant