different-ai/openwork · error · RangeError
Agent context diagnostics timeout must be between 1 ms and 3
Error message
Agent context diagnostics timeout must be between 1 ms and 30 seconds.
What it means
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.
Source
Thrown at apps/app/src/app/lib/agent-context-diagnostics-transport.ts:119
}
/**
* Runs the diagnostics request under one deadline that remains active until
* the bounded response body has been consumed and parsed.
*/
export async function requestAgentContextDiagnosticsPayload(options: {
fetchImpl: AgentContextDiagnosticsFetch;
url: string;
init: RequestInit;
timeoutMs?: number;
}): Promise<AgentContextDiagnosticsTransportResult> {
const timeoutMs = options.timeoutMs ?? AGENT_CONTEXT_DIAGNOSTICS_REQUEST_TIMEOUT_MS;
if (
!Number.isFinite(timeoutMs)
|| timeoutMs <= 0
|| timeoutMs > AGENT_CONTEXT_DIAGNOSTICS_REQUEST_TIMEOUT_MS
) {
throw new RangeError("Agent context diagnostics timeout must be between 1 ms and 30 seconds.");
}
const deadlineAtMs = Date.now() + timeoutMs;
const controller = new AbortController();
let timeoutId: ReturnType<typeof setTimeout> | null = null;
const deadline = new Promise<never>((_, reject) => {
timeoutId = setTimeout(() => {
controller.abort();
reject(timeoutError());
}, timeoutMs);
});
try {
const response = await Promise.race([
options.fetchImpl(
options.url,
{ ...options.init, redirect: "error", signal: controller.signal },
deadlineAtMs,View on GitHub (pinned to 2b7df46e8a)
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
Example fix
// before
await requestAgentContextDiagnosticsPayload({ timeoutMs: 60_000 });
// after
await requestAgentContextDiagnosticsPayload({ timeoutMs: Math.min(Math.max(Math.floor(timeoutMs), 1), 30_000) }); Defensive patterns
Strategy: validation
Validate before calling
function isValidDiagnosticsTimeout(t: unknown): t is number {
return typeof t === "number" && Number.isFinite(t) && t > 0 && t <= 30_000;
}
if (options.timeoutMs !== undefined && !isValidDiagnosticsTimeout(options.timeoutMs)) throw new RangeError("timeoutMs must be 1..30000"); Type guard
const isValidDiagnosticsTimeout = (t: unknown): t is number => typeof t === "number" && Number.isFinite(t) && t > 0 && t <= 30_000;
Try / catch
try {
await requestAgentContextDiagnosticsPayload({ timeoutMs });
} catch (err) {
if (err instanceof RangeError) {
console.warn("Invalid diagnostics timeout, using default");
await requestAgentContextDiagnosticsPayload({});
} else throw err;
} Prevention
- 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
When it happens
Trigger: Calling requestAgentContextDiagnosticsPayload with options.timeoutMs set to 0, a negative number, NaN/Infinity, a value above 30000, or a non-numeric value.
Common situations: 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.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- CONFIGURATION
- Request timed out.
- Timed out waiting for server health
- Invalid cloud provider sync response.
- Invalid cloud provider sync status.
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/c0d0447d38ac84b8.
Report an issue: GitHub.