Repository navigation
fix(token-capture): preserve safe continuations after system updates - #5138
Conversation
e927785 to
439d37b
Compare
|
Pushed Refreshed onto main's shared chat-rendering implementation. The prefix proof runs before any captured-prefix fetch, preserves the full prompt on a mismatch, and retains checkpoint generation-cut metadata. Automatic system-suffix opt-in remains limited to native vLLM staging; no additional harness contract or dependency changes are added. Validation: 65 CPU tests passed (one installed-vLLM-specific test deselected), the focused capture-context typecheck passed, and scoped pre-commit checks passed. All nine new system-suffix cases ran, including checkpoint-cut preservation and both shared-render-only and native preprocessing paths. No fresh live-model or learner qualification is claimed. Do not merge until RL main's Gym pin includes Gym #5771 (merge commit |
hemildesai
left a comment
There was a problem hiding this comment.
Thanks, the change looks correct to me. When a candidate has a system suffix, it reuses captured tokens only if the full render starts with the separately rendered history. In every other case it roots a new segment. Moving resolve_capture_input after the history render is the right order, and the Dynamo path picks up the same check through _render_chat_call. A rooted candidate with a generation_cut still never splices, because prepare_prompt splices only for token_in or an explicit required_prefix_token_ids.
I'm not approving yet, for two reasons:
- Merge order (inline): this PR breaks forest training on the current Gym pin, so the pin bump has to land first or in this PR.
- CI: only the lint and metadata checks have run on 439d37b so far, not the unit or functional tests.
Non-blocking: please extend test_spinup_passes_parent_resolution_to_gym in tests/unit/environments/test_nemo_gym_utils.py. It should assert that allow_system_suffix is True for forest training plus vllm, and that it is absent for non-forest training and for the Dynamo backend. Then the gate wiring in nemo_gym.py has a test, and it validates against the real Gym config once the pin moves.
terrykong
left a comment
There was a problem hiding this comment.
First: this PR conflicts with main in docs/guides/context-compaction.md, because main's #5047 changed the same line. Please rebase on main; C3's suggestion already uses main's wording.
Thanks for this. The check is small and in the right place: it runs in _render_chat_call, which both native vLLM and Dynamo use, and when the rendered prefix changes it falls back to a new root, so a system message that the template moves to the top can no longer be dropped. The team checked it against Gym #5771's contract and against real Qwen3 templates, and found no case where it reuses tokens it should not.
Asks:
- (C1) Blocking: rebase onto main once a Gym bump with #5771 lands (today #5432). At the current pin an existing nemo_gym unit test fails, and forest-training runs on vLLM fail at Gym startup.
- (C2) Add a test that checks when
allow_system_suffixis set. - (C3) Fix the last sentence of the context-compaction guide.
- (C4) For every captured call (forest and non-forest), when a system message follows the last answer, check where the template puts it, and reject the call with a 400
system_message_reorderedif the template moves or drops it. In non-forest mode this is an older bug, not added by this PR, that we ask you to fix here. - (C5) Reword the new-segment warning for the case left after C4, and add a line to the context-compaction guide that such calls are rejected.
C1 and C2 turn the two points from the earlier review on this PR into threads that can be resolved.
FYI, no action: some templates render the last assistant turn differently once something follows it (Qwen3 with empty reasoning adds an empty think block only when the assistant turn is last). There the check sees a different prefix and starts a new root. That is safe, and no worse than before this PR.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5138-system-suffix-check.html
Generated by Claude Code
439d37b to
8770e7a
Compare
Signed-off-by: Ali Roshan Ghias <[email protected]>
Signed-off-by: Ali Roshan Ghias <[email protected]>
Signed-off-by: Ali Roshan Ghias <[email protected]>
8770e7a to
8423d41
Compare
|
/ok to test 8423d41 |
What and why
Claude Code can append system messages, such as token-budget updates, after an assistant response. A chat template may move or drop those instructions, and replacing its historical tokens with a captured prefix can silently change the model's context.
The shared native-vLLM/Dynamo chat-rendering path verifies late system instructions before reading a captured prefix or starting capture. It reuses the captured prefix only when the full render begins with the historical render. Benign history-rendering differences start a new segment with the complete prompt, preserving generation-cut metadata. A marker probe rejects dropped/reordered instructions or uninspectable prompt text with HTTP 400 and
system_message_reordered, in both candidate and ordinary token-in capture.Enable Gym's default-off
allow_system_suffixgate only for native-vLLM forest capture; keep it disabled for Dynamo and non-forest configurations. The marker render is limited to captured calls with late system messages. It checks marker preservation/order relative to the preceding user/tool message, not arbitrary content-dependent template behavior.Issues
Related: Gym #5771 and the Claude Code subagent example #5113.
Convergence / perf / functionality proof
Rebased onto main after #5432. All three commits are patch-identical to the previously qualified range; dependency pins, lockfiles, and submodules are unchanged relative to main.
On refreshed head
8423d417awith pinned Gym91666f9, 292 focused CPU tests plus the new two-turn Messages capture integration test passed (1 installed-vLLM-specific test deselected). The current subagent recipe also passes schema/SingleController configuration validation. These refresh checks ran in the prepared environment; the container/source fingerprint warning was retained. They do not repeat the earlier GPU qualification below.Earlier GPU qualification on
8770e7ab7:Needs upstream changes
None. #5432 merged the Gym revision containing #5771. This PR adds no dependency or lockfile update.