fix: treat overlong prompts as clean truncated rollouts - #1625
Merged
Conversation
An overlong prompt (prompt + requested completion exceeding the model's context window) is a budget limit, not a crash. Previously the model call failed, the interception server returned a 502, and the rollout was recorded as an error. - Add OverlongPromptError(ModelError). Detection lives in the clients: the openai client phrase-matches the provider's 4xx context-length message; the renderer client rebadges the renderers-native client-side OverlongPromptError (raised pre-flight from GET /v1/models, not an OpenAIError) as well as the engine 4xx. - The interception server catches it and ends the rollout cleanly with a `context_length` truncation stop: it returns the last good turn, or refuses the call to halt the harness when there isn't one (the same shape as the existing `refused` path). - Trace.is_truncated counts `context_length`. Mirrors the v0 path (handle_openai_overlong_prompt + renderer_client's RendererOverlongPromptError rebadge). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mikasenghaas
marked this pull request as ready for review
June 11, 2026 06:58
Contributor
ApprovabilityVerdict: Approved Straightforward bug fix that gracefully handles overlong prompt errors as clean truncations rather than crashes. The change is self-contained, limited to error handling paths, and the author is the primary maintainer of these files. You can customize Macroscope's approvability policy. Learn more. |
pull Bot
pushed a commit
to Stars1233/verifiers
that referenced
this pull request
Jun 23, 2026
…ct-ai#1625) * fix(v1): treat overlong prompts as clean truncated rollouts An overlong prompt (prompt + requested completion exceeding the model's context window) is a budget limit, not a crash. Previously the model call failed, the interception server returned a 502, and the rollout was recorded as an error. - Add OverlongPromptError(ModelError). Detection lives in the clients: the openai client phrase-matches the provider's 4xx context-length message; the renderer client rebadges the renderers-native client-side OverlongPromptError (raised pre-flight from GET /v1/models, not an OpenAIError) as well as the engine 4xx. - The interception server catches it and ends the rollout cleanly with a `context_length` truncation stop: it returns the last good turn, or refuses the call to halt the harness when there isn't one (the same shape as the existing `refused` path). - Trace.is_truncated counts `context_length`. Mirrors the v0 path (handle_openai_overlong_prompt + renderer_client's RendererOverlongPromptError rebadge). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(v1): drop redundant comment on the renderer overlong rebadge Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(v1): trim the overlong-prompt comment in handle_chat Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <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.
Summary
Overlong prompts (the prompt + requested completion exceeding the model's context window) are a budget limit, not a crash. Previously the model call failed, the interception server returned a 502, and the rollout was recorded as an error. This makes them produce a clean, truncated rollout instead — so a conversation that simply grows past the context window is preserved as data, not lost to an error.
Detection lives in the clients; the truncation policy lives in the interception server.
v1/errors.py— addOverlongPromptError(ModelError).v1/clients/openai.py—model_error(e)maps a provider 4xx whose message matches a context-length phrase toOverlongPromptError(any other failure stays aModelError).v1/clients/renderer.py— rebadge the renderers-native client-sideOverlongPromptError(raised pre-flight fromGET /v1/models, so it is not anOpenAIError) and the engine 4xx. Without this the renderer path's overlong would slip through uncaught.v1/interception/server.py—handle_chatcatchesOverlongPromptError, sets acontext_lengthtruncation stop, and mirrors the existingrefusedpath: it returns the last good turn when a simulated conversation already produced one, else refuses the call to halt the harness cleanly (Harness.runtreats an exit after a stop condition as expected).v1/trace.py—Trace.is_truncatedcountscontext_length.Mirrors the v0 path (
@handle_openai_overlong_prompt+renderer_client'sRendererOverlongPromptErrorrebadge).Verification
Ran a multi-turn echo rollout (
echo-multi-v1, user-simulator driven, with a longphrasesoverride) against a local vLLM served with--max-model-len 1024, so the conversation grows until the prompt overflows the context window.Before (the overlong turn surfaces as a hard failure):
After — for both the
openaiandrenderersclients, and both branches:last is not None)has_error=False,stop_condition=context_length,is_truncated=True, 5 turns preservedhas_error=False,stop_condition=context_length,is_truncated=True, 5 turns preservedlast is None, harness halted via 400)has_error=False,stop_condition=context_length,is_truncated=True, 0 turnsNote
Treat overlong prompts as clean truncated rollouts in the interception server
OverlongPromptErrorin errors.py as aModelErrorsubclass for context-length failures, distinct from generic model errors.OverlongPromptErrorinstead ofModelErrorwhen the underlying error text indicates a context-length overflow.InterceptionServer.handle_chathandler in server.py to catchOverlongPromptError, stop the trace with reason"context_length", and return the last assistant turn as a normal completion (or a 400 if no prior turn exists) instead of a 502."context_length"as truncated viaTrace.is_truncatedin trace.py.Macroscope summarized 36d1455.
Note
Medium Risk
Changes rollout completion semantics for a common failure mode (context overflow); incorrect phrase matching could misclassify other API errors as truncation.
Overview
Context-window overflows are treated as clean truncations instead of rollout failures.
Adds
OverlongPromptErrorand maps provider/renderer context-length failures to it viamodel_error()(OpenAI client) and renderer pre-flight rebadging. The interception server catches this like other budget stops: setsstop_conditiontocontext_length, returns the last good assistant turn when one exists, or a 400rollout stopped: context_lengthon the first turn.Trace.is_truncatednow includescontext_length.Rollouts that grow past the model limit keep prior turns as data (
has_error=False) rather than ending in a 502 andProgramError.Reviewed by Cursor Bugbot for commit 36d1455. Bugbot is set up for automated code reviews on this repo. Configure here.