-
Notifications
You must be signed in to change notification settings - Fork 9
Fix infinite loop with self-referential data #1240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…d up with the inifinite loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cubic reviewed 1 file and found no issues. Review PR in cubic.dev.
1) reuse proxy objects so that code detecting recursions acts accordingly 2) throw after 100 recursions, for code that doesn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds handling for self-referential query results by introducing proxy caching per ReactivityLog and a recursion depth limit, and supplements the test suite to verify these behaviors.
- Introduce
MAX_RECURSION_DEPTHand trackdepthincreateQueryResultProxyto throw a clear error on excessive recursion. - Add
proxyCacheByLog(with afallbackLog) to reuse the same proxy instance for repeated targets and prevent infinite loops. - Extend tests in
recipes.test.tsto validate that self-references are preserved and that infinite recursion is caught.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/runner/src/query-result-proxy.ts | Add recursion depth guard, proxy cache logic keyed by log, and pass depth |
| packages/runner/test/recipes.test.ts | New test verifying self-referential arrays and recursion overflow handling |
Comments suppressed due to low confidence (3)
packages/runner/src/query-result-proxy.ts:84
- [nitpick] The variable name
cacheIndexis misleading, as it represents a key rather than an index. Consider renaming it tocacheKeyorlogKeyfor clarity.
const cacheIndex = log ?? fallbackLog;
packages/runner/test/recipes.test.ts:1147
- [nitpick] This check relies on a generic throw from recursive traversal. To ensure you’re testing the custom
MAX_RECURSION_DEPTHerror, consider asserting the specific error message or using a proxy-based recursion to trigger the intended limit.
expect(() => recurse(firstState)).toThrow();
packages/runner/src/query-result-proxy.ts:15
- Using a single shared
fallbackLogfor all undefined logs may cause the cache to retain proxies indefinitely, potentially leading to memory leaks. Consider clearing entries when logs are disposed or using a more isolated fallback mechanism.
const fallbackLog: ReactivityLog = { reads: [], writes: [] };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cubic reviewed 2 files and found no issues. Review PR in cubic.dev.
Self-referential data causes issues.
Verified that the creation itself is fine.
Changed
QueryResultProxyin two ways to improve situation: