Skip to content

Fix Convex 16MB bytes read limit by switching all paginated pages to cursor-based pagination #124

Closed

Description

@larryro

Problem Statement

Multiple paginated queries hit Convex's 16MB bytes read limit because they collect ALL documents before slicing for pagination. The error is currently occurring in listExecutionsPaginated but the same pattern exists in other queries.

Error:

Uncaught Error: Too many bytes read in a single function execution (limit: 16777216 bytes)

Affected Queries

Query File Status
listExecutionsPaginated convex/model/wf_executions/list_executions_paginated.ts Currently failing
getProducts convex/model/products/get_products.ts At risk (3510+ products)
getDocuments convex/model/documents/get_documents.ts At risk

All use the same anti-pattern:

const allItems = [];
for await (const item of query) {
  allItems.push(item);  // Collects ALL items
}
const total = allItems.length;
const paginated = allItems.slice(offset, offset + pageSize);

Root Cause

  • Offset-based pagination requires knowing total count
  • To get total count, queries load ALL matching documents
  • Large documents (executions with variables, workflowConfig, etc.) exceed 16MB limit
  • Even smaller documents will fail eventually as data grows

Proposed Solution

Switch to cursor-based pagination using Convex's native .paginate() method:

  • Uses early termination - stops as soon as numItems + 1 are found
  • Never reads the entire dataset
  • Scales infinitely regardless of total data volume

UI will change from page numbers to infinite scroll ("Load more" pattern).

Affected Components

Phase 1: Fix Executions (Critical - Currently Broken)

  • convex/model/wf_executions/list_executions_paginated.ts - Add cursor-based query
  • convex/model/wf_executions/types.ts - Add cursor args interface
  • convex/model/wf_executions/validators.ts - Add cursor args validator
  • convex/wf_executions.ts - Export new query
  • components/ui/data-table/data-table.tsx - Add infinite scroll support
  • executions/components/executions-table.tsx - Switch to cursor pagination
  • executions/page.tsx - Update preload

Phase 2: Fix Products (Preventive)

  • convex/model/products/get_products.ts - Add cursor-based query
  • products/components/product-table.tsx - Switch to cursor pagination

Phase 3: Fix Documents (Preventive)

  • convex/model/documents/get_documents.ts - Add cursor-based query
  • documents/components/document-table.tsx - Switch to cursor pagination

Acceptance Criteria

  • No 16MB bytes read errors regardless of data volume
  • Executions, Products, Documents pages load quickly with large datasets
  • Filters continue to work correctly
  • Infinite scroll UI allows loading more results
  • SSR preloading still works

🤖 Generated with Claude Code

Activity

  1. larryro commented on Jan 8, 2026

    @larryro
    ContributorAuthor

    Implementation Plan

    Step 1: Create New Cursor-Based Query Function

    File: convex/model/wf_executions/list_executions_paginated.ts

    Add listExecutionsCursor function using the existing paginateWithFilter helper for early termination.

    Step 2: Add New Types and Validators

    • types.ts: Add ListExecutionsCursorArgs interface
    • validators.ts: Add listExecutionsCursorArgsValidator

    Step 3: Export New Query

    File: convex/wf_executions.ts - Export listExecutionsCursor query

    Step 4: Add Infinite Scroll to DataTable

    File: components/ui/data-table/data-table.tsx - Add infiniteScroll prop

    Step 5: Update Frontend Components

    • executions-table.tsx: Switch to useCursorPaginatedQuery
    • page.tsx: Update preload

    Files to Modify

    File Changes
    convex/model/wf_executions/list_executions_paginated.ts Add cursor function
    convex/model/wf_executions/types.ts Add args interface
    convex/model/wf_executions/validators.ts Add validator
    convex/wf_executions.ts Export new query
    components/ui/data-table/data-table.tsx Add infinite scroll
    executions/components/executions-table.tsx Switch to cursor pagination
    executions/page.tsx Update preload

    Testing Strategy

    • Test with 10,000+ executions - no errors
    • Apply filters - should work correctly
    • Click "Load more" - should fetch next page
    • Monitor Convex dashboard - bounded bytes read

    Generated with Claude Code

  2. changed the title [-]Fix Convex 16MB bytes read limit in listExecutionsPaginated by switching to cursor-based pagination[/-] [+]Fix Convex 16MB bytes read limit by switching all paginated pages to cursor-based pagination[/+] on Jan 8, 2026
  3. larryro commented on Jan 8, 2026

    @larryro
    ContributorAuthor

    Updated Implementation Plan

    Phase 1: Shared Infrastructure

    • Add infiniteScroll prop to DataTable component

    Phase 2: Fix Executions (Critical)

    • Add listExecutionsCursor function using paginateWithFilter
    • Add ListExecutionsCursorArgs interface
    • Add listExecutionsCursorArgsValidator
    • Export listExecutionsCursor query
    • Update executions-table.tsx to use useCursorPaginatedQuery
    • Update executions/page.tsx preload

    Phase 3: Fix Products

    • Add getProductsCursor function using paginateWithFilter
    • Add GetProductsCursorArgs interface
    • Export getProductsCursor query
    • Update product-table.tsx to use useCursorPaginatedQuery

    Phase 4: Fix Documents

    • Add getDocumentsCursor function using paginateWithFilter
    • Add GetDocumentsCursorArgs interface
    • Export getDocumentsCursor query
    • Update document-table.tsx to use useCursorPaginatedQuery

    Files to Modify (14 total)

    Phase File Changes
    1 components/ui/data-table/data-table.tsx Add infiniteScroll prop
    2 convex/model/wf_executions/list_executions_paginated.ts Add listExecutionsCursor
    2 convex/model/wf_executions/types.ts Add cursor args interface
    2 convex/model/wf_executions/validators.ts Add cursor args validator
    2 convex/wf_executions.ts Export listExecutionsCursor
    2 executions/components/executions-table.tsx Switch to cursor pagination
    2 executions/page.tsx Update preload
    3 convex/model/products/get_products.ts Add getProductsCursor
    3 convex/model/products/types.ts Add cursor args interface
    3 convex/products.ts Export getProductsCursor
    3 products/components/product-table.tsx Switch to cursor pagination
    4 convex/model/documents/get_documents.ts Add getDocumentsCursor
    4 convex/model/documents/types.ts Add cursor args interface
    4 convex/documents.ts Export getDocumentsCursor
    4 documents/components/document-table.tsx Switch to cursor pagination

    🤖 Generated with Claude Code

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions