feat(api): add sort order to GET /v2/sandboxes#3107
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for sorting sandboxes in ascending order by start time. It updates the pagination configuration, the sandbox list handler, and database queries to support an ascending order parameter, including a new SQL query for ascending keyset pagination. Unit tests and OpenAPI specifications have been updated accordingly. There are no review comments, and we have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
7c0a1fe to
b8400ef
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
b3a8bf1 to
7b28403
Compare
mishushakov
left a comment
There was a problem hiding this comment.
prefer enums to booleans - instead of ascending, it should be direction
type OrderDirection string
const (
Asc OrderDirection = "asc"
Desc OrderDirection = "desc"
)06dceff to
b9023d5
Compare
I changed to enum, but we use an |
9a208e8 to
dcb8801
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 927fc44b3a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| Alias: info.Alias, | ||
| SandboxID: info.SandboxID, | ||
| StartedAt: info.StartTime, | ||
| StartedAt: startedAt, |
There was a problem hiding this comment.
Preserve public startedAt precision
When listing running or pausing sandboxes, this now returns the microsecond-truncated cursor value as the public startedAt, so both /sandboxes and /v2/sandboxes can disagree with the sandbox detail endpoint, which still returns the original sbx.StartTime. The truncation is useful for keyset pagination, but it should be limited to PaginationTimestamp/cursor comparisons so callers do not lose the actual start timestamp in list responses.
Useful? React with 👍 / 👎.
Add an order=asc|desc query param to GET /v2/sandboxes so clients can request ascending or descending order by sandbox start time (defaults to desc, the previous hardcoded behavior). - Ascending is implemented as the exact reverse of the existing keyset order (started_at ASC, sandbox_id DESC), so it maps onto a backward scan of the existing idx_snapshots_team_time_id index - no new index/migration. - Add a direction-aware first-page cursor, ascending variants of the in-memory sort and cursor filter, and a GetSnapshotsWithCursorAsc keyset query. - Thread the direction through the v2 handler; the legacy v1 list is untouched. - Tests: ascending default cursor, sort + cursor-filter tie-breaks, and a DB-backed test asserting oldest-first ordering and gap-free pagination.
927fc44 to
37e707b
Compare
What
Adds an
order=asc|descquery param toGET /v2/sandboxesso clients can request ascending or descending order by sandbox start time. Defaults todesc(the previous hardcoded behavior), so existing callers are unaffected.Motivated by the dashboard sandbox list, which previously sorted only the pages already loaded client-side. Companion frontend PR: e2b-dev/dashboard#475.
Changes
started_at ASC, sandbox_id DESC), which maps onto a backward scan of the existingidx_snapshots_team_time_id (team_id, sandbox_started_at DESC, sandbox_id)index.nowfor desc, zero-time for asc) via a newAscendingflag onPaginationConfig.SortPaginatedSandboxes) and cursor filter (FilterBasedOnCursor), plus a newGetSnapshotsWithCursorAscsqlc keyset query.GetV2Sandboxes; the legacy v1GetSandboxesis untouched.api.gen.go(oapi-codegen) and the sqlc query.Scope
Only
started_atordering (asc/desc) — what the dashboard sorts. Sorting by cpu/memory/disk is intentionally out of scope (those live onenv_buildsand would need new indexes + denormalization).Test
go test ./internal/utils/...— ascending default cursor, sort + cursor-filter tie-breaks.go test ./pkg/tests/snapshots/...— DB-backed:GetSnapshotsWithCursorAscreturns oldest-first and paginates without gaps/overlaps.GET /v2/sandboxes?order=ascreturns oldest-first;EXPLAINshows a backward index scan (no Sort node) at scale.