Repository navigation
Order superseding event cancellation by root generation - #7168
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
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
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 780f54ded0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
6adc4c9 to
789f8ae
Compare
Superseding handlers previously only cancelled prior invocations when enqueued as chain roots, so two different chains yielding the same superseding handler left the stale invocation running (#7041). Give each root enqueue a monotonic generation stamp that chained events inherit, and apply supersession on every enqueue as a generation comparison: a newer chain's invocation cancels all live invocations from older chains, invocations within one chain (self-chains and sibling fan-out from one parent) coexist, and a stale chain enqueuing the handler after a newer chain already has is dropped at enqueue instead of cancelling the newer work. Fixes #7041
789f8ae to
3bf5ff5
Compare
An invocation late-chained to a completed parent is not attached to the parent's cancellation tree, but it still inherited the covered flag and skipped supersession registration, so a newer generation could never cancel it. Inherit coverage only from a still-running parent, so a late-chained invocation registers itself in the slot. Also qualify the supersedes docstring: stale enqueues are dropped while the newer chain's invocations are still tracked.
masenf
left a comment
There was a problem hiding this comment.
minor issue where an rx.call_script callback fires after some delay, which could end up cancelling later scheduled work with stale results. not going to block on that though, it seems like it would be complex and difficult to track the generation number for a frontend-executing event like call_script
All Submissions:
Type of change
Changes To Core Features:
Closes #7041.
Superseding handlers only cancelled prior invocations when enqueued as chain roots, so two different chains yielding the same superseding handler left the stale invocation running alongside the newer one.
This is a standalone alternative to #7162: instead of applying enqueue-order supersession to child events with an ancestor-walk exception, it orders supersession by root generation.
The model: each root enqueue receives a monotonic stamp (
EventFuture.root_gen); chained events inherit their parent's stamp._supersededtracks the live invocations of the newest generation per(event name, token), and_supersede_previousbecomes a three-way comparison:return [refresh("x"), refresh("y")]) runs all siblings.This encodes "newest user action wins" in the data model: no O(depth) ancestor walk (an O(1) integer compare instead), no special case for self-chains, and the stale-late-enqueue inversion becomes impossible rather than a documented caveat.
Included:
main: a shared superseding child cancelled across distinct root chains, and a stale chain's late enqueue being dropped without cancelling newer work.reflex-basechangelog fragment and docstring updates for the new semantics.Validation:
tests/units/reflex_base+tests/units/test_state.py.main's event processor.ruff format, and pyright clean on the changed files.Known trade-off: stale-drop protection lasts while the newer chain is still tracked; after its supersession slot is pruned, a very late stale enqueue runs as fresh work. Remembering the max generation per key forever would grow unboundedly, and pruning still strictly improves on enqueue-order semantics, where the stale enqueue cancels the newer work.