Skip to content

fix(store): keep in-memory task pages disjoint - #408

Open
Yi-111-a wants to merge 1 commit into
google:mainfrom
Yi-111-a:fix/stable-memory-task-pages
Open

Yi-111-a wants to merge 1 commit into
google:mainfrom
Yi-111-a:fix/stable-memory-task-pages

Conversation

@Yi-111-a

Copy link
Copy Markdown

Why

MemoryStore.ListTasks builds its slice by ranging a Go map, then applies offset/limit. Map iteration order is randomized on every call, so two pages are not slices of the same sequence.

With 8 tasks and a page size of 4, the first call returned task-01 and the next page returned task-01 again. Tasks that sort into the other page are dropped. Redis listing is ordered by index score, so this only affects the in-memory store used for tests and single-node setups.

Fix

Sort the filtered tasks by atespace, then name, before slicing. Stored records are not modified.

Verification

Before the sort, go test ./internal/store/memory -run TestListTasksPagesDoNotOverlap -count=1 failed:

attempt 0: task "task-01" appears on both pages

After the sort, go test ./internal/store/memory -count=1 passes.

ListTasks ranged a map and then sliced it. Each call walks the map in a new order, so a later page can repeat names from an earlier page and drop others. Sort by atespace and name before applying offset and limit.
@google-cla

google-cla Bot commented Sep 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

1 participant