{"record":{"id":"7df96b8dac7c1271","repo":"JuliusBrussee/caveman","slug":"invalid-deadline","errorCode":"invalid_deadline","errorMessage":"invalid_deadline","messagePattern":"invalid_deadline","errorType":"error_code","errorClass":"MiddlewareError","httpStatus":null,"severity":"error","filePath":"packages/sdk/typescript/src/middleware/runtime.ts","lineNumber":98,"sourceCode":"  private readonly lifetime = new AbortController();\n  private readonly bindings = new WeakSet<RecoveryBinding>();\n  private readonly capsCache: { value: Capabilities | null } = { value: null };\n  private failures = 0;\n  private openUntil = 0;\n  private pending = 0;\n  private receiptsPending = 0;\n  private fetchesPending = 0;\n  private receiptFetchesPending = 0;\n  private receiptTail: Promise<void> = Promise.resolve();\n  private reported: CallReport | null = null;\n\n  constructor(options: RuntimeOptions = {}) {\n    const url = new URL(options.endpoint ?? 'http://127.0.0.1:8787');\n    const local = ['127.0.0.1','[::1]','localhost'].includes(url.hostname);\n    if (!['http:','https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash || (url.pathname !== '/' && url.pathname !== '')) throw new MiddlewareError('invalid_endpoint');\n    if (!local && (!options.allowRemoteContent || url.protocol !== 'https:')) throw new MiddlewareError('remote_content_not_enabled');\n    for (const value of [options.deadlineMs, options.retrieveDeadlineMs]) {\n      if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) throw new MiddlewareError('invalid_deadline');\n    }\n    this.endpoint = url.origin;\n    this.options = { ...options };\n    this.mode = options.mode ?? 'compress';\n    this.fetcher = options.fetch ?? globalThis.fetch;\n  }\n\n  /** Prime capability discovery during app startup, outside the first model call. */\n  async ready(signal?: AbortSignal): Promise<Capabilities> {\n    signal?.throwIfAborted();\n    if (this.mode === 'off') throw new MiddlewareError('off');\n    const value = validateCapabilities(await this.http('capabilities', undefined, this.options.deadlineMs ?? 100, signal));\n    this.capsCache.value = value;\n    return value;\n  }\n\n  /** Nonthrowing startup discovery, including strict mode. Caller cancellation\n   * still propagates. Sends no candidate content or provider request. */","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/sdk/typescript/src/middleware/runtime.ts#L80-L116","documentation":"MiddlewareError('invalid_deadline') is thrown by the MiddlewareRuntime constructor when options.deadlineMs or options.retrieveDeadlineMs is provided but is not a positive safe integer. These options define the millisecond budget for capability discovery and optimize/retrieve HTTP calls. The constructor validates them eagerly so bad deadline configuration fails at startup instead of mid-request.","triggerScenarios":"new MiddlewareRuntime({ deadlineMs: 0 }), a negative deadlineMs/retrieveDeadlineMs, a non-integer like 99.5, NaN/Infinity, or a value passed as a string that exceeds Number.isSafeInteger.","commonSituations":"Reading deadline values from env vars or config files without parsing to int; computing a deadline via division producing a float; copying a Date.now() timestamp in as a deadline instead of a duration.","solutions":["Pass a positive safe integer, e.g. deadlineMs: 100","Parse config values with Number.parseInt and validate > 0 before constructing the runtime","Omit the option entirely to use the built-in 100ms default"],"exampleFix":"// before\nnew MiddlewareRuntime({ deadlineMs: process.env.DEADLINE }) // string\n// after\nconst d = Number.parseInt(process.env.DEADLINE ?? '', 10);\nnew MiddlewareRuntime({ deadlineMs: Number.isSafeInteger(d) && d > 0 ? d : undefined })","handlingStrategy":"validation","validationCode":"const isValidDeadline = (v) => v === undefined || (Number.isSafeInteger(v) && v > 0);\nif (!isValidDeadline(deadlineMs) || !isValidDeadline(retrieveDeadlineMs)) throw new Error('deadlineMs/retrieveDeadlineMs must be positive integers');","typeGuard":"const isPositiveInt = (v: unknown): v is number => typeof v === 'number' && Number.isSafeInteger(v) && v > 0;","tryCatchPattern":"try { const rt = createMiddlewareRuntime({ deadlineMs }); } catch (e) { if (e instanceof MiddlewareError && e.code === 'invalid_deadline') { /* fall back to default deadlines */ } else throw e; }","preventionTips":["Parse numeric config with Number.parseInt and validate before construction","Never assign timestamps (Date.now()) as durations","Centralize runtime construction so deadlines are validated in one place"],"tags":["configuration","typescript","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}