Repository navigation
fix(signals): preserve cycle tracking across unrelated observable not… - #4237
Conversation
|
Performance benchmarks:
|
|
Hi @savinduhasintha2005 , I originally reported this issue in #4234 and have been actively working on it. You shouldn't take over and open a PR for an issue reported by someone else without asking or checking in on the thread first. I am submitting my PR now—please close this duplicate so we don't overlap on the same task. Thanks. |
| if old_computed is None: | ||
| PROCESSING_SIGNALS.clear() |
There was a problem hiding this comment.
old_computed is None doesn't always mean this is the outermost evaluation: peek() also sets CURRENT_COMPUTED to None. If a computed peeks at another computed property, that inner evaluation clears the set and wipes the outer computed's tracking, so this cycle is no longer caught, while main raises for it:
@computed_property
def result(self):
value = self.a
self.peek("helper") # helper is another computed property
self.a = value + 1 # writes what it read: a cycle
return valueCounting how deeply evaluate() is nested and clearing only when it returns to 0 fixes this. The case from #4234 still raises with that change, and the signals and states tests pass.
|
@quaquel Sorry for the noise, my approval here was meant for #4164 and posted here by mistake. Did you get a chance to look at my inline comment below? With this merged, a computed that |
|
I opened a revert PR, which hopefully will be approved asap. I did not check but just trusted your judgement. No worries about the mistake. |
Description
This PR fixes an issue in the
mesa_signalscycle-tracking mechanism where unrelated observable notifications could prematurely clear the active dependency-tracking state during computed-property evaluation.Previously,
PROCESSING_SIGNALS.clear()was called insideObservable.__set__whenever a changed notification was emitted. If an unrelated observable was modified during a computed-property evaluation, this cleared the active tracking information and prevented the cycle detector from identifying cyclical dependencies.Changes
mesa/experimental/mesa_signals/core.pyPROCESSING_SIGNALS.clear()fromObservable.__set__.PROCESSING_SIGNALSto the completion of the outermostComputedState.evaluate().tests/experimental/test_mesa_signals.pyValueError("cyclical dependency").Testing
ruff checkruff format --checkpytest tests/experimental/test_mesa_signals.py -vpytest tests/experimental/test_states.py -vRelated Issue
Fixes #4234