Skip to content

fix(e2b): stabilize pagination for duplicate timestamps#563

Open
chacha923 wants to merge 1 commit into
openkruise:masterfrom
chacha923:fix/pagination-duplicate-token
Open

fix(e2b): stabilize pagination for duplicate timestamps#563
chacha923 wants to merge 1 commit into
openkruise:masterfrom
chacha923:fix/pagination-duplicate-token

Conversation

@chacha923

Copy link
Copy Markdown

What this PR does

Fixes pagination for GET /v2/sandboxes and snapshot listing when multiple objects share the same timestamp sort key.

The previous cursor only stored the timestamp of the last returned item. Since claim timestamps and checkpoint creation timestamps can collide, the next page searched for the first item strictly after that timestamp and skipped remaining objects with the same timestamp.

This PR adds an optional stable cursor to the internal paginator. When a unique key is configured, pagination now sorts and resumes by (sort key, unique key), encodes the cursor as an opaque base64 JSON token, and keeps raw sort-key tokens compatible for existing clients.

Changes

  • Add optional GetUniqueKey support to pkg/utils/pagination.Paginator.
  • Use sandbox ID as the tiebreaker for sandbox listing.
  • Use checkpoint ID as the tiebreaker for snapshot listing, with namespace/name fallback.
  • Add regression coverage for duplicate sandbox claim timestamps and duplicate checkpoint creation timestamps.

Tests

go test ./pkg/utils/pagination
go test ./pkg/sandbox-manager -run 'TestSandboxManager_ListSandboxes|TestSandboxManager_ListCheckpoints'
go test ./pkg/servers/e2b -run 'TestListSandboxes_Pagination|TestListSandboxes_PaginationDuplicateClaimTime|TestListSnapshots'
go test ./pkg/utils/pagination ./pkg/sandbox-manager ./pkg/servers/e2b
git diff --check

Fixes #439

@kruise-bot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign zmberg for approval by writing /assign @zmberg in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kruise-bot

Copy link
Copy Markdown

Welcome @chacha923! It looks like this is your first PR to openkruise/agents 🎉

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.75%. Comparing base (c1cb28c) to head (42ca70c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #563      +/-   ##
==========================================
+ Coverage   79.67%   79.75%   +0.07%     
==========================================
  Files         194      194              
  Lines       13784    13836      +52     
==========================================
+ Hits        10983    11035      +52     
  Misses       2403     2403              
  Partials      398      398              
Flag Coverage Δ
unittests 79.75% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Use an opaque cursor with both the sort key and a unique object key when listing sandboxes and snapshots.

Keep raw sort-key tokens compatible for existing clients.

Fixes openkruise#439

Signed-off-by: zhuangzhewei <zhuangzhewei09@dingtalk.com>
@chacha923 chacha923 force-pushed the fix/pagination-duplicate-token branch from c4a8a7c to 42ca70c Compare June 22, 2026 12:47
@chacha923 chacha923 marked this pull request as ready for review June 22, 2026 13:37
@kruise-bot kruise-bot requested a review from zmberg June 22, 2026 13:37
@chacha923

Copy link
Copy Markdown
Author

Hello @furykerry @AiRanthem @zmberg ,
I wanted to politely follow up on this PR. The CI checks are passing, and I believe it is ready for review. I would appreciate any feedback whenever you have the opportunity.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Listing sandboxes can silently hide some of them when they share the same claim time

2 participants