Repository navigation
fix(opensecret): return context_length_exceeded for provider context rejections - #1627
Merged
Merged
Conversation
…rejections A provider's context rejection reached clients as upstream_context_limit, in a flat body, with wording no client recognizes. Coding agents detect an overflow by OpenAI's context_length_exceeded code or by known wording, then compact and retry; under ours they failed the turn. The context-limit detail of PublicProviderError now uses OpenAI's code on every surface (error-code header, pre-stream body, Chat stream payload, Responses failure) and says the request exceeds the context window. Pre-stream provider errors add the nested OpenAI error object that usage and plan errors already carry; the flat fields stay. The proxy forwards backend errors unchanged, so proxy and SDK changes are fixture renames. A Maple Work test pins that the enclave's body reads as an overflow on both of its paths. Co-Authored-By: Claude <noreply@anthropic.com>
AnthonyRonning
added a commit
that referenced
this pull request
Nov 21, 2026
The Rust SDK lost public Transport V1 items in #1650, so its next publication is a major version. The proxy moves to 0.5.1 because its runtime changed since the released 0.5.0 (#1627) and it now requires maple-sdk 5.0.0. Only the two local package entries change in each lockfile. Co-authored-by: Claude <noreply@anthropic.com>
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.
Problem
When a provider rejects a request as too long, clients get
upstream_context_limitin a header, a flat{"status","message"}body, and wording no client recognizes. Coding agents decide "the context overflowed, compact and retry" by matching OpenAI'scontext_length_exceededcode or a known phrase. Ours matched neither, so OpenCode, and Maple Work's own agent, failed the turn instead of compacting. A user hit this with Kimi K3.1 Pro through the local proxy and OpenCode.Where the fix lives
In the enclave, in
PublicProviderError, the one type that owns this error's public code and message. The proxy forwards backend errors byte for byte and both desktop apps embed that proxy, so a proxy-side translation would reach only proxy users, only after they update, and would leave the stream payload and Responses failure on the old code.Why
context_length_exceededIt is OpenAI's own code for this rejection on the API shape Maple serves.
upstream_context_limitwas a name of ours that no client knew. Checked in each client's source:error.code == "context_length_exceeded"as an overflow and compact.error.codefor it before falling back to message matching.context_length_exceededor the phrase "exceeds the context window".Change
context_length_exceededon every surface:x-opensecret-error-code, the pre-stream body, the Chat stream error payload and the Responses failure.errorobject (message,code,type), as usage and plan errors already do and as the stream payload already did. The flatstatusandmessagestay.Before:
{"status":400,"message":"Upstream provider rejected the context or token limit. Reduce the input or requested output tokens."}After:
{"status":400,"message":"Upstream provider rejected the request because it exceeds the context window. Reduce the input or requested output tokens.","error":{"message":"Upstream provider rejected the request because it exceeds the context window. Reduce the input or requested output tokens.","code":"context_length_exceeded","type":"invalid_request_error"}}No proxy or SDK runtime change. Their diffs rename the code in pass-through fixtures.
Compatibility
upstream_context_limitno longer exists. In this repo only tests and the log allowlist used it. An outside client keyed on that header value needs the new code.upstream_*provider error gains the nestederrorobject before streaming starts. Their codes, messages and statuses are unchanged.public_error_codelog field reportscontext_length_exceeded.max_tokens_limit_exceededfrom a provider still maps to this same detail, as before.Evidence
Not verified: an end-to-end OpenCode session, a live provider rejection, or a deployed enclave. Nothing changes for users until the enclave is deployed.
🤖 Generated with Claude Code