Skip to content

fix(core): retry a lazy ORM import in lower.ts after a rejection - #1286

Merged
borisno2 merged 2 commits into
prisma-8from
claude/jolly-turing-h5aaz7
Sep 8, 2026
Merged

fix(core): retry a lazy ORM import in lower.ts after a rejection#1286
borisno2 merged 2 commits into
prisma-8from
claude/jolly-turing-h5aaz7

Conversation

@borisno2

@borisno2 borisno2 commented Sep 7, 2026

Copy link
Copy Markdown
Member

Summary

packages/core/src/secured/lower.ts loads Prisma's and/or/all combinators (whereCombinators) and the pgvector expression builders (vectorLowering) through a lazy import(), caching the resulting promise in a module-level variable so the package root's static import graph stays free of @prisma/orm-postgres.

Both cached the promise even when it rejected. A single transient import failure was therefore permanent for the life of the process: every later call re-awaited the same rejected promise, and every secured read (and any .nearest() vector search) would fail until the process restarted, with no way to recover.

What changed

Both functions now clear their module-level cache in a .catch() before rethrowing, so:

  • A rejected import is not cached — the next call retries.
  • A successful import is still cached — no per-call import cost, no race (the ??= guard is unchanged).

vectorLowering's inline .then() callback was extracted into a small loadVectorLowering() async function — chaining .catch() directly after the original inline .then() broke TypeScript's contextual typing for the order/bound closures (their parameter types are inferred from the VectorLowering interface via the Promise<VectorLowering> assignment target, which chaining .catch() onto the same expression disrupted). No behavioral change beyond the fix itself.

Test plan

  • New packages/core/src/secured/lower.test.ts: for both whereCombinators and vectorLowering, mocks the lazy import to throw once, asserts the call rejects, then un-mocks it and asserts the next call succeeds — proving the retry. A separate test proves a successful import is still cached (one factory call across repeated callers).
  • pnpm build (tsc) — clean
  • pnpm test — 85 files, 1663 passed / 2 skipped (core package)
  • pnpm lint — 0 errors (2 pre-existing warnings, both untouched by this change)
  • pnpm manypkg fix and pnpm format — no changes needed
  • Changeset added (@opensaas/stack-core: patch)

Closes #1231

🤖 Generated with Claude Code

https://claude.ai/code/session_01HWS4RTvCjP7p5J2LrjNUMR


Generated by Claude Code

whereCombinators and vectorLowering cached the promise from a lazy
import() even when it rejected, so a single transient import failure
was permanent for the life of the process. A rejection now clears the
cache so the next call retries; a successful import is still cached.

Closes #1231

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HWS4RTvCjP7p5J2LrjNUMR
@vercel

vercel Bot commented Sep 7, 2026

Copy link
Copy Markdown

Deployment failed for project stack-docs with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/open-saas?upgradeToPro=build-rate-limit

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@changeset-bot

changeset-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7bdab21

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@opensaas/stack-core Patch
@opensaas/stack-auth Patch
@opensaas/stack-cli Patch
@opensaas/stack-rag Patch
@opensaas/stack-storage Patch
@opensaas/stack-tiptap Patch
@opensaas/stack-ui Patch
@opensaas/stack-storage-s3 Patch
@opensaas/stack-storage-vercel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@borisno2 borisno2 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Single-pass review at high effort (Agent tool unavailable in this context — no multi-agent fan-out or subagent verify pass ran; I worked all 8 angles myself in one context). This is a small, tightly-scoped fix (69 lines in lower.ts, +68 new test lines). I traced the ??= + synchronous-catch-handler reset logic by hand for races and found none — the mutual exclusion via pending/pendingVector staying truthy while a promise is in flight rules out two generations of the cache ever being confused. No callers depend on the old permanent-cache-on-rejection behavior. No correctness bugs found; the two comments below are low-severity cleanup/docs notes only.


Generated by Claude Code

Comment thread packages/core/src/secured/lower.ts Outdated
Comment thread packages/core/src/secured/lower.ts Outdated
… cache

whereCombinators and vectorLowering duplicated the identical
cache-unless-rejected pattern; centralizing it in one lazyImport<T>
helper means the race-sensitive logic only needs to be correct once,
and moving vectorLowering's loader inline restores its "Known limits"
TSDoc onto the exported symbol (it had drifted onto an unexported
helper when the previous commit split it out for type inference).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HWS4RTvCjP7p5J2LrjNUMR

borisno2 commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

The Vercel status check is red on this PR, but it's not this PR's failure: it's a stack-docs deployment hitting Vercel's free-tier daily quota (Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day")), unrelated to anything this diff touches. No code fix applies — it's an account-level rate limit that self-resolves once the daily quota window rolls over, and the error message itself rules out a re-run helping before then. GitHub Actions' test/e2e/GitGuardian checks are the real CI here and are green or still running.


Generated by Claude Code

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Core Package Coverage (./packages/core)

Status Category Percentage Covered / Total
🟢 Lines 94.25% (🎯 65%) 3235 / 3432
🟢 Statements 93.02% (🎯 65%) 3585 / 3854
🟢 Functions 96.6% (🎯 62%) 683 / 707
🟢 Branches 87.73% (🎯 50%) 2476 / 2822
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/secured/lower.ts 90.9% 76.08% 85.71% 93.44% 90, 101, 160, 169, 177, 250
Generated in workflow #2065 for commit 7bdab21 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for UI Package Coverage (./packages/ui)

Status Category Percentage Covered / Total
🔵 Lines 78.45% 244 / 311
🔵 Statements 77.95% 251 / 322
🔵 Functions 69.81% 74 / 106
🔵 Branches 66.94% 160 / 239
File CoverageNo changed files found.
Generated in workflow #2065 for commit 7bdab21 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for CLI Package Coverage (./packages/cli)

Status Category Percentage Covered / Total
🔵 Lines 73.64% 1646 / 2235
🔵 Statements 73.23% 1765 / 2410
🔵 Functions 82.42% 286 / 347
🔵 Branches 60.62% 819 / 1351
File CoverageNo changed files found.
Generated in workflow #2065 for commit 7bdab21 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Auth Package Coverage (./packages/auth)

Status Category Percentage Covered / Total
🔵 Lines 91.2% 280 / 307
🔵 Statements 89.94% 313 / 348
🔵 Functions 96.05% 73 / 76
🔵 Branches 82.38% 262 / 318
File CoverageNo changed files found.
Generated in workflow #2065 for commit 7bdab21 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Storage Package Coverage (./packages/storage)

Status Category Percentage Covered / Total
🔵 Lines 79.66% 235 / 295
🔵 Statements 81.17% 263 / 324
🔵 Functions 87.91% 80 / 91
🔵 Branches 77.46% 220 / 284
File CoverageNo changed files found.
Generated in workflow #2065 for commit 7bdab21 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for RAG Package Coverage (./packages/rag)

Status Category Percentage Covered / Total
🔵 Lines 54.38% 397 / 730
🔵 Statements 53.85% 419 / 778
🔵 Functions 64.06% 82 / 128
🔵 Branches 47.25% 198 / 419
File CoverageNo changed files found.
Generated in workflow #2065 for commit 7bdab21 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Storage S3 Package Coverage (./packages/storage-s3)

Status Category Percentage Covered / Total
🔵 Lines 100% 40 / 40
🔵 Statements 100% 40 / 40
🔵 Functions 100% 9 / 9
🔵 Branches 100% 19 / 19
File CoverageNo changed files found.
Generated in workflow #2065 for commit 7bdab21 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Storage Vercel Package Coverage (./packages/storage-vercel)

Status Category Percentage Covered / Total
🔵 Lines 100% 68 / 68
🔵 Statements 100% 71 / 71
🔵 Functions 100% 15 / 15
🔵 Branches 97.87% 46 / 47
File CoverageNo changed files found.
Generated in workflow #2065 for commit 7bdab21 by the Vitest Coverage Report Action

@borisno2
borisno2 merged commit 47a4b98 into prisma-8 Sep 8, 2026
4 of 5 checks passed
@borisno2
borisno2 deleted the claude/jolly-turing-h5aaz7 branch September 8, 2026 11:30
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.

2 participants