Skip to content

[do not merge] measure parse depth limits on 18.1.5 vs main per OS - #216

Closed
pyramation wants to merge 2 commits into
mainfrom
devin/1795673887-macos-depth-probe
Closed

pyramation wants to merge 2 commits into
mainfrom
devin/1795673887-macos-depth-probe

Conversation

@pyramation

@pyramation pyramation commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Temporary: replaces the v18 test run with a probe that binary-searches the deepest nested function calls, subqueries, chained +1 and PL/pgSQL IF blocks that parseSync / normalizeSync / parsePlPgSQLSync accept, on published libpg-query 18.1.5 and on the main build, so we get the numbers from the macOS and Windows runners. Will be closed without merging.


libpg-query and parser opened this PR for Dan
Implemented in session Settle the last old WASM hardening PRs
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • Tests
    • Added coverage comparing maximum supported nesting depths across several SQL and PL/pgSQL constructs.
    • Test results now include runtime and platform details, along with depth limits and failure messages.
    • The test command now runs the depth-limit comparison.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high · 🟡 2 medium

💬 Inline comments (3)


This PR adds a depth-probe.test.js diagnostic that binary-searches the maximum parse depth for several SQL forms against the wasm parser, comparing libpg-query@18.1.5 (fetched via npm pack at test time) with the local build. It is a useful measurement tool, but the accompanying package.json change makes it the only thing pnpm test runs.

Files Change
versions/18/package.json test script now runs only test/depth-probe.test.js, removing all nine existing test suites from the default run.
versions/18/test/depth-probe.test.js New probe: builds deep SQL inputs, binary-searches the depth limit per form/function, reloads the wasm module between probes, and prints results without asserting anything.

The probe should be wired in as a separate script (e.g. probe or test:probe) so the real suites keep running, and it should treat only depth/memory-related errors as depth failures.

Reviewed commit: 1f6a08a

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The PostgreSQL 18 test script now runs a depth-probe test. The test compares nesting-depth limits between libpg-query@18.1.5 and the current module across several SQL and PL/pgSQL forms.

Changes: Nesting depth probe

Layer / File(s) Summary
Measure and run nesting-depth probes
versions/18/test/depth-probe.test.js, versions/18/package.json
The new test measures successful nesting depths for the reference package and current module, records failure messages, and reloads the module after failed-limit measurements. The package test script now runs this probe instead of the previous test files.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

Suggested reviewers: luxor-code-review

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces the versions/18 test script with a new depth-probe diagnostic, dropping the full existing test suite.

Key findings

Comment thread versions/18/package.json
"wasm:clean": "pnpm wasm:make clean",
"wasm:clean-cache": "pnpm wasm:make clean-cache",
"test": "node --test test/parsing.test.js test/pg18.test.js test/fingerprint.test.js test/normalize.test.js test/plpgsql.test.js test/scan.test.js test/errors.test.js test/input-encoding.test.js test/wasm-recovery.test.js test/load-module.test.js"
"test": "node --test test/depth-probe.test.js"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 bug · high

Test script drops all existing test suites

The test script in versions/18/package.json:34 now runs only test/depth-probe.test.js, replacing the original run of ten test suites (parsing, pg18, fingerprint, normalize, plpgsql, scan, errors, input-encoding, wasm-recovery, load-module). All ten files still exist in versions/18/test/ but are no longer executed by npm test, and no other script runs them. The entire regression suite, including error-handling and WASM-recovery coverage, silently stops running.

📋 Prompt for AI Agents

In versions/18/package.json line 34, restore the test script to run all existing suites (test/parsing.test.js test/pg18.test.js test/fingerprint.test.js test/normalize.test.js test/plpgsql.test.js test/scan.test.js test/errors.test.js test/input-encoding.test.js test/wasm-recovery.test.js test/load-module.test.js) and add a separate script such as "test:probe": "node --test test/depth-probe.test.js" so the new depth probe runs alongside, not instead of, the regression suite.

Comment on lines +33 to +45
it('probe', async () => {
const dir = path.join(__dirname, '..', '.probe');
fs.mkdirSync(dir, { recursive: true });
execSync('npm pack libpg-query@18.1.5 --silent', { cwd: dir });
execSync('tar xzf libpg-query-18.1.5.tgz', { cwd: dir });
const old = require(path.join(dir, 'package', 'wasm', 'index.cjs'));
const cur = require('../wasm/index.cjs');
const out = [`node ${process.version} ${process.platform} ${process.arch}`];
for (const [name, lib] of [['18.1.5', old], ['main', cur]]) {
for (const row of await measure(lib)) out.push(`PROBE ${name} | ${row}`);
}
console.log(out.join('\n'));
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Probe test needs network and always passes

The probe test runs npm pack libpg-query@18.1.5 on every run (versions/18/test/depth-probe.test.js:36), requiring registry network access and a hardcoded version pin, and extracts into versions/18/.probe with no cleanup and no .gitignore entry. Its single it('probe') body only prints rows and contains no assertions, so the test can never fail; combined with it being the sole npm test entry point (see finding-001), any offline CI fails the whole suite while regressions go undetected.

📋 Prompt for AI Agents

In versions/18/test/depth-probe.test.js lines 33-45, make the probe robust: skip the test (e.g. t.skip) when the registry is unreachable or the tarball is already cached, read the version from package.json instead of the hardcoded '18.1.5', clean up versions/18/.probe (fs.rmSync in an after hook or extract to a temp dir; also add .probe/ to .gitignore), and add assertions on the rows collected in measure() — or move the probe to a separate opt-in script since it is not a regression test.

const top = err;
while (lo < hi - 1) { const mid = (lo + hi) >> 1; if (ok(mid)) lo = mid; else hi = mid; }
ok(hi);
rows.push(`${form} ${fn}: max ${lo} (at ${hi}: ${err}; at 20000: ${top})`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Probe conflates any thrown error with depth failure

The ok helper in versions/18/test/depth-probe.test.js:26 treats every thrown error as a depth-limit failure, so out-of-memory errors (libpg_query ran out of WASM memory, allocation failures), WASM traps, and ordinary parse errors all terminate the binary search the same way a stack depth limit exceeded error would. For large-input forms like chained +1, the search can converge on the WASM heap limit rather than the parser stack limit and report a bogus maximum. The typeof r === 'string' && /memory exhausted|stack depth/ branch is dead code: the sync APIs throw on errors and never return error strings.

📋 Prompt for AI Agents

In versions/18/test/depth-probe.test.js line 26, rewrite ok so the catch branch inspects e.message: return false as a depth failure only when the message contains 'stack depth limit exceeded'; if it matches /out of (WASM )?memory|memory allocation failed|terminated/ set err to a distinct marker (e.g. 'oom'); for any other message record the message and abort the measurement rather than treating it as a depth failure. Remove the dead typeof r === 'string' regex branch since the sync APIs throw rather than return error strings.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Measurement only, closing. 18.1.5 and main reach the same depths within a few levels on all three OSes; only normalize of nested function calls on Linux/Windows drops from 838 to 781.

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