fix(provider): map model_context_window_exceeded to length finish reason#18918
Closed
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
Closed
fix(provider): map model_context_window_exceeded to length finish reason#18918kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
Conversation
Some providers (Anthropic via z.ai, zhipuai) return finish_reason: "model_context_window_exceeded" when the prompt exceeds the model's context window. This was falling through to "unknown", causing the session loop to retry indefinitely instead of triggering compaction. Map it to "length" so it flows into the existing context overflow / compaction logic. Fixes anomalyco#18813
Collaborator
|
Closing because PR is not applicable, u did not read the readme for the files u touched. |
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.
Issue for this PR
Closes #18813
Type of change
What does this PR do?
Some providers (Anthropic via z.ai, zhipuai) return
finish_reason: "model_context_window_exceeded"when the prompt exceeds the model's context window. This finish reason was not mapped in the two finish-reason mapping functions, causing it to fall through to"unknown".When the session loop sees
"unknown", it retries indefinitely with exponential backoff instead of triggering compaction — burning tokens and money in an infinite loop.This PR maps
"model_context_window_exceeded"to"length"in both:map-openai-compatible-finish-reason.ts(Chat API path)map-openai-responses-finish-reason.ts(Responses API path)This routes it into the existing context overflow / compaction logic, matching the semantics of
"length"(prompt too long).How did you verify your code works?
"length"already triggers compaction correctly in the session processor (processor.ts)Screenshots / recordings
N/A — finish reason mapping change
Checklist