Remove 2-part cursor fallback in decodeCursor() - #164
Merged
Conversation
decodeCursor() silently accepted a legacy 2-part (value|id) cursor shape and coerced it to createdAt, which meant a corrupt or truncated cursor could be accepted with a fabricated sort field instead of being rejected. encodeCursor() has only ever emitted 3-part cursors, so the fallback was unreachable by construction and contradicted the documented contract that malformed cursors throw StackQueryError. Fixes #152
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
decodeCursor()inpackages/sqlite-shared/src/cursor.tsaccepted a legacy 2-part (value|id) cursor shape and coerced it tocreatedAt.encodeCursor()has only ever emitted 3-part cursors, so this branch was unreachable by construction and, in practice, only served to weaken validation — a corrupt or truncated cursor that happened to decode to two|-separated parts was silently accepted with a fabricated sort field instead of being rejected.StackQueryErrorotherwise. The now-deadfield === undefined || value === undefined || id === undefinedguard was removed along with it.packages/sqlite-shared/tests/cursor.test.ts: replacedaccepts the legacy 2-part (value|id) format as createdAtwith a test asserting a 2-part cursor throwsStackQueryError.Closes #152
Spec
No behavior change relative to the documented contract —
docs/spec/data-model.md§ Sorting and pagination already states that a cursor which can't be decoded is a structurally malformed request that throwsStackQueryError→ 400. This change brings the implementation in line with that existing spec text rather than changing it.Verification
All green across the monorepo (sqlite-shared, record-adapter-sqlite, adapter-api, adapter-local, blob-adapter-disk, wire-types, core).
Notes for reviewers
Both SQLite-backed adapters share this codec via
@haverstack/sqlite-shared, so the fix lands in one place and applies to both. Cursors are opaque and single-session by contract, so tightening the decoder has no data-migration implications.Generated by Claude Code