Repository navigation
fix: piggyback same-payload duplicate in-flight requests instead of 409 - #332
Merged
Merged
Conversation
After a gateway restart or idle-reclaim, a client's reconnect burst can re-fire a request whose JSON-RPC id collides with itself while the first copy is still outstanding. Since the payload is identical, treat it as a retry: attach it to the in-flight request's pending slot and return the same backend reply, instead of rejecting it with 409 (which surfaced to users as "tools fetch failed" on the first reconnect after every restart). A genuinely different payload under the same id is still rejected, since it cannot be correlated. Closes #331
Address code-review findings on the piggyback change: - Retire the shared pending slot from its LAST waiter (refcount) instead of the registering caller: an owner whose own timeout expires no longer orphans a still-waiting piggybacked retry (whose late reply leaked to SSE and which _fail_all could no longer wake, while has_pending read False and let the idle reaper reap the session mid-wait). - Read slot["line"] under the lock on the way out, so a reply landing at a waiter's timeout boundary is still honored instead of diverging into a 504 for one caller and 200 for the other. - Match retries semantically (parsed JSON equality, byte-equality fast path) so a client library that re-serializes with a different key order on retry still piggybacks instead of getting 409. - Document the residual sequential window (a retry landing just after completion is indistinguishable from legitimate sequential id reuse and is dispatched anew) and the per-waiter deadline semantics in the docstring and en/ja operator guides. - Tests: replace the flake-prone wall-clock assertion with a slow_echo dispatch counter (calls) proving exactly one copy reached the backend; poll for in-flight registration instead of a fixed sleep in the HTTP test; add owner-timeout-survival and re-serialized-retry tests; extract the _wait_in_flight helper shared by the spin-wait blocks.
shigechika
force-pushed
the
fix/idempotent-duplicate-in-flight-id
branch
from
July 24, 2026 08:00
5049949 to
d81658d
Compare
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
send_requestnow compares the incoming payload against the one already in flight under that id: an identical payload is piggybacked onto the existing pending slot (both callers observe the same backend reply,200), a genuinely different payload still raises_DuplicateInFlightId(409) since it cannot be correlated.Test plan
pytestfull suite: 1239 passed, 3 skippedtest_duplicate_in_flight_id_same_payload_piggybacks: two concurrent same-id/same-payloadsend_requestcalls against a slow (0.3s) backend return the identical reply and complete in ~0.3s total (proving only one dispatch reached the backend, not two serial ones)test_duplicate_in_flight_id_same_payload_returns_200_over_http: same scenario through the actual gateway HTTP handler, asserts200/200with identical JSON bodiestest_duplicate_in_flight_id_rejectedupdated to clarify it covers the DIFFERENT-payload case; still passes unchangedruff checkclean on all changed filesdocs/guides/serve.md/serve.ja.mdoperator notes to describe the new same-payload-retry behaviorCloses #331
🤖 Generated with Claude Code
https://claude.ai/code/session_01YD76oeDYARdjhLQf93nkug