Skip to content

Add pagination to GET /api/workflows (issue #3435) - #10526

Open
Bhanubathini2002 wants to merge 5 commits into
simstudioai:stagingfrom
Bhanubathini2002:fix/workflows-pagination-3435
Open

Bhanubathini2002 wants to merge 5 commits into
simstudioai:stagingfrom
Bhanubathini2002:fix/workflows-pagination-3435

Conversation

@Bhanubathini2002

Copy link
Copy Markdown

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: null on the last page. The page comes from one ordered
SQL read on the existing position keyset (sortOrder, createdAt, id) via
resumeKeyset/keysetPage, and the cursor is stamped with the sort and
filters, so replaying it under a different scope is a 400.

listWorkflowsForUser keeps its exact behavior (the sidebar prefetch
calls 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 most
50 rows per call for large workspaces.

Tests: 5 new cases in app/api/workflows/route.test.ts (last page, cap at
limit 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.

@vercel

vercel Bot commented Dec 1, 2026

Copy link
Copy Markdown

@Bhanubathini2002 is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · The PR appears safe to merge, with a non-blocking fix needed for invalid cursor keys returning 500.RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P2 Bad cursors return server errors ▶

Summary

Adds cursor pagination to GET /api/workflows, with a default page size of 50 and a maximum of 100.

  • Workflow lists now return pages with a cursor for the next page.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[GET /api/workflows] --> B[Parse limit and cursor]
  B --> C[Check cursor sort and filters]
  C --> D[Check user and workspace access]
  D --> E[Read limit + 1 rows after cursor]
  E --> F[Return data and nextCursor]
Loading

Reviews (1) · Last reviewed commit: "Add pagination to GET /api/workflows (is..." · Reviewed by Greptile

Comment on lines +92 to +98
const page = await listWorkflowsPageForUser({
userId,
workspaceId,
scope,
limit,
cursorKeys,
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant