Conversation
…shes register_wait() lets a newer waiter replace the registry entry of the same session_id, but the older waiter's _cleanup() popped the entry unconditionally. When the older waiter finished, timed out or was cancelled, the newer waiter disappeared from USER_SESSIONS while its future kept waiting, so trigger() could no longer reach it and it could only time out. Only remove the registry entry if it still points at the waiter being cleaned up. Fixes AstrBotDevs#9996
kilisamemarisaaa
approved these changes
Sep 15, 2026
kilisamemarisaaa
left a comment
There was a problem hiding this comment.
Reviewed the latest head and the registry race fix is correct.
egister_wait() can replace USER_SESSIONS[session_id], while the older waiter's cleanup previously removed the newer entry unconditionally; the identity guard now preserves the active waiter and still cleans up the single-waiter case. The added tests exercise replacement cleanup, trigger reachability/handler controller identity, and normal cleanup, with fixture isolation for USER_SESSIONS and FILTERS. I found no remaining correctness blockers.
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.
Motivation / 动机
Fixes #9996.
register_wait()can replace theUSER_SESSIONSentry of asession_idwith a newerSessionWaiter, but the older waiter's_cleanup()always ranUSER_SESSIONS.pop(self.session_id, None). So when waiter A finished, timed out or was cancelled after waiter B had registered for the same session, B's entry was removed while B's future was still pending:trigger()could not find B any more and B could only time out. This happens whenever the same user starts an interactive flow twice.Modifications / 改动点
SessionWaiter._cleanup()only removes the registry entry if it still points at the waiter being cleaned up (USER_SESSIONS.get(self.session_id) is self). Removing the filter and stopping the controller are unchanged.tests/test_session_waiter.py: registering A then B for the same session, stopping A keeps B registered and reachable (trigger()runs B's handler with B's controller), and B still cleans up after itself; plus the plain single-waiter cleanup case. The first test fails onmasterand passes with the fix.Verification / 验证
Checklist / 检查清单
Summary by Sourcery
Prevent stale session waiters from removing newer registrations and leaving interactive flows unreachable.
Bug Fixes:
Tests: