Skip to content

fix(orm): read compiled index-union probes at every stream site - #425

Merged
zbeyens merged 6 commits into
mainfrom
fix/orm-index-union-cursor-pagination
Aug 26, 2026
Merged

zbeyens merged 6 commits into
mainfrom
fix/orm-index-union-cursor-pagination

Conversation

@MikeyZhang75

@MikeyZhang75 MikeyZhang75 commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator
  • Auto release

🐛 Fixes #415

🧭 Task plan: docs/plans/415-restore-compiled-probefilters-at-orm-stream-sites.md

🟢 95-100% confidence

Phase 🧪 Tests 🌐 Browser
Reproduced 🔴 6 original planner regressions plus cursor-boundary regressions ➖ N/A
Verified 🟢 13/13 index-union tests; 157 focused pass / 1 skip; bun check exit 0 ➖ N/A

✅ Outcome

Compiled index-union probes reach every ORM stream construction path. Cursor pagination reads the planned index ranges, preserves normal cursor direction and bounds, excludes disjoint merged ranges without duplicates, and retains equality-prefix metadata when a narrowed child is empty.

Rejected unions keep the original predicate, require maxScan under strict mode, and use the bounded unanchored scan fallback instead of silently walking a rangeless plan index.

🏗️ Design

One CompiledQueryPlan flows to every plan consumer. _buildPlanStream owns the precedence ladder and reports whether the read is bounded by an accepted probe union. Advanced cursor callers preserve that result, while OrderedStreamQuery.narrow closes empty intersections without discarding merge metadata.

Probe unions use mergedStream only when the requested order is serviceable. They fall back to a budgeted scan when the requested order is unsupported, the union exceeds MAX_INDEX_UNION_PROBES (64), or schema metadata is unavailable.

⚠️ Caveat

With no orderBy, an accepted index-union page follows its index order. Add orderBy: { createdAt: 'desc' } when creation order is required. maxScan on a K-probe union can overshoot by up to K−1 reads while the merged stream fills one row per probe; K is capped at 64.

🧪 Verified

bun check; bun typecheck 5/5; bun --cwd packages/kitcn build; fixture sync/check 8/8; intent validation/staleness; 157 focused tests passed with 1 skipped; exact-head P1 autoreview clean at 0.87 confidence.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

_toConvexQuery compiled probeFilters; every stream builder dropped them via a
narrowed queryConfig type. Cursor-paginated in() fell back to a full table scan
and required maxScan.

One CompiledQueryPlan type + _buildPlanStream now own the ladder: compiled index
union, compiled index range, caller withIndex, order index, scan. Union merges
probes on an index-key suffix inside the eq-pinned run, declines when the order
is not servable or past 64 probes.
@changeset-bot

changeset-bot Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1c292f9

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

This PR includes changesets to release 2 packages
Name Type
kitcn Minor
@kitcn/resend Minor

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@vercel

vercel Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
better-convex Ready Ready Preview Aug 26, 2026 3:33am

Request Review

@zbeyens

zbeyens commented Aug 26, 2026

Copy link
Copy Markdown
Member

Autoclosure complete for exact head 1c292f9f0aa6ddcf6aae7bd17fe9a848cf25d574 against main baseline 0e3a2214e8e1037b323e603f19c2df89b0d95602.

  • Per-PR task evidence: docs/plans/415-restore-compiled-probefilters-at-orm-stream-sites.md exists at this head, names PR fix(orm): read compiled index-union probes at every stream site #425, and its completion checker passes.
  • Source-sync P1s fixed: normal no-orderBy endCursor direction; disjoint merged-range reopening/duplicates; empty-child equality metadata; rejected-union strict maxScan enforcement and unanchored fallback.
  • Focused proof: 157 passed / 1 skipped across index-union pagination, pagination, pipeline, where filtering, and both stream suites; source-first typecheck 5/5; package build; fixture sync/check 8/8; intent validation/staleness; lint clean.
  • Full local gate: bun check passed on the final runtime implementation, including fixture and authenticated runtime lanes.
  • Exact-head review: P1 autoreview clean, confidence 0.87; secret scan clean.
  • Hosted exact-head proof: CI passed; Vercel deployment Ready; all required checks settled with 0 failures and 0 pending.
  • Exact-head identity: local HEAD = fetched refs/pull/425/head = live PR OID = 1c292f9f0aa6ddcf6aae7bd17fe9a848cf25d574.

Final feedback inventory: 0 review threads, 0 review bodies, 3 informational issue comments, 0 deferred items.

Terminal verdict: ready to squash-merge. No unresolved P1 or P2 feedback.

This branch was successfully deployed

1 active deployment
Preview — 1c292f9f Deployed Aug 26, 2026 by vercel[bot]
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.

ORM: the compiled plan's probeFilters is dropped at every stream site — cursor-paginated in() degrades to a full table scan

2 participants