[core] feat: support rollback for rewritten last assistant messages - #88
Merged
yyDing1 merged 2 commits intoJul 23, 2026
Merged
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Collaborator
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR makes Gateway sessions reuse an existing chain when a client rewrites
only that chain's latest Assistant message.
The Gateway records the token/message/media boundary immediately before each
Assistant turn. When the next request preserves the earlier prefix but replaces
that Assistant turn, it rolls the chain back to the recorded boundary,
re-encodes the replacement suffix, and continues generation on the same chain.
This avoids materializing a redundant trajectory while preserving token IDs,
response masks, rollout log probabilities, and multimodal inputs.
Last-Assistant rollback is enabled by default. Set
actor_rollout_ref.rollout.custom.agent_framework.enable_last_assistant_rollback=falseto retain the previous split-on-rewrite behavior.
Checklist Before Starting
[{modules}] {type}: {description}(checked by CI)Test
Automated validation on
upstream/mainatecdddea(#87):All hooks pass for files changed by this PR:
pre-commit run --all-filesadditionally reformatsexamples/blackbox_recipes/sandbox_client.py, an unchanged file introduced by#87. That unrelated baseline formatting change is intentionally excluded from
this focused PR.
CC rollout experiment
Full rollout configuration:
Results:
max_response_lengthmaterializationsAll 50 trajectory records satisfied:
The full 8x4 run was collected on the #83-rebased rollback implementation.
After rebasing onto #85/#87, the rollback implementation in
session.pyisbyte-for-byte identical except that the feature default changes from
falsetotruein this PR.A fresh #87 smoke run used
MAX_SAMPLES=2,N=1, and the same model/tokenbudgets. It completed 2/2 sessions, produced three trajectories (one
max_response_lengthmaterialization), and all response ID/mask/log-probabilityarrays remained aligned.
The CC recipe currently needs a separate post-#83 reward-wiring compatibility
fix. That fix was applied only in the local rollout workspace and is not part of
this PR.
Observed task-level warnings included agents reaching the configured 100-turn
limit, one malformed Tool-call parse, and one 143,813-token prompt exceeding the
140,288-token model context. These were not rollback or token-alignment failures;
the full experiment still finalized all 32 sessions.
API and Usage Example
Rollback is enabled when the option is omitted:
To preserve the previous behavior and split a rewritten latest Assistant into a
new chain:
Design & Code Changes
LastAssistantStartboundary before every Assistantgeneration, including response IDs, response masks, log probabilities,
message-history length, media lengths, and the prefix hash.
exact continuation on ties and refusing ambiguous deepest rollback matches.
re-encode only the incoming replacement suffix.
truth is already inconsistent.
rollback_countandrollback_dropped_trainable_tokens_totalin the session snapshot.session. The default is
true; explicitfalseremains supported.re-encoding, response-budget materialization, log-probability alignment, and
explicit opt-out behavior.
This PR intentionally does not include the independent CC reward compatibility
fix or rollout snapshot logging used to collect the experiment metrics.
Checklist Before Submitting
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always