Skip to content

fix: recover from model token limit errors - #207

Merged
kermanx merged 1 commit into
mainfrom
xtr/fix-model-token-limit-compaction
May 29, 2026
Merged

fix: recover from model token limit errors#207
kermanx merged 1 commit into
mainfrom
xtr/fix-model-token-limit-compaction

Conversation

@kermanx

@kermanx kermanx commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This fixes a reproducible long-conversation failure where a provider reports context overflow as a generic 400 model token limit error.

Problem

Some providers return context overflow as Your request exceeded model token limit instead of the context overflow phrases Kimi already recognized. Kimi treated that response as a non-retryable provider API error, so compaction did not shrink and retry the request. When a turn was blocked waiting for auto compaction and compaction ultimately failed, the turn could then continue with the original oversized context and surface a second provider error.

What changed

  • Classify provider model token limit 400 responses as context overflow so the existing compaction recovery path can handle them.
  • Propagate blocked auto-compaction failures back to the waiting turn instead of continuing with the uncompressed context.
  • Add regression coverage for both the provider error normalization and blocked auto-compaction failure path.

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.

Validation

  • pnpm vitest run packages/kosong/test/errors.test.ts
  • pnpm vitest run packages/agent-core/test/agent/compaction.test.ts
  • pnpm --filter @moonshot-ai/kosong run typecheck
  • pnpm --filter @moonshot-ai/agent-core run typecheck
  • pnpm exec oxlint --type-aware packages/kosong/src/errors.ts packages/kosong/test/errors.test.ts packages/agent-core/src/agent/compaction/full.ts packages/agent-core/test/agent/compaction.test.ts
  • pnpm --filter @moonshot-ai/agent-core run test
  • pnpm vitest run packages/kosong/test
  • git diff --check

@changeset-bot

changeset-bot Bot commented May 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d6cd835

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

This PR includes changesets to release 3 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kosong Patch
@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 May 29, 2026

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

commit: d6cd835

@kermanx
kermanx merged commit e280f33 into main May 29, 2026
7 checks passed
@kermanx
kermanx deleted the xtr/fix-model-token-limit-compaction branch May 29, 2026 09:28
@github-actions github-actions Bot mentioned this pull request May 29, 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