Conversation
…ck delivery
stop_typing() cancelled the typing loop and then awaited it with no bound.
Cancellation is only delivered at the loop's next await; if that await is a
/channels/{id}/typing POST that ignores cancellation until the request
completes (the NousResearch#64874 failure mode), stop_typing blocks for the transport
timeout and holds up message delivery.
Reap the cancelled task with a bounded timeout and detach if it does not
finish promptly, mirroring base._stop_typing_refresh. Adds a regression
test that emulates a cancellation-immune transport and asserts stop_typing
detaches within the reap bound.
Closed
1 task
Contributor
PR: fix(discord): bound stop_typing reap so a stuck typing loop can't block delivery Clean fix with a good regression test. Observations:
|
1 task
This was referenced Aug 29, 2026
Closed
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
Bounds
DiscordAdapter.stop_typing()so a stuck typing loop can never block message delivery. This closes member #3 of the Discord typing race family tracked in #85427 (design issue).Root cause
stop_typing()cancelled the typing loop and then awaited it with no bound:Cancellation is only delivered at the loop's next await point. If that await is a
/channels/{id}/typingPOST that ignores cancellation until the request completes (the failure mode described in #64874 — a stuck request that only clears at the ~30s transport timeout),stop_typingblocks for the whole timeout, holding up response delivery after the turn has already finished.Fix
Reap the cancelled task with a bounded timeout and detach if it does not finish promptly, mirroring the existing
base._stop_typing_refreshpattern (wait_for(shield(task), timeout=0.5)):_TYPING_STOP_REAP_TIMEOUT = 0.5(module constant, matchingbase._stop_typing_refresh).Test
tests/gateway/test_discord_typing_stop_nonblocking.pyemulates a cancellation-immune transport (a request coroutine that swallowsCancelledErroruntil released) and assertsstop_typingdetaches within the reap bound.The test uses
asyncio.wait(notwait_for) deliberately: wrappingstop_typinginwait_forwould itself deadlock on the buggy code, becausestop_typing's unboundedawait taskis stuck on the cancellation-immune loop and cannot be cancelled cleanly either.AssertionError: stop_typing blocked on the cancellation-immune loop…Relationship to the rest of the race family (#85427)
finallypopped the registry entry unconditionallyawait request(route)has no timeoutstop_typingblocks deliveryawait task_keep_typingno-op calls for DiscordThis PR is independent and non-conflicting with #85425 (different lines:
stop_typingvs the loop'sfinally) and complements #64910 (which bounds the request; this bounds the reap). Together they close the whole class short of the single-ownership refactor proposed in #85427.