fix(agent-core): classify context-worded 401/403 as context.overflow instead of auth error - #1
Closed
bowser-bot wants to merge 1 commit into
Closed
fix(agent-core): classify context-worded 401/403 as context.overflow instead of auth error#1bowser-bot wants to merge 1 commit into
bowser-bot wants to merge 1 commit into
Conversation
…xt.overflow The Kimi managed subscription intentionally returns 401/403 for capability rejections worded as "<model> supports only <N> context". Treating every 401 as a credential failure forced a pointless token refresh and surfaced "Authentication required" for an over-long context, both over ACP and in the TUI. - kosong: add isKimiContextCapabilityError in the Kimi vendor error module (providers/kimi-errors.ts, next to classifyKimiQuotaError), with a quantity-anchored wording gate so auth/scope rejections that merely mention "context" stay on the credential path; the shared provider-agnostic classification is untouched, so non-Kimi providers are unaffected - agent-core / node-sdk OAuth wrappers: skip the forced token refresh on these errors and throw CONTEXT_OVERFLOW with the provider's message instead of a misleading re-login prompt - agent-core serialize: map the same wording on 401/403 to the context.overflow payload code instead of provider.auth_error - compaction: propagate context.overflow unwrapped (matching the existing auth-code passthrough) and treat its KimiError form as recoverable so shrink-and-retry still applies - acp-adapter: a turn.ended failure coded context.overflow now rejects session/prompt with -32603 carrying the code as structured data instead of silently resolving end_turn; wire data codes are limited to a public whitelist and raw provider messages/stacks never cross the wire - agent-core-v2 parity: the model requester skips the forced refresh and re-mints Kimi context-worded 401s as APIContextOverflowError; classifyApiError classifies them as context_overflow - turn telemetry: check the Kimi-scoped wording before the auth statuses; baseline status ordering otherwise unchanged
bowser-bot
force-pushed
the
fix/context-overflow-401-classification
branch
from
August 4, 2026 18:15
3958e0e to
36d57be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Related to MoonshotAI#2613
Problem
The Kimi managed subscription intentionally returns 401/403 for capability rejections worded as
<model> supports only <N> context. The client treated every 401 as a credential failure, so an over-long context (e.g. an auto-compaction request that itself exceeds a 256K model's window) forced a pointless token refresh and surfaced as-32000 Authentication requiredover ACP — indistinguishable from a real auth problem.What changed
The 401/403 detection is added only in the Kimi vendor error module (
kosong/src/providers/kimi-errors.ts, beside the existingclassifyKimiQuotaError), with a quantity-anchored wording gate: a size must follow "supports only" (256K context,kimi-k3 up to 256K context). Auth/scope rejections that merely mention "context" in prose keep the credential path, and the shared provider-agnostic classification is untouched — nothing changes for non-Kimi providers.agent-core/session/provider-manager.ts,node-sdk/kimi-code-model-provider.ts): skip the forced token refresh and throwCONTEXT_OVERFLOWwith the provider's message instead of a misleading re-login prompt.errors/serialize.tsmaps the same wording to thecontext.overflowpayload code.agent-core-v2): the model requester skips the forced refresh and re-mints the error asAPIContextOverflowError;classifyApiErrorreportscontext_overflow, notauth.agent-core/compaction/full.ts): propagatescontext.overflowunwrapped (matching the existing auth-code passthrough) and treats its KimiError form as recoverable, keeping the shrink-and-retry path.acp-adapter/session.ts): aturn.endedfailure codedcontext.overflownow rejectssession/promptwith-32603and structureddata{ code: "context.overflow" }instead of silently resolvingend_turn. Only whitelisted public codes cross asdata.code; raw provider messages and stacks never cross the wire. Other non-auth codes keep the log-and-resolve path.agent-core/turn/index.ts): checks the Kimi-scoped wording before the auth statuses; ordering otherwise unchanged.Out of scope (awaiting maintainer feedback on the issue):
session/set_modelpre-flight checks and chunking oversized compaction input. Wordings without a quantity are not matched by design; the Kimi-scoped pattern is the single extension point.Checklist
gen-changesetsskill, or this PR needs no changeset. — changeset added (minor, both publishable packages; wire-visible behavior semantics change)gen-docsskill, or this PR needs no doc update. — behavior fix only, no config/API surface changeVerification
kosong+acp-adapter+node-sdk— 2046 passed;agent-core— 4132 passed;agent-core-v2— 4676 passed, 11 failed (plugin zip/GitHub install fixtures that fail identically on the base commit in this sandbox — unrelated)pnpm typecheckclean;oxlint0 errors on changed files401 k3-256k supports only 256K context.→ no forced refresh, turn failscontext.overflow, ACP client receives-32603+data.code; genuine-auth negatives (Bearer/scope phrasings) still refresh and stay auth errors.