feat(api): add sort order to GET /v2/sandboxes#3287
Conversation
❌ 11 Tests Failed:
View the top 3 failed test(s) by shortest run time
View the full list of 1 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Code Review
This pull request introduces support for sorting sandboxes by start time in both ascending and descending order (defaulting to descending) in the list sandboxes endpoint. It updates the OpenAPI specification, database queries, pagination logic, and in-memory sorting/filtering to support the new order query parameter. Additionally, it truncates the pagination timestamp to microsecond precision to ensure consistency between running sandboxes and database snapshots. Feedback suggests validating the order query parameter against its enum values to return a bad request error for invalid inputs instead of silently defaulting to descending.
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.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2fd3a4014
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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.
The bare OR cursor predicate never became an index condition, so every deep ascending page rescanned the team's index range from the oldest row (~30s at 43M rows deep on the largest team). Adding a redundant AND-ed >= bound lets the planner seek directly to the cursor (<1ms, verified with EXPLAIN ANALYZE). Also add the active_envs join that the descending query gained on main after the original PR, so both directions exclude soft-deleted envs.
e000c7c to
eeb5ff7
Compare
What
Adds an
order=asc|descquery param toGET /v2/sandboxesso clients can request ascending or descending order by sandbox start time. Defaults todesc, so existing callers are unaffected.Revives #3107 (rebased on current main). Motivated by the dashboard sandbox list, which otherwise sorts only the client-side loaded pages.
Changes
idx_snapshots_team_time_idindex via a newGetSnapshotsWithCursorAsckeyset query.GetSandboxesis untouched.Test
go test ./internal/utils/... ./internal/handlers/...and DB-backedpackages/db/pkg/tests/snapshots/...pass;golangci-lintclean.