fix: avoid false infinite loop detection when cached signal self-updates#24412
Draft
Artur- wants to merge 4 commits into
Draft
fix: avoid false infinite loop detection when cached signal self-updates#24412Artur- wants to merge 4 commits into
Artur- wants to merge 4 commits into
Conversation
When an effect reads from a cached signal that detects its value is stale, the cached signal recomputes and submits an update. This previously triggered infinite loop detection because the notification happened while the effect was still active. However, this is lazy evaluation (read-triggered), not an actual write loop. Add a ThreadLocal flag to track when we're in a "read-triggered update" context and skip the infinite loop check in that case. Fixes #24409 https://claude.ai/code/session_0193Z8ydgjUCCpbgCZwHhGGM
|
|
|
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
ThreadLocalflag inEffectto track when we're in a "read-triggered update" contextsubmit()call in this contextBackground
When an effect reads from a cached signal that detects its value is stale (via
hasChanges()), the cached signal recomputes its value and submits an update. This update triggers a change notification back to the effect. Previously, this was incorrectly detected as an infinite loop because the effect was still active when the notification arrived.However, this is not a true infinite loop - it's lazy evaluation happening during a read operation. The effect is reading, not writing, so there's no actual loop.
Test plan
infiniteLoopDetection_cachedSignalSelfUpdate_notDetectedAsLoopto verify an effect reading a cached signal that self-updates does not throw an infinite loop exceptionFixes #24409
https://claude.ai/code/session_0193Z8ydgjUCCpbgCZwHhGGM
Generated by Claude Code