Skip to content

Support buffered SSE with external token staging - #3382

Merged
pthombre merged 3 commits into
mainfrom
pranav/external_capture_streaming
Sep 16, 2026
Merged

pthombre merged 3 commits into
mainfrom
pranav/external_capture_streaming

Conversation

@pthombre

@pthombre pthombre commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Capture-prefixed requests with stream: true returned HTTP 422 when external token staging was enabled. Allow Chat Completions, Responses, and Anthropic Messages clients to use Gym's existing buffered SSE replay with externally staged training tokens. The compaction Responses adapter is covered by the same integration tests.

Keep worker requests non-streaming after request overrides and reject conflicting static or per-request streaming overrides. Convert Responses output before fingerprinting so reasoning and tool-call continuations resolve the correct captured parent. Generation completes before SSE replay, so this provides protocol compatibility without reducing time to first content. Training reconstruction reads the staged tokens.

Add 27 route-level cases covering JSON/SSE requests, evaluation capture on/off, worker request enforcement, response IDs, internal-field stripping, token reconstruction, and two-call reasoning/tool continuations.

Validation

  • 826 relevant Gym tests passed, including all 27 new integration cases, the capture and streaming suites, and the vLLM and compaction adapter suites.
  • Real Qwen3-0.6B tool rollout through Gym HTTP, the NeMo-RL HTTP worker, vLLM, and TransferQueue passed (Slurm job 3747841): two committed calls, answer 4, reward 1.0, and reconstruction of 234 tokens including 27 training tokens with finite logprobs.
  • Full pre-commit run --all-files passed.
  • Fern check passed with zero errors and one warning.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated changes are excluded.
  • Relevant tests pass locally.
  • Full pre-commit checks pass locally.
  • The commit has DCO sign-off.

@copy-pr-bot

copy-pr-bot Bot commented Sep 14, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown
Contributor

@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test 0f4034e

@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test 6e52306

@yaoyu-33 yaoyu-33 added area:model Model servers, inference providers, and model adapters feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Sep 14, 2026
@pthombre

Copy link
Copy Markdown
Contributor Author

/claude review

@pthombre
pthombre requested a review from ananthsub September 14, 2026 23:42
@claude

claude Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

SHIP — LGTM, no reliability concerns.

Reviewed the buffered-SSE + external-staging relaxation with focus on lineage/fingerprint correctness (the part that would silently corrupt training data):

  • Fingerprint consistency across dialects is sound. The served response (postprocess_chat_response) and the new response-items conversion (chat_completions_messages_to_responses_items) both funnel through postprocess_assistant_message_dict, so the fingerprint stored for a captured call matches what the agent receives and re-sends on the next turn. _invoke_responses sets response_dialect="responses" and messages()/compaction route through it; chat/completions keeps the default and needs no conversion. Verified by the two-call continuation test across all four dialects (parent staging_chain/model_call_id match, linearized token_ids/token_mask/logprobs correct).
  • Backend streaming is correctly force-disabled at both config validation (model_post_init) and per-request (_apply_external_capture sets stream=False, drops stream_options), while the client still gets a synthesized SSE replay. A runtime metadata override that re-injects stream=True on a captured call fails safely to response.failed + a ledger poison row (backend never called) rather than capturing mismatched tokens — covered by test_runtime_override_is_scoped_to_captured_calls.
  • No fail-the-call regressions. The dialect conversion at vllm_model/app.py:1140 is inside the try/except that poisons capture without turning a valid completion into a harness error; token transport fields are stripped in the finally before SSE replay.
  • Removed _reject_external_capture_streaming / HTTPException import have no dangling references, and no existing test asserted the old 422 behavior. Docs match the code.

Relaxing streaming from 422→buffered-SSE is an additive change, not a public-API break.

@yaoyu-33 yaoyu-33 added the complexity:medium Single-domain change with interacting parts or a moderate review surface label Sep 15, 2026

@ananthsub ananthsub left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should merge #3301 first and then rebase these changes

Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread nemo_gym/base_responses_api_model.py Resolved
Allow captured streaming requests to use the existing buffered SSE routes
while enforcing non-streaming inference worker requests after overrides.
Fingerprint converted Responses items so reasoning and tool-call
continuations resolve their staged parent correctly.

Add 27 route-level integration cases and document the supported behavior.

Signed-off-by: Pranav Thombre <[email protected]>
Extend #3301's finalization boundary to buffered SSE and the compaction
adapter. Serialize the client-visible response before committing capture,
and persist uncommitted-call failures before releasing terminal events.

Restore namespaced tool output before finalization and preserve namespace
identity in version 2 fingerprints. Add refusal, conversion, serialization,
content-attribution, and failure-durability regressions.

Validation: 1,084 Gym tests and 32 NeMo-RL boundary tests pass. A live Qwen3
rollout through the NeMo-RL worker, vLLM, and TransferQueue returns reward
1.0, reconstructs 238 tokens, and attributes the terminal call by content
(Slurm job 3772908). Full pre-commit passes; Fern reports zero errors and
an unauthenticated redirect-check warning.

Signed-off-by: Pranav Thombre <[email protected]>
@pthombre
pthombre force-pushed the pranav/external_capture_streaming branch from 6e52306 to d5bc7dc Compare September 16, 2026 01:45
@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test d5bc7dc

@github-actions github-actions Bot added the sla:author-overdue Author response is over the one-business-day SLA label Sep 16, 2026
@pthombre
pthombre requested a review from ananthsub September 16, 2026 20:35
@github-actions github-actions Bot removed the sla:author-overdue Author response is over the one-business-day SLA label Sep 16, 2026
Emit and reconstruct Chat refusal deltas so clients receive the output whose tokens are staged. Require the current fingerprint version when resolving file-backed ledger parents.

Add refusal continuation and mixed-version ledger regressions. Validation: 1,172 relevant tests and full pre-commit checks pass.

Signed-off-by: Pranav Thombre <[email protected]>
@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test a4402f8

@ananthsub
ananthsub enabled auto-merge September 16, 2026 22:27
@ananthsub
ananthsub added this pull request to the merge queue Sep 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 16, 2026
@pthombre
pthombre added this pull request to the merge queue Sep 16, 2026
Merged via the queue into main with commit 1c2dcc7 Sep 16, 2026
56 of 58 checks passed
@pthombre
pthombre deleted the pranav/external_capture_streaming branch September 16, 2026 23:46
lauradang added a commit to lauradang/Gym that referenced this pull request Sep 17, 2026
Resolve the vLLM model conflict with NVIDIA-NeMo#3382 (buffered SSE with external
token staging) by porting its stream guards into the capture handler
path and adapting the new streaming test to wrap the handler's
finalize_response.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Laura Dang <[email protected]>
ertkonuk pushed a commit that referenced this pull request Oct 2, 2026
…tion, not content

conversation_digest hashed every request item including the harness's
system prompt. OpenCode regenerates that prompt per request with today's
date, so the first model call after 00:00 UTC in any running session no
longer matched its parent's recorded context: resolve_node returned
UNRESOLVED (no_match), the call was poisoned, and the finalizer rejected
the whole rollout. In a run whose step spanned 2026-09-24 00:00 UTC, 453 of
512 rollouts (every rollout that made calls on both sides of midnight)
became placeholder rows; the healthy rollouts were exactly those that ran
entirely before or entirely after midnight.

system/developer items now contribute only their role and position to the
digest. User, assistant and tool turns are hashed as before, so a
summarized or rewritten conversation still fails verification. Reusing the
parent's tokens then serves the instruction text the model actually saw,
which is what the training rows need. FINGERPRINT_VERSION bumps to 2.

[tkonuk: FINGERPRINT_VERSION 3 here, since #3382 already bumps it to 2]
Signed-off-by: Tugrul Konuk <[email protected]>

This branch was previously deployed

1 inactive deployment
public — a4402f8b Deployed Sep 16, 2026 by copy-pr-bot[bot] via release / finalize / notify #3090
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model servers, inference providers, and model adapters complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants