Skip to content

feat(api): add pagination to listRepositories, listUsers, and workspace.list #5969

Open

Description

@ANSHSINGH050404

What problem are you trying to solve?

  • packages/trpc/src/router/integration/github/github.ts:99-117 — returns all repos
  • packages/trpc/src/router/admin/admin.ts:11-14 — returns all users
  • packages/host-service/src/trpc/router/workspace/workspace.ts:40-62 — returns all workspaces

No limit(), no cursor, no pagination. Large organizations get massive single responses.

Proposed solution

Add cursor-based pagination with a default limit of 50 items. Return { items, nextCursor, totalCount }.

Workarounds you've tried

Implemented a local prototype of cursor-based pagination using limit + 1 queries and a cursor based on the last item's ID. This reduces payload size and avoids fetching entire datasets at once. However, the current API contracts don't expose pagination parameters or return pagination metadata, so the implementation can't be used consistently across listRepositories, listUsers, and workspace.list without changing the API.

Activity

  1. github-actions commented on Jul 26, 2026

    @github-actions
    Contributor

    Triage: claims verified, but this is a feature request — no reproduction PR

    I verified the three call-sites. All three are genuinely unbounded — no limit(), no cursor:

    • packages/trpc/src/router/integration/github/github.ts:113-116 — findMany over githubRepositories, ordered only.
    • packages/trpc/src/router/admin/admin.ts:12-14 — findMany over all users.
    • packages/host-service/src/trpc/router/workspace/workspace.ts:41 — ctx.db.select().from(workspaces).all().

    I did not open a reproduction PR: there's no defective behavior to pin down with a failing test. These endpoints return everything because nothing ever asked them not to, so a test asserting "returns all rows" would encode today's intended behavior rather than prove a bug. What follows is the design input I'd want settled before someone implements this.

    There's already a pagination convention in the repo — reuse it

    packages/host-service/src/trpc/router/workspace-creation/procedures/search-branches.ts:35,169 establishes the house pattern: input.limit ?? 50, an opaque offset cursor via decodeCursor/encodeNextCursor, returning { items, nextCursor }. acp-sessions uses the same shape. Worth matching that instead of introducing a new one.

    One deviation to flag: the proposal's totalCount isn't part of the existing convention, and it costs a second COUNT(*) on every page. Suggest omitting it unless a specific UI needs a total.

    Also note listPullRequests already hard-caps at limit: 100 (github.ts:179) — precedent for a cap even without a cursor.

    The three endpoints are not equal risk — I'd split this issue

    Safe to paginate as proposed (1 consumer each, both plain render-the-array UIs):

    • admin.listUsers → apps/admin/src/app/(dashboard)/users/components/UsersTable/UsersTable.tsx:49
    • integration.github.listRepositories → apps/web/src/app/(dashboard-legacy)/integrations/github/components/RepositoryList/RepositoryList.tsx:23

    workspace.list is the problem. It has ~10 consumers spanning desktop, mobile, CLI, SDK, and MCP, and it's part of the public SDK/CLI surface. A default limit of 50 would silently truncate:

    1. packages/sdk/src/resources/workspaces.ts:43 fetches the full array and then filters by search / projectId client-side. With a default page of 50, those filters would only ever see page 1 — superset workspaces list --search foo would return wrong results with no error.
    2. apps/desktop/src/renderer/lib/v1-migration/runV1Migration.ts:250,530 builds a complete workspaceId → projectId map from the full list. Truncation means workspaces past Ship deep links #50 are silently skipped during migration.
    3. packages/mcp-v2/src/tools/workspaces/list.ts:28 and packages/cli/src/lib/host-workspaces/workspacesOnHost.ts:28 pass the raw array through to callers.

    Separately, the motivation in the issue ("large organizations get massive single responses") doesn't really apply here: workspace.list reads from the local host SQLite db — it's bounded by workspaces on one machine, typically tens, and it's a synchronous local read, not a network-scale query.

    Suggested scoping

    • Do: paginate listUsers and listRepositories using the search-branches convention (limit default 50, opaque cursor, { items, nextCursor }), updating their single consumers to useInfiniteQuery.
    • For workspace.list: either leave it alone, or add opt-in limit/cursor that default to unlimited, so the SDK/CLI/MCP/migration contract is preserved. If it must become paginated by default, the SDK's client-side search/projectId filtering has to be pushed server-side first, and runV1Migration needs an explicit paginate-to-exhaustion loop — that's the real work in this issue, and it deserves its own ticket.

    Happy to implement the two low-risk ones if a maintainer confirms that scoping.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions