{"record":{"id":"29cd426e5807a7c1","repo":"JuliusBrussee/caveman","slug":"cave-harness-aborted","errorCode":"cave_harness_aborted","errorMessage":"cave_harness_aborted","messagePattern":"cave_harness_aborted","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/agent/src/adapters.ts","lineNumber":129,"sourceCode":"    version: identity.adapterVersion,\n    manifest,\n    contractSHA256,\n    async run(request: HarnessRequest): Promise<HarnessResult> {\n      const frozenRequest = snapshotRequest(request);\n      const prepared = prepareLockedHarnessExecution({\n        build: frozenRequest.build,\n        harness: id,\n        adapterVersion: identity.adapterVersion,\n        upstreamVersion: identity.upstreamVersion,\n        contextIR: frozenRequest.contextIR,\n        plan: frozenRequest.plan,\n      });\n      const { build, planSHA256, contextIRSHA256 } = prepared;\n      if (typeof frozenRequest.prompt !== \"string\" || frozenRequest.prompt.length === 0 ||\n          typeof frozenRequest.runID !== \"string\" || frozenRequest.runID.length === 0) {\n        throw new Error(\"cave_harness_request_invalid\");\n      }\n      if (isAborted(frozenRequest.signal)) throw new Error(\"cave_harness_aborted\");\n      validateTransformEvidence(frozenRequest, frozenRequest.plan);\n      const execution = snapshotExecution(await invoke(frozenRequest));\n      if (isAborted(frozenRequest.signal)) throw new Error(\"cave_harness_aborted\");\n      validateExecution(execution, frozenRequest.plan);\n      return {\n        terminal: execution.terminal,\n        text: execution.text,\n        provider: execution.provider,\n        model: execution.model,\n        inputTokens: execution.inputTokens,\n        outputTokens: execution.outputTokens,\n        cacheReadTokens: execution.cacheReadTokens,\n        cacheWriteTokens: execution.cacheWriteTokens,\n        reasoningTokens: execution.reasoningTokens,\n        totalTokens: execution.totalTokens,\n        costUsd: execution.costUsd,\n        usageBasis: execution.usageBasis,\n        priceBasis: execution.priceBasis,","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/packages/agent/src/adapters.ts#L111-L147","documentation":"`adapter.run` checks `isAborted(frozenRequest.signal)` immediately before dispatching to the harness `invoke`. If the caller's AbortSignal is already aborted at that instant, the run is discarded and `cave_harness_aborted` throws — no provider call is made, nothing is billed. This is a cooperative-cancellation checkpoint, not a harness failure.","triggerScenarios":"Caller `abort()`s a shared controller (timeout, user cancel, losing a race) before `await adapter.run(...)` executes; a retry loop reusing one controller whose previous attempt already aborted it; a shutdown signal fired while jobs were still queued.","commonSituations":"`Promise.race` cancellation where the loser's abort fires before the winner starts; global shutdown controllers triggered during drain; deadline timers that expire while the request waits in a queue.","solutions":["Create a fresh `AbortController` for each attempt and pass its signal","Check `signal.aborted` before building the request, not only after","Treat this code as cancellation — do not count it in error budgets or retry with the same aborted signal"],"exampleFix":"// before\nconst ac = sharedController; // already aborted by a previous attempt\nawait adapter.run({ ...req, signal: ac.signal });\n// after\nconst ac = new AbortController();\nconst t = setTimeout(() => ac.abort(), timeoutMs);\ntry { await adapter.run({ ...req, signal: ac.signal }); } finally { clearTimeout(t); }","handlingStrategy":"validation","validationCode":"if (req.signal?.aborted) {\n  throw new Error('run skipped: signal already aborted before dispatch');\n}\n// fresh controller per attempt — never reuse one from a previous aborted run\nconst ac = new AbortController();\nreturn adapter.run({ ...req, signal: ac.signal });","typeGuard":null,"tryCatchPattern":"try {\n  return await adapter.run(req);\n} catch (e) {\n  if (e instanceof Error && e.message === 'cave_harness_aborted') {\n    // intentional cancellation: propagate as a Cancelled sentinel,\n    // don't count toward error budgets, and don't retry the same signal\n    throw cancelSentinel(e);\n  }\n  throw e;\n}","preventionTips":["Create a fresh AbortController for every attempt","Check signal.aborted before building the request, not only in a catch block","Don't share controllers across queued jobs or racing branches"],"tags":["typescript","abort-signal","cancellation","async"],"backgroundTag":"abort-signal-aborted","analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}