{"record":{"id":"83e276d56d71f7b8","repo":"mastra-ai/mastra","slug":"page-value-too-large-83e276","errorCode":null,"errorMessage":"page value too large","messagePattern":"page value too large","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/scorer-definitions/inmemory.ts","lineNumber":150,"sourceCode":"      authorId,\n      organizationId,\n      projectId,\n      metadata,\n      status,\n    } = args || {};\n    const { field, direction } = this.parseOrderBy(orderBy);\n\n    // Normalize perPage for query (false → MAX_SAFE_INTEGER, 0 → 0, undefined → 100)\n    const perPage = normalizePerPage(perPageInput, 100);\n\n    if (page < 0) {\n      throw new Error('page must be >= 0');\n    }\n\n    // Prevent unreasonably large page values\n    const maxOffset = Number.MAX_SAFE_INTEGER / 2;\n    if (page * perPage > maxOffset) {\n      throw new Error('page value too large');\n    }\n\n    // Get all scorer definitions and apply filters\n    let scorers = Array.from(this.db.scorerDefinitions.values());\n\n    // Filter by status\n    if (status) {\n      scorers = scorers.filter(scorer => scorer.status === status);\n    }\n\n    // Filter by authorId if provided\n    if (authorId !== undefined) {\n      scorers = scorers.filter(scorer => scorer.authorId === authorId);\n    }\n\n    // Filter by organizationId if provided (multi-tenant scoping)\n    if (organizationId !== undefined) {\n      scorers = scorers.filter(scorer => scorer.organizationId === organizationId);","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/scorer-definitions/inmemory.ts#L132-L168","documentation":"The in-memory scorer-definitions list() throws when page * perPage exceeds Number.MAX_SAFE_INTEGER / 2, guarding offset math against unsafe-integer overflow. It is a deterministic input guard, not a size limit on stored data.","triggerScenarios":"Calling list({ page: 1e15 }) or list({ page: Number.MAX_SAFE_INTEGER }); combining a moderately large page with perPage: false, where perPage normalizes to MAX_SAFE_INTEGER and page * perPage instantly exceeds the cap.","commonSituations":"MAX_SAFE_INTEGER used as a 'get everything' page sentinel; unbounded user-supplied page numbers; composing perPage: false with pagination loops instead of a single call.","solutions":["Fetch everything with list({ page: 0, perPage: false }) instead of a huge page.","Page normally from 0 upward, stopping when a page returns fewer than perPage items.","Clamp page to a sane maximum derived from your expected record count.","Sanitize/validate page numbers coming from external input before calling list()."],"exampleFix":"// before\nawait storage.scorerDefinitions.list({ page: Number.MAX_SAFE_INTEGER });\n// after\nawait storage.scorerDefinitions.list({ page: 0, perPage: false });","handlingStrategy":"validation","validationCode":"const MAX_OFFSET = Number.MAX_SAFE_INTEGER / 2;\nfunction guardPage(page: number, perPage: number): void {\n  if (page * perPage > MAX_OFFSET) throw new RangeError('page value too large for scorer list');\n}","typeGuard":"function paginationIsSafe(page: number, perPage: number): boolean {\n  return Number.isInteger(page) && page >= 0 && page * perPage <= Number.MAX_SAFE_INTEGER / 2;\n}","tryCatchPattern":"try {\n  return await storage.scorerDefinitions.list({ page, perPage });\n} catch (e) {\n  if (e instanceof Error && e.message === 'page value too large') {\n    return storage.scorerDefinitions.list({ page: 0, perPage: false });\n  }\n  throw e;\n}","preventionTips":["Use { page: 0, perPage: false } for 'fetch all'; never a huge page.","Cap user-supplied page numbers before calling list().","With perPage: false, perPage becomes MAX_SAFE_INTEGER — only use page 0 there.","Loop pages sequentially from 0 rather than computing a distant page."],"tags":["storage","pagination","argument-validation","scorer-definitions"],"backgroundTag":"page-value-too-large","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}