fix: record events in mjai_log for apply_event/observe_event (#184) - #187
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a viewer/debugging regression where MJAI events applied via the Python API (apply_event() / observe_event()) updated state but were not recorded into mjai_log, causing get_viewer() to show only constructor-emitted events.
Changes:
- Push applied/observed MJAI events into the underlying game state’s
mjai_log(and per-player logs) so the viewer can render full replays. - Clear constructor-emitted logs when a user replays from a new
start_gameevent. - Add regression tests covering
mjai_logaccumulation for both 4P and 3P, and for bothapply_event()andobserve_event().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
riichienv-python/src/env.rs |
Records applied/observed MJAI events into mjai_log and clears stale constructor logs on start_game. |
tests/env/test_apply_event_mjai_log.py |
Adds regression tests to ensure mjai_log is populated correctly for replay + viewer use. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
This PR fixes MJAI event logging for the Python RiichiEnv wrapper so that events applied via apply_event() / observe_event() are recorded into mjai_log, enabling get_viewer() to display replayed/custom logs correctly (regression for #184).
Changes:
- Add shared Rust-side helper logic to “parse → (optional start_game reset) → apply → push into mjai_log” for both
apply_event()andobserve_event(). - Add
parse_mjai_event()helper to avoid redundant JSON parsing. - Add Python regression tests covering mjai_log recording for both 4P and 3P, for both
apply_event()andobserve_event().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
riichienv-python/src/env.rs |
Refactors event parsing and ensures apply_event()/observe_event() push MJAI events into the core state’s mjai log (with start_game log reset behavior). |
tests/env/test_apply_event_mjai_log.py |
Adds regression tests asserting that events applied/observed are recorded into env.mjai_log in correct order and with expected fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Fixes #184
apply_event()andobserve_event()updated game state correctly but did not push events tomjai_log, causingget_viewer()to show only the constructor's initial events (typically juststart_game,start_kyoku,tsumo).