Repository navigation
Deliver typed session events to the Python callback - #5
Merged
Merged
Conversation
The session reported events as (name: str, payload) tuples, so every embedder dispatches on raw strings and unpacks payloads unchecked. The session now delivers a single typed SessionEvent (a PyO3 complex enum: StateChanged, ConnectionStatusChanged, CommandStatusChanged, JobFinished, ProbeStatusChanged, WcsUpdated, ConfigChanged, RawRx, RawTx); Python matches on the variant classes and reads typed attributes. The stubs expose final variant classes with __match_args__, so pyright can check the callback contract. This also fixes event routing for batches drained by a progress report: a drainer scheduled for a progress report delivered any session events in its batch to the progress callback. EventDrainer now carries both callbacks and routes by event kind. Breaking change: event_callback(event) replaces event_callback(name, payload) (bump to 0.5.0 when releasing).
knipknap
added a commit
to barebaric/rayforge
that referenced
this pull request
Oct 17, 2026
raydriver 0.5.0 delivers a typed SessionEvent to the driver's event callback instead of (name, payload) string tuples, so _on_session_event now matches on the event variants; each former branch became a small named handler. The callback is annotated as a union of the stub's variant classes with assert_never in the fall-through, so an event added on the Rust side fails the type check here until it is handled. Also regenerates pixi.lock (raydriver 0.3.0 -> 0.4.0) and syncs requirements.txt and debian/requirements-bundle.txt with the pixi.toml pin; both were left at 0.3.0. Requires the raydriver typed-events change (barebaric/raydriver#5); the pin and lockfile move to 0.5.0 once it is released.
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
The session reported events as
(name: str, payload)tuples, so every embedder had to dispatch on raw strings and unpack payloads unchecked. This PR replaces that contract with a single typed object:SessionEventis a PyO3 complex enum (StateChanged,ConnectionStatusChanged,CommandStatusChanged,JobFinished,ProbeStatusChanged,WcsUpdated,ConfigChanged,RawRx,RawTx);event_callback(event)receives it on the loop thread. Python matches on the variant classes and reads typed attributes (event.status,event.line,event.state, ...).@typing.finalvariant classes with__match_args__, so pyright can verify the callback contract andmatchdestructuring works.EventDrainernow carries both callbacks and routes by event kind.Breaking change
event_callback(event)replacesevent_callback(name, payload). Rayforge is the only known Python embedder and pins==; this lands as 0.5.0. The Rust-embedderSessionEventstrait is unchanged.Test plan
make lint(cargo fmt, clippy -D warnings, ruff, pyright) green; also fixes a pre-existingclone_on_copyclippy error intypes.rs.Rayforge-side migration (PR #576) follows once 0.5.0 is released.