mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Unrelated observable notifications clear active cycle tracking and hide cyclical dependencies

Open sangitabera opened this issue 1 week ago • 0 comments

Describe the bug The cycle-tracking mechanism in the experimental signals implementation can lose its active tracking state when an unrelated observable notification is processed during a computed-property evaluation.

When a computed property reads one observable, modifies another observable that triggers a notification, and subsequently modifies the original observable, the notification handling can clear the global PROCESSING_SIGNALS collection.

As a result, the cycle detector loses information about the ongoing computation and fails to detect the cyclical dependency.

This causes a computed property with a cyclical dependency to evaluate without raising the expected ValueError.

Expected behavior Processing an unrelated observable notification should not clear or interfere with the cycle-tracking state of an active computed-property evaluation.

The implementation should preserve active tracking information across nested or unrelated notifications and correctly raise:

ValueError("cyclical dependency")

when a computed property modifies an observable involved in its active dependency chain.

To Reproduce

def test_unrelated_notification_does_not_clear_cycle_tracking():
    class Model(HasEmitters):
        a = Observable()
        b = Observable()

        @computed_property
        def result(self):
            value = self.a
            self.b = 10
            self.a = value + 1
            return value

    model = Model()
    model.a = 1
    model.b = 2

    callback = lambda signal: None
    model.observe("b", ObservableSignals.CHANGED, callback)

    with pytest.raises(ValueError, match="cyclical dependency"):
        _ = model.result

Actual result:

The test fails with:

Failed: DID NOT RAISE ValueError

Additional context The likely cause is the use of PROCESSING_SIGNALS.clear() during notification handling.

Clearing the entire tracking collection can remove information belonging to an ongoing computed-property evaluation.

Cycle-tracking state should be managed within the scope of the corresponding signal processing or computation rather than being globally cleared when an unrelated notification occurs.

A regression test should ensure that unrelated notifications cannot interfere with active cycle detection.

sangitabera avatar Nov 25 '26 10:11 sangitabera