Skip to content

fix: treat overlong prompts as clean truncated rollouts - #1625

Merged
mikasenghaas merged 4 commits into
feat/nano-as-v1from
fix/v1-overlong-prompt-truncation
Jun 11, 2026
Merged

fix: treat overlong prompts as clean truncated rollouts#1625
mikasenghaas merged 4 commits into
feat/nano-as-v1from
fix/v1-overlong-prompt-truncation

Conversation

@mikasenghaas

@mikasenghaas mikasenghaas commented Jun 11, 2026

Copy link
Copy Markdown
Member

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 — add OverlongPromptError(ModelError).
  • v1/clients/openai.pymodel_error(e) maps a provider 4xx whose message matches a context-length phrase to OverlongPromptError (any other failure stays a ModelError).
  • v1/clients/renderer.py — rebadge the renderers-native client-side OverlongPromptError (raised pre-flight from GET /v1/models, so it is not an OpenAIError) and the engine 4xx. Without this the renderer path's overlong would slip through uncaught.
  • v1/interception/server.pyhandle_chat catches OverlongPromptError, sets a context_length truncation stop, and mirrors the existing refused path: it returns the last good turn when a simulated conversation already produced one, else refuses the call to halt the harness cleanly (Harness.run treats an exit after a stop condition as expected).
  • v1/trace.pyTrace.is_truncated counts context_length.

Mirrors the v0 path (@handle_openai_overlong_prompt + renderer_client's RendererOverlongPromptError rebadge).

Verification

Ran a multi-turn echo rollout (echo-multi-v1, user-simulator driven, with a long phrases override) 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):

openai.InternalServerError: Error code: 502 - "The prompt is 1025 tokens, which exceeds
the model's maximum context length of 1024 tokens" → ProgramError: harness exited 1

After — for both the openai and renderers clients, and both branches:

client scenario result
openai multi-turn overflow (last is not None) has_error=False, stop_condition=context_length, is_truncated=True, 5 turns preserved
renderers multi-turn overflow has_error=False, stop_condition=context_length, is_truncated=True, 5 turns preserved
openai first-turn overflow (last is None, harness halted via 400) has_error=False, stop_condition=context_length, is_truncated=True, 0 turns
renderers first-turn overflow same

Note

Treat overlong prompts as clean truncated rollouts in the interception server

  • Introduces OverlongPromptError in errors.py as a ModelError subclass for context-length failures, distinct from generic model errors.
  • Updates openai.py and renderer.py to raise OverlongPromptError instead of ModelError when the underlying error text indicates a context-length overflow.
  • Updates the InterceptionServer.handle_chat handler in server.py to catch OverlongPromptError, 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.
  • Marks traces stopped due to "context_length" as truncated via Trace.is_truncated in trace.py.
  • Behavioral Change: overlong-prompt failures that previously produced 502 errors now produce either a valid completion response or a 400, and the trace is flagged as truncated.

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 OverlongPromptError and maps provider/renderer context-length failures to it via model_error() (OpenAI client) and renderer pre-flight rebadging. The interception server catches this like other budget stops: sets stop_condition to context_length, returns the last good assistant turn when one exists, or a 400 rollout stopped: context_length on the first turn. Trace.is_truncated now includes context_length.

Rollouts that grow past the model limit keep prior turns as data (has_error=False) rather than ending in a 502 and ProgramError.

Reviewed by Cursor Bugbot for commit 36d1455. Bugbot is set up for automated code reviews on this repo. Configure here.

mikasenghaas and others added 4 commits June 11, 2026 06:56
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
mikasenghaas marked this pull request as ready for review June 11, 2026 06:58
@mikasenghaas
mikasenghaas merged commit fd6a083 into feat/nano-as-v1 Jun 11, 2026
3 checks passed
@macroscopeapp

macroscopeapp Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant