Core code treats one query() page as the complete result set#89
Merged
Conversation
Several internal consumers treated a single query() page as the complete result set, even though query() always paginates: the grant prefetch behind ScopedStack.query()/hasGrant() could silently deny an existing grant past the default page, deleteAttachment()'s fallback could leave orphaned _attachment@1 metadata past page one, and the getAttachment() uploader check hardcoded limit: 1 on the in-memory matching path, false-denying access to any upload but the one it happened to fetch. Adds a queryAllPages() helper that cursor-walks to exhaustion (and throws rather than silently truncating past a safety cap), applies it at each site while keeping the contentFieldQuery fast path where a narrowed query already terminates immediately, and brings MemoryAdapter's filter support up to parity with the real adapters so permission-logic tests exercise real predicates instead of an adapter that quietly ignores most filters. Fixes #50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
query()always paginates — an absentlimitreturns one adapter-default page, never every match — but several internal call sites inpackages/core/src/stack.tsassumed a single call was exhaustive:ScopedStack.query()'s grant prefetch andhasGrant()'s non-prefetched path: only the first page of_grant@1records was ever considered, so a grant past page one was silently invisible — legitimate access denied with no error.Stack.deleteAttachment()'s fallback metadata scan: on adapters withoutcontentFieldQuery, only the first page of_attachment@1records was scanned, so metadata beyond page one survived bytes deletion — an orphan.ScopedStack.getAttachment()'s uploader check: hardcodedlimit: 1even on the in-memory-matching path, so it could only ever see one of the requester's uploads. This one didn't need 50+ records to misfire — it false-denies with as few as two uploads.Changes
queryAllPages()— a cursor-walking helper (throwsStackQueryErrorrather than silently truncating past a generous safety cap) — and applied it at the three sites above. LeftmigrateAll()'s existing cursor walk as-is: it interleaves per-page mutation with fetching (already-migrated records naturally drop out of the filter as it goes), so "collect everything first" doesn't fit its access pattern.contentFieldQueryfast path everywhere it applies (a narrowed query already terminates in one page) — the full scan only runs on adapters without that capability.MemoryAdapter(core's test double) up to real filter parity —content,tags,hasAttachment,relatedTo,appId, date ranges, and payload-awaredissociate()— mirroringsqlite-shared'sbuildWhereClause, so permission-logic tests exercise real predicates instead of an adapter that quietly ignored most filters.query()always paginates" rule indocs/spec.md§Queries — it was previously unstated, which is how the ambiguity crept in.Test plan
_grantrecords) is still honored;deleteAttachment()leaves no orphaned metadata when the match is beyond the first page (>50 records); a newScopedStack.getAttachmenttest suite (previously uncovered) including the n=2 uploader-access regression.stack.tsfix and confirmed all three failed with the expected symptoms) and passes with it restored.pnpm -r buildpnpm -r typecheckpnpm -r lintpnpm -r test(all packages green)pnpm format:checkGenerated by Claude Code