Repository navigation
Fix superseding shared child events - #7162
harsh21234i wants to merge 5 commits into
Conversation
60a1a64 to
d47f94f
Compare
|
| @@ -0,0 +1 @@ | |||
| Ensure superseding event handlers shared by distinct event chains cancel stale child invocations. | |||
There was a problem hiding this comment.
Changelog has trailing whitespace
The added changelog line ends with trailing whitespace, which causes git diff --check to fail. Remove the trailing carriage-return or whitespace character so standard Git whitespace validation passes.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
FarhanAliRaza
left a comment
There was a problem hiding this comment.
Reviewed by exercising this branch in a real app (two roots returning a shared @rx.event(background=True, supersedes=True) child, a root-supersession pair, a self-chaining superseding poll loop, and a same-batch sibling yield), driven headless in Chromium, plus a static pass.
Verdict: LGTM — the fix does what it claims, with only minor non-blocking notes (inline).
Verified live on this branch:
- The #7041 repro is fixed: clicking Event A then Event B while the shared child sleeps yields
do_stuff(a) started → do_stuff(b) started → do_stuff(b) finished, with the staleainvocation cancelled mid-sleep. No console errors. - Root-level supersession is unchanged (two rapid clicks of the same superseding root → only the second finishes).
- The
_is_future_ancestorguard works: a self-chaining superseding handler runs its full chain to completion. - Plain (non-superseding) events unaffected.
Test/static evidence:
- The new regression test fails on
main'sevent_processor.pyand passes with the fix — and themainfailure mode also shows the old code leaked the_supersededtracking entry, which this change cleans up. - Full
tests/units/reflex_basesuite passes (443 passed, 1 skipped); pyright and ruff clean on the changed files; the touched functions stay under the C901 complexity threshold. - No component changes, so no
pyi_hashes.jsonupdate needed; backend-only, no prod-build impact.
Inline comments: one suggested test to pin the (apparently intended) new sibling-yield cancellation semantics, one docstring suggestion for a latest-enqueue-wins edge case, and a news-fragment naming nit.
Generated by Claude Code
| key = (event.name, token) | ||
| previous = self._superseded.get(key) | ||
| if previous is not None and not previous.all_done(): | ||
| is_ancestor = previous is not None and _is_future_ancestor(previous, tracked) | ||
| if previous is not None and not is_ancestor and not previous.all_done(): |
There was a problem hiding this comment.
Untested behavior change worth pinning with a unit test: because the supersession key is (event.name, token) and ignores args, a handler that yields the same superseding handler twice in one batch — e.g. return [State.do_other("x"), State.do_other("y")] — now has y cancel x before it even starts (verified in a live app on this branch; previously both ran, since chained enqueues never superseded). The siblings share a parent, so the ancestor check doesn't protect them.
This is consistent with latest-wins and with how roots already behave, so it looks intended — but it's downstream-visible beyond the #7041 scenario and no test covers it. Suggest adding a test asserting only the last sibling runs, so the semantics are locked in deliberately.
Generated by Claude Code
|
|
||
| When True, enqueuing this handler cancels the previous unfinished | ||
| invocation chain for the same handler and client token. This also | ||
| applies when the handler is yielded by multiple distinct roots. |
There was a problem hiding this comment.
Edge case that might deserve a sentence here: cancellation is latest-enqueue-wins, not latest-user-action-wins. Roots with different names don't supersede each other, so if the older root chain is still running and enqueues the shared superseding child after the newer chain already did, the stale chain's invocation cancels the newer one. Unlikely in practice (children are usually enqueued promptly), and inherent to the (event.name, token) key design — just worth documenting so the semantics aren't surprising.
Generated by Claude Code
There was a problem hiding this comment.
Nit: the +slug form is for before the PR number is known — this can be renamed to 7162.bugfix.md now.
Generated by Claude Code
|
Hi @FarhanAliRaza , I’ve addressed the review feedback on PR #7162 and pushed the latest changes. The final commit is |
|
superceded by this #7168 |
Fixes #7041.
When two different superseding root events enqueue the same superseding child event, the second child event did not cancel the first because supersession was only applied to root-level enqueues. This could allow stale background work to continue running alongside the newer event.
This change applies the existing supersession-key logic to chained events while preserving existing behavior for non-superseding handlers.
Included:
Regression test covering distinct root chains sharing a superseding child event.
Documentation update for chained-event supersession behavior.
reflex-basechangelog fragment.Validation:
45 event processor tests passed.
Changed-file pre-commit checks passed, including Ruff, codespell, pyright, ty, and the pyi hook.