Skip to content

Conversation

@seefeldb
Copy link
Contributor

@seefeldb seefeldb commented Jun 13, 2025

Self-referential data causes issues.

Verified that the creation itself is fine.

Changed QueryResultProxy in two ways to improve situation:

  1. It now uses a cache to return the exact same object when recursing, so any code that already detects cycles acts correctly
  2. throw an error after 100 recursions to at least error more sanely.

@linear
Copy link

linear bot commented Jun 13, 2025

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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
Copy link
Contributor

Copilot AI left a 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_DEPTH and track depth in createQueryResultProxy to throw a clear error on excessive recursion.
  • Add proxyCacheByLog (with a fallbackLog) to reuse the same proxy instance for repeated targets and prevent infinite loops.
  • Extend tests in recipes.test.ts to 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 cacheIndex is misleading, as it represents a key rather than an index. Consider renaming it to cacheKey or logKey for 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_DEPTH error, 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 fallbackLog for 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: [] };

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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.

@seefeldb seefeldb merged commit f8ab59e into main Jun 13, 2025
7 checks passed
@seefeldb seefeldb deleted the berni/ct-456-fix-infinite-loop-in-handlers branch June 13, 2025 19:31
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