Skip to content

core(gather): fix broken cycle detection in recurse functions - #17173

Merged
connorjclark merged 1 commit into
GoogleChrome:mainfrom
Nithin0620:fix/seen-has-seen-cycle-detection
Aug 24, 2026
Merged

connorjclark merged 1 commit into
GoogleChrome:mainfrom
Nithin0620:fix/seen-has-seen-cycle-detection

Conversation

@Nithin0620

Copy link
Copy Markdown
Contributor

Summary

  • Fix cycle detection in recursiveReplaceLocalizableStrings (core/computed/trace-engine-result.js:136) and recursiveObjectEnumerate (core/gather/gatherers/trace-elements.js:101)
  • Both guarded against circular references with seen.has(seen), which is always false (a Set can't contain itself), so the seen set was dead code
  • With seen.has(obj), revisits short-circuit and circular insight data no longer causes Maximum call stack size exceeded

Why it matters

Both functions walk trace-engine insight models on every run. Trace-engine data is graph-like (parent/child back-references), so a single circular reference currently crashes the entire audit run with a raw stack overflow instead of a catchable error.

Tests

  • core/test/computed/trace-engine-result-test.js: circular object passed to localizeObject no longer overflows; nested i18nId objects still localize
  • core/test/gather/gatherers/trace-elements-test.js: circular insight model in getTraceEngineElements returns cleanly
  • Verified both tests fail (stack overflow) on main and pass with the fix
  • yarn type-check and yarn lint clean; update:sample-json produces no relevant diffs
    Note: repo style appends (#NNNN) to commit/PR titles once you open the PR. Want me to commit on the branch?

Both recursiveObjectEnumerate (trace-elements gatherer) and
recursiveReplaceLocalizableStrings (trace-engine-result) guard against
circular references with `seen.has(seen)`, which can never be true since
a Set cannot contain itself. The guard was dead code, so any circular
reference in trace-engine insight data caused infinite recursion and a
stack overflow that takes down the whole run.
Check `seen.has(obj)` instead so the visited set actually short-circuits
cycles. Add regression tests that crash on the old code and pass now.
@Nithin0620
Nithin0620 requested a review from a team as a code owner August 16, 2026 04:48
@Nithin0620
Nithin0620 requested review from connorjclark and removed request for a team August 16, 2026 04:48
@connorjclark connorjclark changed the title core: fix broken cycle detection in trace-engine recursion core(trace-engine): fix broken cycle detection for strings Aug 16, 2026
@connorjclark connorjclark changed the title core(trace-engine): fix broken cycle detection for strings core(gather): fix broken cycle detection in recurse functions Aug 24, 2026
@connorjclark

Copy link
Copy Markdown
Collaborator

yup, thanks!

@connorjclark
connorjclark merged commit bfd6c76 into GoogleChrome:main Aug 24, 2026
31 checks passed
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