Skip to content

fix: classify context-overflow 401 responses correctly - #2655

Open
crow-1412 wants to merge 2 commits into
MoonshotAI:mainfrom
crow-1412:agent/fix-context-overflow-auth-classification
Open

fix: classify context-overflow 401 responses correctly#2655
crow-1412 wants to merge 2 commits into
MoonshotAI:mainfrom
crow-1412:agent/fix-context-overflow-auth-classification

Conversation

@crow-1412

Copy link
Copy Markdown

Related Issue

Resolve #2613

Problem

Some managed models return HTTP 401 when a request exceeds the model context window. The provider message identifies the context limit, but both engines treated every 401 as an authentication failure, retried with a refreshed OAuth token, and ACP ultimately reported Authentication required.

What changed

  • Recognize context-limit wording, including supports only 256K context, before generic 401 authentication handling in both engines.
  • Skip OAuth refresh for those errors while keeping the existing refresh-and-retry behavior for genuine credential failures.
  • Preserve context.overflow through failed compaction and expose its actionable provider message to ACP clients.
  • Add regression coverage for error normalization, OAuth refresh boundaries, compaction propagation, telemetry, serialization, and both ACP failure paths.

Validation

  • Focused Vitest run: 11 files passed, 517 tests passed, 1 skipped.
  • TypeScript checks passed for kosong, agent-core, agent-core-v2, kimi-code-sdk, and acp-adapter.
  • agent-core-v2 import-boundary check passed.
  • Repository lint completed with 0 errors.

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 Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8eeac58

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

@crow-1412
crow-1412 marked this pull request as ready for review August 5, 2026 15:31

@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: cc3ebf04a2

ℹ️ 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".

(error.code === ErrorCodes.AUTH_LOGIN_REQUIRED ||
error.code === ErrorCodes.PROVIDER_AUTH_ERROR)
error.code === ErrorCodes.PROVIDER_AUTH_ERROR ||
error.code === ErrorCodes.CONTEXT_OVERFLOW)

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 Avoid re-running failed compactions as fresh overflows

When a scheduled auto-compaction in the beforeStep path itself exhausts its shrink attempts with context.overflow, rethrowing that provider error unchanged lets the loop-level full-compaction error handler match it as a new recoverable overflow (shouldRecoverFromContextOverflow accepts any coded context.overflow) and start another auto-compaction instead of failing immediately. That repeats an already-failed summarizer request and can add another expensive provider round-trip before the turn fails; the legacy path tags these as compaction_context_overflow, so v2 should similarly mark or guard compaction-origin overflows while preserving the public code/message.

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

1 participant