{"record":{"id":"c0d0447d38ac84b8","repo":"different-ai/openwork","slug":"agent-context-diagnostics-timeout-must-be-between","errorCode":null,"errorMessage":"Agent context diagnostics timeout must be between 1 ms and 30 seconds.","messagePattern":"Agent context diagnostics timeout must be between 1 ms and 30 seconds\\.","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"apps/app/src/app/lib/agent-context-diagnostics-transport.ts","lineNumber":119,"sourceCode":"}\n\n/**\n * Runs the diagnostics request under one deadline that remains active until\n * the bounded response body has been consumed and parsed.\n */\nexport async function requestAgentContextDiagnosticsPayload(options: {\n  fetchImpl: AgentContextDiagnosticsFetch;\n  url: string;\n  init: RequestInit;\n  timeoutMs?: number;\n}): Promise<AgentContextDiagnosticsTransportResult> {\n  const timeoutMs = options.timeoutMs ?? AGENT_CONTEXT_DIAGNOSTICS_REQUEST_TIMEOUT_MS;\n  if (\n    !Number.isFinite(timeoutMs)\n    || timeoutMs <= 0\n    || timeoutMs > AGENT_CONTEXT_DIAGNOSTICS_REQUEST_TIMEOUT_MS\n  ) {\n    throw new RangeError(\"Agent context diagnostics timeout must be between 1 ms and 30 seconds.\");\n  }\n\n  const deadlineAtMs = Date.now() + timeoutMs;\n  const controller = new AbortController();\n  let timeoutId: ReturnType<typeof setTimeout> | null = null;\n  const deadline = new Promise<never>((_, reject) => {\n    timeoutId = setTimeout(() => {\n      controller.abort();\n      reject(timeoutError());\n    }, timeoutMs);\n  });\n\n  try {\n    const response = await Promise.race([\n      options.fetchImpl(\n        options.url,\n        { ...options.init, redirect: \"error\", signal: controller.signal },\n        deadlineAtMs,","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/app/lib/agent-context-diagnostics-transport.ts#L101-L137","documentation":"requestAgentContextDiagnosticsPayload validates the caller-supplied timeoutMs before issuing the diagnostics request. A RangeError is thrown when the timeout is not a finite positive number or exceeds the 30-second maximum (AGENT_CONTEXT_DIAGNOSTICS_REQUEST_TIMEOUT_MS). This guards the internal deadline/AbortController machinery from impossible or unbounded timeouts.","triggerScenarios":"Calling requestAgentContextDiagnosticsPayload with options.timeoutMs set to 0, a negative number, NaN/Infinity, a value above 30000, or a non-numeric value.","commonSituations":"Passing a timeout read from misconfigured settings (e.g. seconds instead of milliseconds), parsing user input without validation, or hardcoding 60_000 assuming it is allowed.","solutions":["Ensure timeoutMs is a finite number in the 1..30000 range, or omit options.timeoutMs to use the 30s default","Clamp or validate the value before the call: Math.min(Math.max(Math.floor(t),1),30000)","Fix config parsing that reads seconds vs milliseconds or produces NaN"],"exampleFix":"// before\nawait requestAgentContextDiagnosticsPayload({ timeoutMs: 60_000 });\n// after\nawait requestAgentContextDiagnosticsPayload({ timeoutMs: Math.min(Math.max(Math.floor(timeoutMs), 1), 30_000) });","handlingStrategy":"validation","validationCode":"function isValidDiagnosticsTimeout(t: unknown): t is number {\n  return typeof t === \"number\" && Number.isFinite(t) && t > 0 && t <= 30_000;\n}\nif (options.timeoutMs !== undefined && !isValidDiagnosticsTimeout(options.timeoutMs)) throw new RangeError(\"timeoutMs must be 1..30000\");","typeGuard":"const isValidDiagnosticsTimeout = (t: unknown): t is number =>\n  typeof t === \"number\" && Number.isFinite(t) && t > 0 && t <= 30_000;","tryCatchPattern":"try {\n  await requestAgentContextDiagnosticsPayload({ timeoutMs });\n} catch (err) {\n  if (err instanceof RangeError) {\n    console.warn(\"Invalid diagnostics timeout, using default\");\n    await requestAgentContextDiagnosticsPayload({});\n  } else throw err;\n}","preventionTips":["Clamp user/config-supplied timeouts to the 1..30000 ms range before calling","Omit timeoutMs when the 30s default is acceptable","Watch for seconds-vs-milliseconds unit mistakes in config parsing"],"tags":["validation","range-error","timeout","argument-error"],"backgroundTag":"invalid-argument-range","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}