Skip to content

fix(memory): PartiQL pages continue after the last item the page read - #120

Merged
kalaspuff merged 1 commit into
issues-stack/5-atomic-table-updatesfrom
issues-stack/6-partiql-next-token
Oct 31, 2026
Merged

kalaspuff merged 1 commit into
issues-stack/5-atomic-table-updatesfrom
issues-stack/6-partiql-next-token

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What and why

PartiQL SELECT pages of the in-memory DynamoDB continued at an offset into the list of results (NextToken was offset:N), not after the last item the page read. With Limit=2, page 1 returned sk 0 and 1; delete those two rows, and page 2 returned sk 4 and 5, where DynamoDB returns 2 and 3. Rows inserted before the position were returned again. A "select a page, delete it, continue" cleanup loop missed items on the in-memory backend. last_evaluated_key was never set on SELECT pages either.

NextToken now encodes the key of the last item the page evaluated: the table key, plus the index key for index reads, as LastEvaluatedKey holds it. The page also returns that key as last_evaluated_key, and the next page continues after its position in the read's order (the table's or index's key order, or the ORDER BY order), wherever the item is now. A token that does not decode into a key of the read raises ValidationException: Invalid NextToken, as before.

Verified with a memory backend test that pages through a table, a local index, a global index, a scan and an ORDER BY ... DESC read, deletes each first page's rows before the second page and writes them again before the third, and checks last_evaluated_key and invalid tokens; and a Python integration test of the cleanup loop on the in-memory backend and MiniStack. Both fail without the fix. make check passes.

Fixes #91

Checklist

  • Tests cover the change (in-memory backend and MiniStack)
  • Docs updated (changelog)
  • make check passes locally (lint, types, clippy, consistency, tests)
  • Breaking change? No

fctl session


Note

Low risk. It changes only how the in-memory test backend pages PartiQL SELECT results; the AWS adapter and the Python API are untouched, and the existing page tests and CI pass on both backends.

What it does. PartiQL SELECT pages of the in-memory DynamoDB used to continue at an offset into the result list, so deleting a page's rows before asking for the next page skipped rows, and inserting rows before the position repeated them. NextToken now encodes the key of the last item the page evaluated (the table key, plus the index key for index reads), the page also returns it as last_evaluated_key, and the next page continues after that key in the read's order, including ORDER BY reads. A token that does not decode into a key of the read still raises Invalid NextToken.

Token format. The in-memory NextToken changes from offset:N to a key:... string, so tokens saved from an earlier run of the in-memory backend are refused with Invalid NextToken.

fctl review's first look at 0b4d04c · 4 files, +201 −24 · Review agent settings

SELECT pages of the in-memory backend continued at an offset into the
list of results (NextToken "offset:N"), so rows deleted before the
position made the next page skip rows and rows inserted before it were
returned again: a "select a page, delete it, continue" loop missed
items. LastEvaluatedKey was never set either.

NextToken now encodes the key of the last item the page evaluated (the
table key, and the index key for index reads), the page returns it as
last_evaluated_key, and the next page continues after that position in
the read's order, ORDER BY included.

Fixes #91

Co-authored-by: Carl Oscar Aaro <[email protected]>
@kalaspuff
kalaspuff added this pull request to stack #124 October 31, 2026 01:30
@kalaspuff
kalaspuff merged commit 03c9196 into main Oct 31, 2026
22 checks passed
@kalaspuff
kalaspuff deleted the issues-stack/6-partiql-next-token branch October 31, 2026 01:34
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.

In-memory PartiQL: NextToken is a list offset, so pages skip or repeat rows when items change

1 participant