Skip to content

fix(state): ensure change listeners are triggered in modification order#83

Merged
jourdain merged 2 commits intoKitware:masterfrom
Thibault-Pelletier:fix-change-listener-order
May 7, 2026
Merged

fix(state): ensure change listeners are triggered in modification order#83
jourdain merged 2 commits intoKitware:masterfrom
Thibault-Pelletier:fix-change-listener-order

Conversation

@Thibault-Pelletier
Copy link
Copy Markdown
Contributor

Update StateChangeHandler and _SuppressListenersChangeStack to use an ordered set instead of a set to ensure listeners are triggered in the same order when flushed

@jourdain
Copy link
Copy Markdown
Collaborator

jourdain commented May 6, 2026

Small comment on the copy of the key for the iterator to allow modification while iterating.

Comment thread src/trame_server/state.py
self._currents.clear()

def __iter__(self):
return iter(list(self._currents))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list was there to make a copy and allow internal update while iterating.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the review! I have rollbacked this change.

After introducing the _suppress_change_stack this copy is handled by the following code which returns the current listeners to trigger and clears the stack to properly check for newly modified keys:

        self._state_listeners.add_all(
            self._suppress_change_stack.get_change_listener_keys()
        )

        # Clear change keys before triggering listeners as listeners can trigger modifications in chain
        self._suppress_change_stack.clear()

This reentrant case is correctly covered by the test_minimum_change_detection test case.

@Thibault-Pelletier Thibault-Pelletier force-pushed the fix-change-listener-order branch from 0ab35d3 to a19ebef Compare May 7, 2026 06:07
Update StateChangeHandler and _SuppressListenersChangeStack to
use an ordered set instead of a set to ensure listeners are triggered in
the same order when flushed
@Thibault-Pelletier Thibault-Pelletier force-pushed the fix-change-listener-order branch from a19ebef to 38dc9b0 Compare May 7, 2026 06:10
Install package in editable mode to properly map pytest results and src folder
@Thibault-Pelletier
Copy link
Copy Markdown
Contributor Author

Thibault-Pelletier commented May 7, 2026

I have rebased this PR on main and added another fix for the coverage which was still 0% after my previous CI fix. I hadn't seen that the CI also reported the coverage for PR and coverage was still 0% ...

- name: Install and Run Tests
run: |
pip install ".[dev]"
pip install -e ".[dev]"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need -e that probably mean we are not properly installing something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -e is only needed so that the coverage reports outputs something more than 0% since moving the files to src.
My previous fix of the src path for the coverage didn't resolve the problem but installing using -e did.

Locally I can also run the tests without installing and providing the PYTHON_PATH with ./src to get coverage as well so I suppose the problem is coming from where the coverage expects the files to be.

I'm open to suggestions on this!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that I'm saying is that if we mess up something on the install part, we could miss it because of that. But I'm ok to merge for now.

@jourdain jourdain merged commit 9f1fc3f into Kitware:master May 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants