Skip to content

fix(wasm): restore the PG 18 stack depth budget - #210

Merged
devin-ai-integration[bot] merged 3 commits into
mainfrom
devin/1795658924-wasm-stack-budget
Nov 26, 2026
Merged

devin-ai-integration[bot] merged 3 commits into
mainfrom
devin/1795658924-wasm-stack-budget

Conversation

@pyramation

@pyramation pyramation commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

libpg-query 18.2.5–18.2.6 reject nesting that 18.1.5 parsed: SELECT 1+1+… fails with "stack depth limit exceeded" at about 800 terms (18.1.5: 2000+), and nested subqueries fail at 500. The fork's stack-depth check (from upstream pganalyze/libpg_query#348) never sized max_stack_depth under Emscripten, so it stayed at the 100kB default. The fix landed in the fork in constructive-io/libpg_query#18: it reads the WASM stack bounds and caps the limit at 512kB, so the clean error fires before V8's native stack overflows.

  • versions/18/test/wasm-recovery.test.js: 2000 chained operators, 1000 nested subqueries and 2000 nested function calls must parse. This commit was pushed alone first and went red on the old pin on all three OSes. The existing 100k-term test still requires the clean stack depth error, not a V8 RangeError.
  • versions/18/package.json / Makefile (via pnpm copy:templates): pin 18-constructive at the fork PR's merge commit 7791971.

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


@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. No issues found — approved ✅.


This PR adds a single new test file covering the WASM crash-recovery behavior after the v18.2.x stack-depth limit change: it reloads the WASM module, then parses 2,000-deep nested +1 expressions and a 20,000-node case to confirm no crashes and correct statement counts. No production code is changed.

Files Change
versions/18/test/wasm-recovery.test.js New test: loadModule() recovery after deep-nesting parse, asserting returned statement counts.

Reviewed commit: 76ee723

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PostgreSQL 18 libpg_query commit pin is updated. New WASM tests check that 2,000 chained operators, 1,000 nested subqueries, and 2,000 nested function calls each parse as one statement.

Changes: Parser depth coverage

Layer / File(s) Summary
WASM parser depth coverage
versions/18/Makefile, versions/18/package.json, versions/18/test/wasm-recovery.test.js
The build and package metadata use commit 7791971be1fc169d3f1b0d1ec887dc3f134ad134. Tests check that three deeply nested SQL forms parse as one statement.

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

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to da271

This updates the PostgreSQL 18 WASM parser to a libpg_query revision that restores the stack depth budget and adds tests for deeply nested SQL. No actionable merge-blocking risk was found in the supplied changes.

Architecture risk: Low · up to da271

The change affects 1 system.

Changed systems: versions

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — versions (service) was modified; 3 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in versions/18/test/wasm-recovery.test.js: Adds a test that loads the module and confirms chained operators, nested subqueries, and nested function calls at the specified depths parse successfully as single statements.
  • observed — Modified behavior in versions/18/Makefile: The LIBPG_QUERY_COMMIT value changes from f75f8010a8a75fe4645db550c5f8f435dbc938a3 to 7791971be1fc169d3f1b0d1ec887dc3f134ad134.
  • observed — Modified behavior in versions/18/package.json: The libpgQueryCommit value changes from f75f8010a8a75fe4645db550c5f8f435dbc938a3 to 7791971be1fc169d3f1b0d1ec887dc3f134ad134.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(wasm): restore the PG 18 stack depth budget" matches the main change. The PR restores the stack depth budget for PG 18 under WASM. The objectives describe a fix for the stack depth limi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(wasm): restore the PG 18 stack depth budget" matches the main change. The PR restores the stack depth budget for PG 18 under WASM. The objectives describe a fix for the stack depth limit that now triggers at lower nesting levels. The changeset itself is mostly a version pin bump plus one WASM test. The title names the fix, but the diff only pins the fork commit and adds a test, so the pinned commit carries the fix. This is a reasonable match for the primary intent.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 49bdbbc and da271b1.

Files selected for processing: 2

  • versions/18/Makefile
  • versions/18/package.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@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

coderabbitai[bot]

This comment was marked as resolved.

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