Prevent ambiguous retry replay - #2371
Open
xeophon wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 109e3e0. Configure here.
Contributor
ApprovabilityVerdict: Approved 690c2d1 Straightforward bug fix that adds safety checks to prevent serving cached responses for the wrong logical request when identical request bodies appear. Small, focused change with clear intent and limited scope. You can customize Macroscope's approvability policy. Learn more. |
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.

Summary
Root cause
The retry cache and in-flight map are keyed only by request-body digest. When two fresh byte-identical requests overlap, the second request replaces the first request's in-flight future. A marked retry of the first request can then coalesce onto the second request and receive its independently sampled response.
Impact
Normal completed and in-flight SDK retries retain the existing replay behavior. Once a body is reused by another logical request, the server no longer guesses which request a retry belongs to.
Verification
uv run pytest tests/: 914 passed, 75 skippedverifiers/legacy/envs/experimental/composable/tasksets/swe/README.mdNote
Prevent ambiguous retry replay in
InterceptionServerrequest handlerrequest_generations(a per-body-digest counter) toRolloutSessionto track how many distinct fresh requests share a given body digest.unambiguous_retryinInterceptionServer: a retry is unambiguous only when its body digest maps to exactly one fresh request.last_responseand coalescing with an in-flight request now requireunambiguous_retryinstead of justretried, preventing identical bodies across distinct fresh requests from incorrectly triggering replay or coalescing.Macroscope summarized 690c2d1.
Note
Medium Risk
Changes graph-atomicity behavior on the model interception path for overlapping identical bodies; normal single-request SDK retries are unchanged, but ambiguous cases now re-sample instead of replaying.
Overview
Fixes incorrect retry replay and in-flight coalescing when the same request-body digest is used by more than one logical model call (e.g. overlapping byte-identical requests or compaction regenerating the same body).
RolloutSessionnow tracksrequest_generations: how many fresh (non-retry) requests have been seen per body digest. On each intercept, fresh requests increment that count; marked SDK retries seed generation 1 when the original never reached the handler.Replay and in-flight coalescing require
unambiguous_retry—a marked retry whose digest still maps to exactly one logical request—instead of anyretriedrequest. Ambiguous retries sample independently so they cannot attach to another request’s completion or fork the graph.Reviewed by Cursor Bugbot for commit 690c2d1. Bugbot is set up for automated code reviews on this repo. Configure here.