Skip to content

fix(parser): retry failed parser loads - #202

Merged
pyramation merged 2 commits into
mainfrom
fix/parser-retry-failed-load
Nov 23, 2026
Merged

pyramation merged 2 commits into
mainfrom
fix/parser-retry-failed-load

Conversation

@pyramation

@pyramation pyramation commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Parser in @pgsql/parser (parser/templates/index.js.template, index.cjs.template) cached a rejected load forever: if the version import or loadModule() failed once, every later parse() rethrew the stale error and parser.ready never settled.

Now:

  • concurrent callers share one load attempt; the parser is only published after init succeeds
  • on failure the cached attempt is cleared and that attempt's ready rejects
  • the next call retries with a fresh ready promise

Regression tests in parser/test/esm.test.mjs cover both the ESM and CJS entry points using a PG 18 loader that fails once: concurrent callers and ready see the failure, parseSync() still reports unloaded, and the next parse() succeeds. Both tests fail on unmodified main. README documents the ready semantics.

Found by luxor-code-review on #201; kept separate from that PR.


libpg-query and parser opened this PR for Dan
Implemented in session Fix cached failed load in @pgsql/parser
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • Bug Fixes
    • Parser loading can be retried after a failed attempt, allowing later parsing to succeed without requiring a restart.
    • Concurrent parsing requests share the same loading attempt. The parser becomes available only after its optional initialization completes successfully.
  • Documentation
    • Clarified that retrying after a loading failure creates a new readiness promise.

@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 23, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This change revises the parser loader templates and the ESM test suite with no verified defects.

Files Change
parser/templates/index.cjs.template, parser/templates/index.js.template Updates the CJS and ESM loader templates.
parser/README.md Updates documentation.
parser/test/esm.test.mjs Updates ESM tests.

Reviewed commit: add4509

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The parser templates update ready handling and load retries. They assign the imported module to this.parser only after its optional loadModule() completes. Tests cover retry behavior for ESM and CommonJS entry points.

Changes: Parser load retry lifecycle

Layer / File(s) Summary
Ready promise and retry handling
parser/templates/index.cjs.template, parser/templates/index.js.template, parser/test/esm.test.mjs, parser/README.md
Both parser templates reject ready when loading fails and allow a later attempt to create a new promise. Tests cover failed and successful retries for ESM and CommonJS. The README describes the replacement promise.
Module initialization before assignment
parser/templates/index.cjs.template, parser/templates/index.js.template
Both templates call an available loadModule() before assigning the imported module to this.parser.

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

Change: Bug fix

Merge Risk: Minimal · up to 692fb

This change lets parser loading recover after a transient failure instead of caching the rejection. The retry behavior is covered for both ESM and CommonJS, and no merge-blocking risk was found.

Architecture risk: Low · up to add45

The change affects 1 system.

Changed systems: parser

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — parser (service) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in parser/README.md: The ready property description now says that after a loading failure, the next load attempt replaces its promise; the previous description only said it resolves when loading completes.
  • observed — Modified behavior in parser/templates/index.cjs.template: The constructor now initializes ready through _resetReady(). That method creates a promise with resolve and reject handlers and attaches a rejection handler; the previous promise could only resolve.
  • observed — Modified behavior in parser/templates/index.cjs.template: loadParser() now resets ready when there is no current reject handler and catches load failures to clear _loadPromise, reject the current ready, and rethrow the error. This replaces the prior shared load promise, which was not cleared on failure and did not reject ready.
  • observed — Modified behavior in parser/templates/index.cjs.template: _doLoad() now stores the required module locally, awaits its optional loadModule(), and assigns it to this.parser afterward. Previously it assigned the module before awaiting loadModule().
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(parser): retry failed parser loads" states the main change. The changeset makes failed parser loads retryable: a failed load clears the shared promise, rejects ready, and lets a later…
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(parser): retry failed parser loads" states the main change. The changeset makes failed parser loads retryable: a failed load clears the shared promise, rejects ready, and lets a later call create a new ready promise. The title is specific, concise, and uses a conventional commit prefix.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • 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 add4509 and 692fbd4.

Files selected for processing: 1

  • parser/test/esm.test.mjs
Files with no reviewable changes: 1

  • parser/test/esm.test.mjs

Limit details: You’ve used all 10 included reviews currently available.

@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

@pyramation
pyramation merged commit a65466a into main Nov 23, 2026
69 of 70 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