Skip to content

fix(sql-store): allow filter() on the bare global reader so RLS can stage a search - #301

Closed
prisis wants to merge 3 commits into
alphafrom
advisor/270-mask-iterator-and-estimate-bytes
Closed

prisis wants to merge 3 commits into
alphafrom
advisor/270-mask-iterator-and-estimate-bytes

Conversation

@prisis

@prisis prisis commented Aug 2, 2026

Copy link
Copy Markdown
Member

Branched before #288/#289 landed, so it needs a rebase onto current alpha before merge.

Commits

  • fix(sql-store): allow filter() on the bare global reader so RLS can stage a search
  • fix(server): restore async iteration on masked readers
  • fix(shard-engine): fail unserializable writes distinctly instead of charging the byte cap

Files this branch still changes relative to alpha

packages/server/__tests__/mask.test.ts
packages/server/src/mask/middleware.ts
packages/shard-engine/__tests__/reactive-cache.test.ts
packages/shard-engine/__tests__/transaction-headroom.test.ts
packages/shard-engine/src/estimate-bytes.ts
packages/shard-engine/src/reactive-cache.ts
packages/shard-engine/src/transaction-headroom.ts
packages/sql-store/__tests__/ctx-db-search.test.ts
packages/sql-store/src/ctx-db.ts

prisis and others added 3 commits August 1, 2026 18:48
…tage a search

RLS installs a `.filter()` predicate at query() time, before the caller
can chain `.withSearchIndex(...)`. The bare (stage-less) global reader's
`filter` threw LEGACY_READER_ERROR eagerly, so any RLS-guarded procedure
reading a `.global()` table hit INTERNAL the moment it called
ctx.db.query(table) — making .withSearchIndex() unreachable under RLS.

Make filter() chainable on the bare reader (mirrors the order()
precedent): it pushes into the shared searchFilters array and returns
the reader, so a predicate installed before .withSearchIndex() carries
into the search stage. Terminals, the async iterator, and withIndex()
keep throwing LEGACY_READER_ERROR — only entry through filter() was
blocked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The mask middleware's reader wrapper rebuilds `query()`'s reader as an
11-member object literal that omits `[Symbol.asyncIterator]`, even
though the public TableReader type declares it and both the raw and
RLS-wrapped readers keep it. So `for await (const row of
ctx.db.query(table))` threw `TypeError: ... is not async iterable`
inside any procedure using `.use(mask(...))`, while identical code
worked unmasked and under RLS.

Add the iterator to wrapReader, delegating to the underlying reader
and masking each yielded row exactly like every other terminal.

Also removes a duplicate `withGeoIndex` key in the mask test's fake
reader (a leftover copy-paste that failed `tsc --noEmit` with "object
literal cannot have multiple properties with the same name" — the
second copy also called its builder callback unconditionally instead
of the safe `build?.(builder)` the first copy used).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…harging the byte cap

estimateBytes charged the caller-supplied `fallback` when JSON.stringify
threw, and both call sites passed their own cap as that fallback. In the
transaction meter this meant the FIRST unserializable write set
writtenBytes to exactly maxWrittenBytes and passed (the check is `>`,
not `>=`) — only the second write tripped TRANSACTION_LIMIT_EXCEEDED,
naming byte limits when the real problem was serializability. In the
reactive cache, one unserializable query result was charged the whole
maxBytes budget and could evict every other live entry.

estimateBytes now returns `undefined` for a value it cannot size and
drops the fallback parameter; each caller decides what "cannot be
sized" means on its own terms. The meter throws immediately with a
message naming serializability. The cache declines to memoize
(runs the callback, returns the result, stores and charges nothing) so
the next call is a normal miss instead of an eviction storm.

Updates the pinned estimateBytes(cyclic, 999) === 999 assertion in
transaction-headroom.test.ts to the new contract — that pin was
guarding the exact fallback behavior this change deliberately replaces.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@prisis, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d0f0b7e5-5491-4fde-949b-472f676dce74

📥 Commits

Reviewing files that changed from the base of the PR and between 6a4dd72 and 1869628.

⛔ Files ignored due to path filters (4)
  • packages/server/__tests__/mask.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/shard-engine/__tests__/reactive-cache.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/shard-engine/__tests__/transaction-headroom.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/sql-store/__tests__/ctx-db-search.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
📒 Files selected for processing (5)
  • packages/server/src/mask/middleware.ts
  • packages/shard-engine/src/estimate-bytes.ts
  • packages/shard-engine/src/reactive-cache.ts
  • packages/shard-engine/src/transaction-headroom.ts
  • packages/sql-store/src/ctx-db.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for confirming the Contributor License Agreement! 🙏

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@netlify

netlify Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for lunorash failed.

Name Link
🔨 Latest commit 1869628
🔍 Latest deploy log https://app.netlify.com/projects/lunorash/deploys/6a6f0b509777800008cb1c42

@codspeed

codspeed Bot commented Aug 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 34 untouched benchmarks
⏩ 229 skipped benchmarks1


Comparing advisor/270-mask-iterator-and-estimate-bytes (1869628) with alpha (6a4dd72)

Open in CodSpeed

Footnotes

  1. 229 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@prisis

prisis commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

Closing: this PR was opened in error by an automated run, outside the scope of its task.

No work is lost — the branch is retained on origin and this PR can be reopened at any time.

Context: this branch predates the merges of #288 and #289, so much of its content is already on alpha, and it would need a rebase before being reviewable. Reopening deliberately, after a rebase, is preferable to leaving it open in this state.

@prisis prisis closed this Aug 2, 2026
@prisis
prisis deleted the advisor/270-mask-iterator-and-estimate-bytes branch August 2, 2026 09:46
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using our GitHub Discussions tab for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 8, 2026

This branch was previously deployed

1 inactive deployment
benchmarks — 18696285 Deployed Aug 2, 2026 by prisis via Benchmarks #1366
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant