Repository navigation
fix(embeddings): match a third OpenAI token-limit error phrasing - #404
Merged
ofriw merged 1 commit intoSep 8, 2026
Merged
Conversation
_embed_batch_internal's classifier only recognized "maximum context length"+"tokens" or "tokens"+"max"+"per request". The reported message "the input length exceeds the context length" matches neither, so the error propagated instead of triggering the existing split-and-retry path in handle_token_limit_error. Fixes chunkhound#210
ofriw
approved these changes
Sep 8, 2026
ofriw
left a comment
Collaborator
There was a problem hiding this comment.
Thank you so much for this valuable contribution! LGTM
Contributor
Author
|
Appreciate it. This one closes the last of the three OpenAI token-limit phrasings the classifier was missing, so the split-retry path should catch all of them now. |
HananKavitzAmat
added a commit
to HananKavitzAmat/chunkhound
that referenced
this pull request
Sep 15, 2026
…e matching
The 400 -> context-length classifier matched a bare "context", or any body
containing both "token" and "limit". Python's live path uses three
conjunctive predicates: ("maximum context length" AND "tokens"), ("tokens"
AND "max" AND "per request"), or ("input length exceeds" AND "context
length"). The Rust set was a strict superset, so nothing was missed -- the
problem was the other direction.
`ContextLengthExceeded` is the only error `embed_with_split` recovers from,
and it is excluded from retry, so a misclassified 400 recurses through
batch halving and issues up to 2N-1 requests against an endpoint that
already refused the batch (N is `embed_batch_size`, default 200). It then
records "input exceeds the provider context limit" for every chunk, burying
the real cause -- a quota error or a rejected parameter reads to the user as
"your chunks are too long".
Extract the predicate into `common.rs::is_context_length_error` and call it
from both providers. Sharing it is the point: the copies were
character-for-character identical, this classifier has needed three upstream
revisions (most recently chunkhound#404), and a per-provider copy is the likeliest way
a future fix lands in one file only.
Case-insensitivity is kept and documented as a deliberate widening over
Python's case-sensitive checks -- it only adds bodies differing by
capitalisation, and errs toward the recoverable path.
Tests: unit tests for all three phrasings plus the non-length bodies that
the loose version wrongly accepted, and a contract test asserting a
non-length 400 issues exactly one request. Verified against a build with the
loose predicate restored: the contract test fails with "3 requests issued
where 1 was expected" while the three positive tests still pass, so the new
test is the discriminating one.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
_embed_batch_internal's token-limit classifier only recognizes two phrasings from the OpenAI API:"maximum context length"+"tokens", or"tokens"+"max"+"per request". The reported error,the input length exceeds the context length, matches neither, so it falls through toraiseinstead of routing through the existing split-and-retry logic inhandle_token_limit_error, and the whole batch fails outright.This adds a third condition matching
"input length exceeds"+"context length", following the same style as the two existing ones.Verification:
tests/unit/test_openai_provider_token_limit.py) reproduces the reported message against a mockedBadRequestError: fails onmain(error propagates), passes on this branch (batch splits and completes). A second test pins that an unrelatedBadRequestErrorstill raises.tests/unit/suite (1799 tests) passes unchanged.ruff check/ruff format --checkclean on the changed lines;mypyclean on the changed file.