Skip to content

Conversation

@dobrac
Copy link
Contributor

@dobrac dobrac commented Sep 16, 2025

Fix running sandboxes pagination. The running sandboxes were not sorted when limit was applied, causing missing sandboxes in the result set and improper token pagination.

@dobrac dobrac self-assigned this Sep 16, 2025
@dobrac dobrac added the bug Something isn't working label Sep 16, 2025
@linear
Copy link

linear bot commented Sep 16, 2025

@dobrac dobrac marked this pull request as ready for review September 16, 2025 10:32
@dobrac dobrac force-pushed the pagination-of-running-sandboxes-ends-prematurely-e2b-3011 branch 2 times, most recently from 0902b6a to 41427ad Compare September 16, 2025 10:36
@dobrac dobrac force-pushed the pagination-of-running-sandboxes-ends-prematurely-e2b-3011 branch from 41427ad to deeb029 Compare September 16, 2025 10:37
Copy link
Member

@jakubno jakubno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be more error prone to sort in the filter based on cursor function?

@dobrac dobrac requested a review from jakubno September 16, 2025 11:26
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Sandbox Pagination Fails Due to Premature Filtering

Pagination is incorrect because cursor filtering is applied to individual sandbox lists before the final merge and sort. Also, paused sandboxes are prematurely limited at the database level, which can exclude them from the final paginated results.

packages/api/internal/handlers/sandboxes_list.go#L162-L180

// Filter based on cursor
runningSandboxList = utils.FilterBasedOnCursor(runningSandboxList, cursorTime, cursorID)
sandboxes = append(sandboxes, runningSandboxList...)
}
if slices.Contains(states, api.Paused) {
pausedSandboxList, err := a.getPausedSandboxes(ctx, team.ID, runningSandboxesIDs, metadataFilter, limit, cursorTime, cursorID)
if err != nil {
zap.L().Error("Error getting paused sandboxes", zap.Error(err))
a.sendAPIStoreError(c, http.StatusInternalServerError, "Error getting paused sandboxes")
return
}
pausingSandboxList := instanceInfoToPaginatedSandboxes(sandboxesInCache[instance.StatePausing])
pausingSandboxList = utils.FilterSandboxesOnMetadata(pausingSandboxList, metadataFilter)
pausingSandboxList = utils.FilterBasedOnCursor(pausingSandboxList, cursorTime, cursorID)

Fix in Cursor Fix in Web


@dobrac
Copy link
Contributor Author

dobrac commented Sep 16, 2025

Bug: Sandbox Pagination Fails Due to Premature Filtering

Pagination is incorrect because cursor filtering is applied to individual sandbox lists before the final merge and sort. Also, paused sandboxes are prematurely limited at the database level, which can exclude them from the final paginated results.

packages/api/internal/handlers/sandboxes_list.go#L162-L180

// Filter based on cursor
runningSandboxList = utils.FilterBasedOnCursor(runningSandboxList, cursorTime, cursorID)
sandboxes = append(sandboxes, runningSandboxList...)
}
if slices.Contains(states, api.Paused) {
pausedSandboxList, err := a.getPausedSandboxes(ctx, team.ID, runningSandboxesIDs, metadataFilter, limit, cursorTime, cursorID)
if err != nil {
zap.L().Error("Error getting paused sandboxes", zap.Error(err))
a.sendAPIStoreError(c, http.StatusInternalServerError, "Error getting paused sandboxes")
return
}
pausingSandboxList := instanceInfoToPaginatedSandboxes(sandboxesInCache[instance.StatePausing])
pausingSandboxList = utils.FilterSandboxesOnMetadata(pausingSandboxList, metadataFilter)
pausingSandboxList = utils.FilterBasedOnCursor(pausingSandboxList, cursorTime, cursorID)

Fix in Cursor Fix in Web

I don't think this comment is correct

@dobrac dobrac requested a review from jakubno September 16, 2025 14:39
@dobrac dobrac merged commit 7c269b4 into main Sep 16, 2025
26 checks passed
@dobrac dobrac deleted the pagination-of-running-sandboxes-ends-prematurely-e2b-3011 branch September 16, 2025 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants