Skip to content

feat: forward rollout session IDs to Dynamo - #3856

Open
jthomson04 wants to merge 7 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/dynamo-session-id-forwarding
Open

jthomson04 wants to merge 7 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/dynamo-session-id-forwarding

Conversation

@jthomson04

@jthomson04 jthomson04 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Forward stable rollout session IDs to Dynamo for NeMo-Gym and direct NeMo-RL rollouts.

  • NeMo-Gym rollouts:
    • For the Dynamo backend, setup_nemo_gym_config enables Gym's forward_session_id_as_conversation_id (feat(vllm-model): forward gym session id as backend conversation id Gym#3582) on policy_model's vllm_model.
    • Gym then sends its session ID as conversation_params.conversation_id.
    • The Dynamo token wrapper removes conversation_params from the request body, because Dynamo's frontend rejects it as an unsupported field, and sends the ID as X-Dynamo-Session-ID.
  • Direct rollouts: each trajectory attempt gets one UUID, reused across its turns and HTTP retries. Sibling trajectories and complete-trajectory retries get different IDs.
  • Only Dynamo receives X-Dynamo-Session-ID. Other backends and Dynamo routing policy are unchanged.
  • Gym is pinned to NVIDIA-NeMo/Gym@75bb53e6d494437d616019040f22a9df7dcacd26 (Gym main, includes feat(sc): add ready-first staleness sampler #3582), and uv.lock is relocked.

This PR is transport-only. Session affinity stays opt-in through the existing frontend_args.extra_cli_args escape hatch. It does not add an affinity default, tracing controls, or a new routing policy.

Gym's session ID follows the model server's session cookie:

  • Agents that carry that cookie across turns (for example simple_agent) send one ID per rollout.
  • Agents that drop cookies (for example verifiers_agent, tau2) get a new ID on every model call, so session affinity doesn't apply to them.

Issues

None.

Usage

No user configuration is required for session forwarding. Dynamo-backed Gym and direct rollouts send the session header automatically. Users who want session affinity can configure the existing Dynamo frontend CLI escape hatch.

Before your PR is "Ready for review"

Pre checks:

  • Read and followed the contributor guidelines.
  • Added focused tests for:
    • Gym configuration;
    • wrapper forwarding (conversation_params becomes the header and is stripped from the forwarded body; malformed values return 400);
    • direct rollout identity;
    • Dynamo HTTP forwarding.
  • No documentation update is required because this does not add a user-facing option.

Additional Information

Validation:

  • Unit tests: 240 passed across the affected files: Dynamo token wrapper, generation and HTTP client; SWE Dynamo config; rollouts; rollout manager; and the NeMo-Gym env, utils and token capture tests.
  • Not run: tests marked vllm/sglang/nemo_gym that need GPUs, and functional/GPU tests.
  • Lint: pre-commit on all changed files passed, including ruff, ruff-format and pyrefly.
  • Lockfile: uv lock --check and uv sync --locked --group test pass. The Gym bump raises aiohttp to 3.14.5 (Gym requires >=3.14.4; the sglang fork keeps 3.14.3) and PyJWT to 2.15.1.
  • Gym pin: the new pin is a fast-forward from the current NeMo-RL Gym pin.

@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 6ef3f99 (PR #3856 from jthomson04/dynamo-session-id-forwarding)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@jthomson04
jthomson04 force-pushed the jthomson04/dynamo-session-id-forwarding branch from 6ef3f99 to 2af6e1b Compare August 26, 2026 23:52
@jthomson04 jthomson04 added the CI:L0 Run doctests and unit tests label Aug 26, 2026
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 2af6e1b

@jthomson04
jthomson04 marked this pull request as ready for review August 27, 2026 23:23
@jthomson04
jthomson04 requested review from a team as code owners August 27, 2026 23:23
@copy-pr-bot

copy-pr-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@jthomson04
jthomson04 force-pushed the jthomson04/dynamo-session-id-forwarding branch from 2af6e1b to 1760154 Compare September 8, 2026 17:07
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 1760154

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 1760154 (PR #3856 from jthomson04/dynamo-session-id-forwarding)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

jthomson04 and others added 3 commits October 12, 2026 09:05
Replace the unmerged Gym session_id_header fork with Gym main's
forward_session_id_as_conversation_id (NVIDIA-NeMo/Gym#3582).

- Pin Gym to 75bb53e6d494437d616019040f22a9df7dcacd26 and relock.
- For the Dynamo backend, setup_nemo_gym_config enables
  forward_session_id_as_conversation_id on policy_model's vllm_model.
- The Dynamo token wrapper reads conversation_params.conversation_id,
  sends it as X-Dynamo-Session-ID, and strips conversation_params from
  the forwarded body, which Dynamo's frontend rejects as unsupported.
- Malformed conversation_params return 400. The incoming
  X-Dynamo-Session-ID header is no longer read.
- Build the wrapper's FastAPI app in _build_app so the handler can be
  tested without binding a port.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jthomson04
jthomson04 force-pushed the jthomson04/dynamo-session-id-forwarding branch from 1760154 to fa45749 Compare October 12, 2026 17:07
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test fa45749

@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: fa45749 (PR #3856 from jthomson04/dynamo-session-id-forwarding)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

jthomson04 and others added 3 commits October 12, 2026 11:25
The setdefault chain raised AttributeError on a null policy_model, and in
a sharded job without a top-level policy_model it created an overlay no
shard claimed, which parse_shard_plan rejects. Route the overlay through
_gym_policy_model_overlay, which treats null levels as empty and uses
common_overrides when a sharded job has no top-level policy_model.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sibling PRs add other keys to the same vllm_model overlay and change the
wrapper's response metadata. Assert only forward_session_id_as_conversation_id
and the keys each test seeds, so those changes do not break these tests.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Describe how Gym and direct rollouts reach Dynamo with a session ID, and
how to opt into router session affinity through the frontend's
extra_cli_args.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test d244da0

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 12, 2026
jthomson04 added a commit to jthomson04/RL that referenced this pull request Oct 12, 2026
Move the shard-aware lookup of the Gym policy model's vllm_model overlay
into _gym_policy_model_overlay, byte-identical to the copy that NVIDIA-NeMo#3856 and
NVIDIA-NeMo#3763 add, so the three PRs merge onto one helper.
_enable_gym_prefix_derivation now only decides the flag.

The helper treats a null overlay level as empty and rejects a non-mapping
one with a ValueError. Before, an unsharded policy_model: null (or a null
nested level) failed with an AttributeError.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
jthomson04 added a commit to jthomson04/RL that referenced this pull request Oct 12, 2026
The dynamo case asserted that setup_nemo_gym_config leaves env.nemo_gym
untouched. The Dynamo setup in NVIDIA-NeMo#3856 and NVIDIA-NeMo#3763 writes its own policy model
overlay there, and NVIDIA-NeMo#3763 sets derive_prefix_token_ids_from_messages for
Dynamo too, so neither that assertion nor a narrower one on the flag would
survive those PRs. Pin only megatron, whose Gym overlay nothing touches.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: d244da0 (PR #3856 from jthomson04/dynamo-session-id-forwarding)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

test_run_single_rollout_preserves_native_media_across_turns builds
AsyncRolloutImpl without __init__, so it had no _policy_generation for the
Dynamo session-ID lookup, and its generate_response stub rejected the new
session_id keyword. Set a non-Dynamo generation and accept session_id, as
the sibling rollout test already does.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 0d4c7ae

@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 0d4c7ae (PR #3856 from jthomson04/dynamo-session-id-forwarding)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

jthomson04 added a commit to jthomson04/RL that referenced this pull request Oct 13, 2026
Move the shard-aware lookup of the Gym policy model's vllm_model overlay
into _gym_policy_model_overlay, byte-identical to the copy that NVIDIA-NeMo#3856 and
NVIDIA-NeMo#3763 add, so the three PRs merge onto one helper.
_enable_gym_prefix_derivation now only decides the flag.

The helper treats a null overlay level as empty and rejects a non-mapping
one with a ValueError. Before, an unsharded policy_model: null (or a null
nested level) failed with an AttributeError.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
jthomson04 added a commit to jthomson04/RL that referenced this pull request Oct 13, 2026
The dynamo case asserted that setup_nemo_gym_config leaves env.nemo_gym
untouched. The Dynamo setup in NVIDIA-NeMo#3856 and NVIDIA-NeMo#3763 writes its own policy model
overlay there, and NVIDIA-NeMo#3763 sets derive_prefix_token_ids_from_messages for
Dynamo too, so neither that assertion nor a narrower one on the flag would
survive those PRs. Pin only megatron, whose Gym overlay nothing touches.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@terrykong terrykong added CI:L1 Run doctests, unit tests, and functional tests and removed CI:L0 Run doctests and unit tests labels Nov 5, 2026
@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants