Skip to content

fix(agent-core): honor model output cap during compaction#829

Open
mikkihugo wants to merge 4 commits into
MoonshotAI:mainfrom
mikkihugo:fix/full-compaction-max-output-size
Open

fix(agent-core): honor model output cap during compaction#829
mikkihugo wants to merge 4 commits into
MoonshotAI:mainfrom
mikkihugo:fix/full-compaction-max-output-size

Conversation

@mikkihugo

@mikkihugo mikkihugo commented Jun 16, 2026

Copy link
Copy Markdown

Related Issue

No linked issue. This fixes a reproducible full-history compaction failure when a model alias has a larger context window than output-token limit.

Problem

Full compaction reused the selected model provider but resolved its completion budget without the model output cap. Any model alias with max_context_size greater than max_output_size could make compaction request a token budget above the provider limit and fail before producing a summary.

What changed

  • Pass the selected model output cap into full-compaction budget resolution.
  • Add a regression test that covers compaction after a context-overflow-triggered retry.
  • Add a patch changeset for the CLI package because the internal fix affects bundled CLI behavior.

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.

Verification:

  • pnpm exec vitest run packages/agent-core/test/agent/compaction/full.test.ts packages/agent-core/test/utils/completion-budget.test.ts --config vitest.config.ts

Copilot AI review requested due to automatic review settings June 16, 2026 20:06
@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eb01127

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

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code Patch
@moonshot-ai/agent-core 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR ensures full-history compaction respects the model’s output token limit by wiring maxOutputSize into the completion budgeting logic, with a regression test and a changeset entry.

Changes:

  • Pass maxOutputSize into resolveCompletionBudget during full compaction.
  • Add a test that verifies compaction honors a model-level maxOutputSize cap.
  • Add a changeset documenting the patch behavior change.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/agent-core/src/agent/compaction/full.ts Threads maxOutputSize into completion-budget resolution during compaction.
packages/agent-core/test/agent/compaction/full.test.ts Adds coverage to assert compaction uses the model’s output cap.
.changeset/honest-timers-flow.md Documents the patch release note for the behavior change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


it('honors model maxOutputSize during compaction', async () => {
let callCount = 0;
const compactionMaxCompletionTokens: unknown[] = [];
Comment on lines +1651 to +1657
const providerManager = ctx.agent.modelProvider;
if (providerManager === undefined) throw new Error('Expected provider manager');
const resolveProviderConfig = providerManager.resolveProviderConfig.bind(providerManager);
providerManager.resolveProviderConfig = (model) => ({
...resolveProviderConfig(model),
maxOutputSize: 32768,
});

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b91e242cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge List agent-core in the changeset

This changeset only selects the CLI even though the diff changes packages/agent-core/src/agent/compaction/full.ts. The current gen-changesets rules require source changes that affect a package's output to list that package, and internal package changes that enter the CLI bundle should list both the internal package and @moonshot-ai/kimi-code; otherwise the agent-core version/changelog will not record this fix when the changeset is consumed.

Useful? React with 👍 / 👎.

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.

2 participants