{"record":{"id":"b7a5e2544548a8ca","repo":"mastra-ai/mastra","slug":"durable-agent-list-active-runs-invalid-per-page","errorCode":"DURABLE_AGENT_LIST_ACTIVE_RUNS_INVALID_PER_PAGE","errorMessage":"DurableAgent \"${this.name}\" listActiveRuns() requires perPage to be a positive integer.","messagePattern":"DurableAgent \"(.+?)\" listActiveRuns\\(\\) requires perPage to be a positive integer\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"warning","filePath":"packages/core/src/agent/durable/durable-agent.ts","lineNumber":2903,"sourceCode":"   * (see {@link DurableAgent.recoverActiveRuns} and workflow `restart`).\n   *\n   * Requires persistent workflow storage. Filters `agentId` against the\n   * persisted `DurableAgenticWorkflowInput.agentId`, so runs started by other\n   * durable agents sharing the same storage are not surfaced.\n   *\n   * @example\n   * ```typescript\n   * const { runs } = await durableAgent.listActiveRuns({ resourceId });\n   * for (const run of runs) {\n   *   await durableAgent.recoverActiveRuns({ runId: run.runId });\n   * }\n   * ```\n   */\n  async listActiveRuns(options: DurableAgentListActiveRunsOptions = {}): Promise<DurableAgentListActiveRunsResult> {\n    const { threadId, resourceId, fromDate, toDate, perPage, page } = options;\n\n    if (perPage !== undefined && (!Number.isInteger(perPage) || perPage <= 0)) {\n      throw new MastraError({\n        id: 'DURABLE_AGENT_LIST_ACTIVE_RUNS_INVALID_PER_PAGE',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        text: `DurableAgent \"${this.name}\" listActiveRuns() requires perPage to be a positive integer.`,\n        details: { agentName: this.name, perPage },\n      });\n    }\n    if (page !== undefined && (!Number.isInteger(page) || page < 0)) {\n      throw new MastraError({\n        id: 'DURABLE_AGENT_LIST_ACTIVE_RUNS_INVALID_PAGE',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        text: `DurableAgent \"${this.name}\" listActiveRuns() requires page to be a non-negative integer.`,\n        details: { agentName: this.name, page },\n      });\n    }\n\n    const workflowsStore = await this.#mastra?.getStorage()?.getStore('workflows');","sourceCodeStart":2885,"sourceCodeEnd":2921,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/durable/durable-agent.ts#L2885-L2921","documentation":"listActiveRuns() validates its pagination options: if perPage is provided it must be a positive integer. Otherwise MastraError DURABLE_AGENT_LIST_ACTIVE_RUNS_INVALID_PER_PAGE (category USER) is thrown at durable-agent.ts:2903. Omitting perPage entirely is allowed.","triggerScenarios":"Passing perPage: 0, a negative number, a float like 10.5, NaN, or a string from a query param; deriving perPage from user input without parsing; computing perPage via arithmetic that yields a non-integer.","commonSituations":"Reading perPage from req.query (?perPage=20) and passing the string through; UI sending perPage=0 for 'show all'; off-by-one arithmetic producing 0 on the first page; JSON payloads with null coerced unexpectedly.","solutions":["Coerce and validate before calling: Number.isInteger(perPage) && perPage > 0, otherwise omit the option or clamp to a sane default.","Parse query-string values with Number()/parseInt before passing them.","Treat 0/negative as 'use the default' by omitting perPage instead of sending it.","Floor any computed page-size values (Math.floor) so floats never reach the API."],"exampleFix":"// before\nawait agent.listActiveRuns({ perPage: req.query.perPage }); // string -> throws\n// after\nconst perPage = Number(req.query.perPage);\nawait agent.listActiveRuns(Number.isInteger(perPage) && perPage > 0 ? { perPage } : {});","handlingStrategy":"validation","validationCode":"function normalizePerPage(v: unknown): number | undefined {\n  const n = Number(v);\n  return Number.isInteger(n) && n > 0 ? n : undefined;\n}\nconst perPage = normalizePerPage(req.query.perPage);","typeGuard":"function isValidPerPage(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  await agent.listActiveRuns(opts);\n} catch (e) {\n  if ((e as any).id === 'DURABLE_AGENT_LIST_ACTIVE_RUNS_INVALID_PER_PAGE') {\n    // fall back to default pagination\n    return agent.listActiveRuns();\n  } else throw e;\n}","preventionTips":["Parse and validate query params before passing to listActiveRuns.","Omit perPage instead of sending 0/null.","Use a shared pagination parsing helper across endpoints."],"tags":["durable-agent","pagination","validation","arguments"],"backgroundTag":"invalid-pagination-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}