Skip to content

fix(wasm): normalize deep nesting on a fresh instance - #214

Merged
devin-ai-integration[bot] merged 17 commits into
mainfrom
devin/1795672086-normalize-depth
Nov 26, 2026
Merged

devin-ai-integration[bot] merged 17 commits into
mainfrom
devin/1795672086-normalize-depth

Conversation

@pyramation

@pyramation pyramation commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #213; retarget to main once that merges.

normalizeSync stops at about 770 chained terms (SELECT 1+1+…) on a fresh WASM instance and reaches about 1,640 only once V8 has warmed the instance up (1,000 WASM↔JS crossings, --wasm-wrapper-tiering-budget). Since 18.2.x replaces the instance after an overflow, a caller that hits one too-deep query drops back to 770, where 18.1.5 kept its warm (but corrupt) instance and still normalized 1,640.

The fix is in the C fork, constructive-io/libpg_query#21: normalize no longer has a PG_TRY block, and with it a WASM → JS → WASM round trip, on every level of an expression. This PR pins that commit. A fresh instance now normalizes 4,000 chained terms. No memory or stack setting changes.

The test commit is pushed first and fails on the current pin: it normalizes 3,000 chained terms right after an overflow, three times in a row.


libpg-query and parser opened this PR for Dan
Implemented in session Audit WASM memory history and verify full-stack depth
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of deeply nested SQL during normalization and fingerprinting, reducing stack overflow errors.
    • Deep normalization now recovers more reliably after stack-depth failures.
    • Increased the depth of SQL expressions that can be normalized before a stack-depth error occurs.
  • Tests
    • Enabled depth-related tests across supported Node.js versions, including Node 20.

@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 change introduces a single new test file exercising WASM recovery behavior for the pg_query parser in the PostgreSQL 18 version build. The test parses a sample SQL statement, simulates a WASM module reset, re-parses, and asserts results are consistent across the reset boundary.

Files Change
versions/18/test/wasm-recovery.test.js New test asserting that query parsing still works correctly after a WASM module reset.

Reviewed commit: ffc70bd

@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 pin changes to a new commit. The release-diff allowlist and tests cover deeper SQL normalization and fingerprinting, including normalization after a stack-depth error and execution with Node’s --no-liftoff flag.

Changes: PostgreSQL 18 deep SQL handling

Layer / File(s) Summary
Update libpg_query pin
versions/18/Makefile, versions/18/package.json
Both pin declarations now use commit 91d254f764b270a02f8445d3b49030eb4fda0302.
Validate deep SQL handling
versions/18/release-diff.allow.json, versions/18/test/wasm-recovery.test.js, versions/18/test/limits.test.js, .github/workflows/ci.yml
The allowlist records a baseline stack overflow and candidate success. Tests increase several normalization depth limits, cover repeated deep normalization and no-Liftoff execution, and use 3,000 nested subqueries for the stack-depth error case. Fingerprint and normalize tests no longer skip Node 20; the CI matrix is unchanged.

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

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to 28f94

This updates the PostgreSQL 18 parser dependency so much deeper SQL can be normalized and fingerprinted. It extends the tests to cover that behavior. No concrete merge-blocking risk was found.

Architecture risk: Low · up to 28f94

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; 5 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in versions/18/release-diff.allow.json: The allowlist adds a case for normalization and fingerprinting, recording the baseline stack overflow and candidate success for 18.2.7, with a reason describing the changed handling of deeply nested SQL.
  • observed — Modified behavior in versions/18/test/limits.test.js: The normalization depth limits increase from 500 to 1500 for chained + and ||, and from 500 to 750 for nested function calls and COALESCE; the other limits in these entries remain unchanged.
  • observed — Modified behavior in versions/18/test/limits.test.js: The node20 version check and comments describing stack overflows on Node 20 are removed.
  • observed — Modified behavior in versions/18/test/limits.test.js: Fingerprint and normalize tests no longer set skip: node20; both test groups now run on Node versions that were previously skipped.
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): normalize deep nesting on a fresh instance" matches the main change. The PR pins a libpg_query commit that removes a per-level PG_TRY round trip during normalization, and tests c…
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): normalize deep nesting on a fresh instance" matches the main change. The PR pins a libpg_query commit that removes a per-level PG_TRY round trip during normalization, and tests cover deep SQL normalization after an instance replacement. The title is specific, concise, and uses a conventional commit prefix. It does not mention the fingerprint fix or the test and CI changes, which is acceptable because the title need not cover every detail.

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 fcb0d4b and 28f947a.

Files selected for processing: 3

  • versions/18/Makefile
  • versions/18/package.json
  • versions/18/test/wasm-recovery.test.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 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

@devin-ai-integration
devin-ai-integration Bot changed the base branch from devin/1795668138-wasm-depth-18-1-5 to main November 26, 2026 07:31
@devin-ai-integration
devin-ai-integration Bot merged commit 6d76432 into main Nov 26, 2026
63 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.

1 participant