Skip to content

Preserve upstream execution outcomes in model-call observability #2792

Closed

Description

@giuliolovisotto

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:

  1. 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 rejects sequential_reasoning_allowed=false outright.)
  2. When vLLM rejects a request with HTTP 400 whose error body mentions context length or max_tokens (typically an oversized context or requested token count), Gym returns a synthetic HTTP 200 response with finish_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 | None

New 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_exceeded when Gym adapts an excessive-context error into a synthetic length response — on both the chat-completions and completions-API paths.
  • Account for the Responses-dialect conversion, which remaps the synthetic finish_reason: "length" to incomplete_details.reason: "max_output_tokens" — capture-side classification must not key on the chat-dialect length label alone.
  • Propagate the execution metadata through:
    • raw model-call capture sidecars;
    • ModelCallRecord;
    • ng_model_call_capture;
    • TrajectoryModelCall and 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 existing chtcmpl-123 response-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_filter response 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.

Activity

  1. added a commit that references this issue on Sep 2, 2026
    be7764a
  2. added a commit that references this issue on Sep 30, 2026
    35454e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions