Repository navigation
Description
Problem
Gym's model server can return a successful OpenAI-compatible response that does not faithfully describe what happened during upstream execution.
Two current vllm_model paths demonstrate the problem:
- When sequential reasoning is disabled and the request's last message is an assistant message with no content and no tool calls, Gym returns a synthetic HTTP 200 response with
finish_reason: "content_filter". No upstream model request occurs. (Chat-completions path only: the completions-API path never runs this check, and the responses-native path rejectssequential_reasoning_allowed=falseoutright.) - When vLLM rejects a request with HTTP 400 whose error body mentions
context lengthormax_tokens(typically an oversized context or requested token count), Gym returns a synthetic HTTP 200 response withfinish_reason: "length". This adaptation exists on both the chat-completions path and the completions-API path (_chat_completions_via_completions_api).
The capture middleware observes only the response returned by Gym. Consequently, persisted model-call records contain information such as:
{
"status_code": 200,
"error_category": null,
"finish_reason": "content_filter",
"tokens_in": null,
"tokens_out": null
}or:
{
"status_code": 200,
"error_category": null,
"finish_reason": "length",
"tokens_in": null,
"tokens_out": null
}These records do not reveal:
- whether an upstream model request occurred;
- whether the upstream request failed, when the failure was adapted into a normal-looking response rather than raised;
- the original upstream status code on those adapted paths;
- why Gym produced a synthetic response.
(When the handler raises, the middleware already extracts the upstream status and body from the exception and classifies it into error_category; the blind spot is exactly the paths where the server swallows the upstream outcome — the two synthetic paths above — or never calls upstream at all.)
Consumers therefore cannot distinguish:
- a locally generated response that never invoked a model;
- an upstream error adapted into an HTTP 200 response;
- a real successful provider response that omitted token usage.
Inferring this distinction from finish_reason, request contents, or synthetic response IDs would couple consumers to implementation details and misclassify genuine provider responses. This is not hypothetical: harbor_agent already keys on the shared synthetic ID chtcmpl-123 and reports every match as context-length exceeded — misclassifying the empty-assistant short-circuit, since all synthetic call sites reuse that ID.
Required behavior
Persist the upstream execution outcome explicitly in model-call observability.
The representation must communicate at least:
- whether an upstream request was attempted;
- whether the returned response was produced locally;
- the original upstream HTTP status, when available;
- a normalized reason or error category for locally adapted outcomes.
Exact field names are an implementation choice. One possible representation is:
execution_kind: Literal["upstream", "local_short_circuit"] | None
upstream_status_code: int | None
error_category: str | None
local_response_reason: str | NoneNew fields must be optional so existing capture and trajectory records remain readable.
Implementation scope
- Annotate the empty-assistant short-circuit as locally produced without an upstream request.
- Preserve the upstream HTTP 400 and classify it as
context_length_exceededwhen Gym adapts an excessive-context error into a syntheticlengthresponse — on both the chat-completions and completions-API paths. - Account for the Responses-dialect conversion, which remaps the synthetic
finish_reason: "length"toincomplete_details.reason: "max_output_tokens"— capture-side classification must not key on the chat-dialectlengthlabel alone. - Propagate the execution metadata through:
- raw model-call capture sidecars;
ModelCallRecord;ng_model_call_capture;TrajectoryModelCalland its response metadata.
- Preserve the model server's current externally visible response behavior.
- Do not infer execution outcomes later from response IDs, finish reasons, or request shape.
- Migrate
harbor_agent's existingchtcmpl-123response-ID check to the new metadata (or keep the ID stable until it is migrated), so its context-length detection does not silently break.
Acceptance criteria
- An empty-assistant short-circuit records that no upstream request occurred and includes its local reason.
- An adapted context-length rejection records that an upstream request occurred, preserves upstream status 400, and records
context_length_exceeded. - A normal successful upstream request records that upstream execution occurred and retains its existing status and token accounting.
- A genuine upstream
content_filterresponse remains distinguishable from Gym's local short-circuit. - Existing records without the new metadata continue to parse, with execution outcome treated as unknown.
- The new metadata survives capture-to-trajectory projection and JSON round trips.
- Tests cover all cases above without depending on synthetic response IDs.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(vllm): propagate provider HTTP errors
fix(model): preserve upstream execution outcomes (NVIDIA-NeMo#3761)