Repository navigation
Add pagination to GET /api/workflows (issue #3435) - #10526
Bhanubathini2002 wants to merge 5 commits into
Conversation
Added v2 pagination fields to workflow list query schema.
|
@Bhanubathini2002 is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
[Medium impact] The change reaches clients that list workflows through the existing endpoint. The PR appears safe to merge, with a non-blocking fix needed for invalid cursor keys returning 500. Findings
SummaryAdds cursor pagination to
|
| const page = await listWorkflowsPageForUser({ | ||
| userId, | ||
| workspaceId, | ||
| scope, | ||
| limit, | ||
| cursorKeys, | ||
| }) |
There was a problem hiding this comment.
Bad cursors return server errors
A cursor with matching sort and filter stamps but an invalid keys array returns 500 instead of 400. readSortedCursor checks only the outer fields. resumeKeyset checks the keys inside listWorkflowsPageForUser, where its OrchestrationError reaches the generic catch. Clients may retry a request that cannot succeed. Handle that validation error around the paged read too.
Fixes #3435
GET /api/workflows fetched every workflow in the workspace (or every
workspace the user can access) with no LIMIT, so large workspaces dumped
thousands of rows into server memory and a giant JSON payload at once.
The endpoint now pages exactly like the v2 workflow list:
limit(1-100,default 50) and an opaque keyset
cursor, response{ data, nextCursor }with
nextCursor: nullon the last page. The page comes from one orderedSQL read on the existing position keyset (sortOrder, createdAt, id) via
resumeKeyset/keysetPage, and the cursor is stamped with the sort andfilters, so replaying it under a different scope is a 400.
listWorkflowsForUserkeeps its exact behavior (the sidebar prefetchcalls it directly); the paged read is a new
listWorkflowsPageForUser.Follow-up, not in this PR: the dashboard caller of GET /api/workflows
should follow
nextCursor— with the default limit it now sees at most50 rows per call for large workspaces.
Tests: 5 new cases in
app/api/workflows/route.test.ts(last page, cap atlimit with a cursor, cursor replayed under another scope → 400, undecodable
cursor → 400, limit outside 1-100 → 400). All 5 fail on the pre-fix code.