{"record":{"id":"63952f778c6541bc","repo":"github/copilot-sdk","slug":"factory-limit-timeoutseconds-must-be-a-positive","errorCode":null,"errorMessage":"Factory limit \"timeoutSeconds\" must be a positive, finite number of seconds","messagePattern":"Factory limit \"timeoutSeconds\" must be a positive, finite number of seconds","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodejs/src/factory.ts","lineNumber":436,"sourceCode":"\nfunction validateLimits(meta: FactoryMeta): void {\n    const limits = meta.limits;\n    if (!limits) {\n        return;\n    }\n\n    for (const field of [\"maxConcurrentSubagents\", \"maxTotalSubagents\"] as const) {\n        const value = limits[field];\n        if (value !== undefined && (!Number.isInteger(value) || value <= 0)) {\n            throw new Error(`Factory limit \"${field}\" must be a positive integer`);\n        }\n    }\n\n    if (\n        limits.timeoutSeconds !== undefined &&\n        (!Number.isFinite(limits.timeoutSeconds) || limits.timeoutSeconds <= 0)\n    ) {\n        throw new Error(\n            'Factory limit \"timeoutSeconds\" must be a positive, finite number of seconds'\n        );\n    }\n    if (\n        limits.timeoutSeconds !== undefined &&\n        limits.timeoutSeconds > MAX_FACTORY_TIMEOUT_SECONDS\n    ) {\n        throw new Error(\n            `Factory limit \"timeoutSeconds\" must not exceed ${MAX_FACTORY_TIMEOUT_SECONDS} seconds`\n        );\n    }\n\n    if (limits.maxAiCredits !== undefined) {\n        const maxNanoAiu = Math.round(limits.maxAiCredits * NANO_AIU_PER_AIU);\n        if (\n            !Number.isFinite(limits.maxAiCredits) ||\n            limits.maxAiCredits <= 0 ||\n            !Number.isSafeInteger(maxNanoAiu) ||","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/nodejs/src/factory.ts#L418-L454","documentation":"This error is thrown by validateLimits when a factory definition specifies a timeoutSeconds limit that is not a finite positive number. The library validates factory limits at defineFactory time so invalid configuration fails fast instead of producing undefined behavior at runtime. timeoutSeconds controls how long factory operations may run, so zero, negative, NaN, or Infinity values are meaningless and rejected.","triggerScenarios":"Calling defineFactory with limits.timeoutSeconds set to 0, a negative number, NaN, or Infinity. Also occurs when timeoutSeconds is computed dynamically (e.g. from config or env) and the computation yields NaN or a non-positive value.","commonSituations":"Reading timeout values from environment variables or JSON config where the value is a string or missing and becomes NaN after numeric coercion; a config template with a placeholder 0; mixing units (milliseconds vs seconds) and dividing wrongly.","solutions":["Pass a positive finite number of seconds for limits.timeoutSeconds, e.g. 30.","If the value comes from config or env, validate/coerce it before calling defineFactory (Number.isFinite check).","Fix unit conversions so the result is in seconds, not milliseconds or a NaN-producing operation.","Remove the timeoutSeconds field entirely if you do not intend to set a timeout."],"exampleFix":"// before\ndefineFactory({ name: 'build', limits: { timeoutSeconds: Number(process.env.TIMEOUT) } });\n// after\nconst t = Number(process.env.TIMEOUT);\ndefineFactory({ name: 'build', limits: { timeoutSeconds: Number.isFinite(t) && t > 0 ? t : 30 } });","handlingStrategy":"validation","validationCode":"function isValidTimeout(t) { return typeof t === 'number' && Number.isFinite(t) && t > 0 && t <= 2147483.647; }\nif (!isValidTimeout(opts.limits?.timeoutSeconds)) throw new TypeError('timeoutSeconds must be a positive finite number of seconds');","typeGuard":"function hasValidTimeout(l) { return l.timeoutSeconds === undefined || (Number.isFinite(l.timeoutSeconds) && l.timeoutSeconds > 0); }","tryCatchPattern":"try {\n  defineFactory({ ...meta, limits: { timeoutSeconds: t } });\n} catch (e) {\n  if (String(e.message).includes('\"timeoutSeconds\"')) {\n    console.error('Bad timeoutSeconds config:', t);\n  }\n  throw e;\n}","preventionTips":["Coerce env/config values through Number() and Number.isFinite before use","Keep all timeouts in one unit (seconds) with named constants","Add a schema (zod) validation on factory limits before defineFactory","Never pass raw env strings as numeric limits"],"tags":["validation","factory","configuration","typescript"],"backgroundTag":"invalid-argument-value","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}