fix(gateway): follow async delegation completions across compression - #69312
Merged
Conversation
…mpletions Adapter acceptance is not proof of delivery: the inner #55578 resolver can still fail closed inside the message pipeline after the adapter accepted the synthetic event, which falsely acknowledged the durable row as delivered and silently discarded the delegation result. Pre-flight the delivery target in _deliver_completion_notification before adapter acceptance (adapted from #65838 by @henrynguyeninfo1): - live parent or verified live compression tip -> deliver (inner resolver still owns the actual route retarget) - explicit-reset / unknown parent -> terminal 'dropped' disposition via new drop_completion_delivery() (not falsely 'delivered', not eternally 'pending') - transient uncertainty (DB error, mid-flight rotation without a visible continuation) -> release the claim for retry release_completion_delivery() now converges to a terminal 'dropped' state once _MAX_DELIVERY_ATTEMPTS is exhausted, so an undeliverable completion cannot replay on every gateway restart forever.
Contributor
૮ >ﻌ< ა ci reviewrunning on dc2342b CI timingsCI timings · View jobWall time 8m27s vs 7m46s (+8.8%). 5 job(s) slower, 13 faster, 2 unchanged.
|
Collaborator
Related to open #64530 and #55578. This current diff contains the same compression-tip/CAS routing repair as #64530 but also adds target classification and durable terminal/retry handling; it is broader competing work rather than a redundant same-policy patch. |
Contributor
|
Big thank you for preserving the credit and improving the original fix instead of replacing it. <3 I'm officially a contributor. Feels good to help something that you use every day! |
This was referenced Jul 22, 2026
19 tasks
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
Async delegation completions now reach the user after a context-compression rotation instead of being silently dropped, and undeliverable completions get an honest durable disposition instead of being falsely marked delivered. Root cause: the #55578 fail-closed pinning guard treated a compression-ended parent session like an explicitly-ended one (dropping the completion without consulting
end_reason/get_compression_tip), while_deliver_completion_notificationacknowledged the durable row as delivered on mere adapter acceptance — so drops inside the pipeline were unrecoverable.Changes
gateway/run.py: new_resolve_async_delegation_session()— resolves a pinned parent to its verified live compression tip (live → keep pin; compression-ended → followSessionDB.get_compression_tipto a verified live continuation; anything else fails closed), with a lineage-ownership check so a late completion can never override an unrelated/newor restored route; also covers the pinned==current stale-route bypass.gateway/session.py: newSessionStore.advance_compression_session()— CAS route-advance along an already-verified compression lineage; deliberately NOTswitch_session, whose end/reopen side effects are wrong for a compression heal.gateway/run.py: pre-flight_classify_completion_target()in_deliver_completion_notification— deliver / terminal / retry verdict before adapter acceptance, so the durable ack stays honest.tools/async_delegation.py: newdrop_completion_delivery()terminal disposition for permanently-gone targets (explicit/new-reset boundaries);release_completion_delivery()now converges to a terminaldroppedstate after_MAX_DELIVERY_ATTEMPTS(8) so an undeliverable row can't replay on every gateway restart forever.test_async_delegation_session_binding.py), 3 CAS route-advance tests (test_session_store_runtime_stale_guard.py), 4 ack-semantics tests incl. attempt-cap churn (test_completion_delivery.py).Validation
ended_at)deliveredon adapter acceptancedropped(explicit reset) orpendingretry with attempt capdroppedafter 8 attemptsTargeted tests:
tests/gateway/ -k 'delegation or completion or compression'→ 160 passed, 0 failed; async-delegation consumer suites (12 files) → 921 passed, 0 failed.Credit
Salvaged from #64530 by @richkapp (first submitter). Ack-semantics hardening adapted from #65838 by @henrynguyeninfo1. Root-cause diagnosis credit: @allenkaplan (#65779, #65780). Also fixes the same bug reported in #65820 by @heyparth1. Fixes #65779.
Infographic