Skip to content

fix(sync): avoid argument-stack overflow gathering unresolved refs on large syncs#1283

Open
ianmage wants to merge 1 commit into
colbymchenry:mainfrom
ianmage:fix/unresolved-refs-stack-overflow
Open

fix(sync): avoid argument-stack overflow gathering unresolved refs on large syncs#1283
ianmage wants to merge 1 commit into
colbymchenry:mainfrom
ianmage:fix/unresolved-refs-stack-overflow

Conversation

@ianmage

@ianmage ianmage commented Jul 14, 2026

Copy link
Copy Markdown

Problem

codegraph sync aborts with RangeError: Maximum call stack size exceeded on large projects — reproduced on a large Perforce workspace (Unreal Engine C++/Python, ~6k files, ~1.1M references), and reproducible on any fresh index, large changelist, or first sync after a branch switch.

Captured stack:

RangeError: Maximum call stack size exceeded
    at QueryBuilder.getUnresolvedReferencesByFiles (dist/db/queries.js)
    at CodeGraph.sync (dist/index.js)   // resolution git-fast-path

Root cause

Two unresolved-ref readers chunk their IN (...) list under SQLite's parameter limit, then collect the matched rows with rows.push(...chunkRows). Chunking the file-path / name list bounds the SQL parameters, not the returned row count: one 500-item chunk can match hundreds of thousands of rows, and spreading them as call arguments exceeds V8's argument-stack limit (~125k args). Affected:

Fix

Append row-by-row (for (const row of chunkRows) rows.push(row)) in both readers. No behavior change; only removes the arg-spread. The existing file-path / name chunking (for the SQLite parameter limit, #540) is unchanged.

Tests

Two regression tests in __tests__/db-perf.test.ts drive each reader past the arg-spread ceiling. Both throw Maximum call stack size exceeded on the pre-fix spread and pass on the fix. Full db-perf + pr19-improvements suites green (55 tests). Verified end-to-end: a forced full re-sync of the ~1.1M-ref workspace that previously threw now completes.

… large syncs

Two unresolved-ref readers in the DB query layer chunked their IN-list
under SQLite's parameter limit but then collected the matched rows with
`rows.push(...chunkRows)`. Chunking the file-path / name list bounds the
SQL parameters, not the returned ROW count: on a large `codegraph sync`
(fresh index, big changelist, first sync after a branch switch) a single
chunk matches hundreds of thousands of rows, and spreading them as call
arguments blows V8's argument-stack limit — the sync aborts with
"Maximum call stack size exceeded" (arg-spread ceiling ~125k).

Append row-by-row instead of spreading, in both readers:
  - getUnresolvedReferencesByFiles  (pending refs for changed files)
  - getRetryableFailedReferences    (failed-ref retry path, colbymchenry#1240)

Adds two regression tests (db-perf) that overflow on the pre-fix spread
and pass on the fix.
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.

1 participant