{"record":{"id":"968e437e6399debf","repo":"vercel/ai","slug":"harness-input-harness-harnessid-emitted-appr-968e43","errorCode":null,"errorMessage":"`Harness '${input.harness.harnessId}' emitted approval request '${value.approvalId}' for unknown tool call '${value.toolCallId}'.`","messagePattern":"`Harness '(.+?)' emitted approval request '(.+?)' for unknown tool call '(.+?)'\\.`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/harness/src/agent/internal/run-prompt.ts","lineNumber":843,"sourceCode":"            toolName: value.toolName,\n            input: value.input,\n          });\n        }\n\n        // Telemetry: close a tool span when its provider-executed result lands.\n        if (value.type === 'tool-result') {\n          await telemetry.toolEnd(\n            value.toolCallId,\n            value.isError\n              ? { ok: false, error: value.result }\n              : { ok: true, output: value.result },\n          );\n        }\n\n        if (value.type === 'tool-approval-request') {\n          const toolCall = toolCallsByToolCallId.get(value.toolCallId);\n          if (toolCall == null) {\n            throw new Error(\n              `Harness '${input.harness.harnessId}' emitted approval request '${value.approvalId}' for unknown tool call '${value.toolCallId}'.`,\n            );\n          }\n\n          const rawToolCall = rawToolCallsByToolCallId.get(value.toolCallId);\n          const pendingApproval =\n            pendingApprovalsByApprovalId.get(value.approvalId) ??\n            ({\n              approvalId: value.approvalId,\n              toolCallId: value.toolCallId,\n              toolName: toolCall.toolName,\n              input: rawToolCall?.input ?? JSON.stringify(toolCall.input),\n              kind: 'builtin',\n              providerExecuted: rawToolCall?.providerExecuted ?? true,\n              ...(rawToolCall?.nativeName !== undefined\n                ? { nativeName: rawToolCall.nativeName }\n                : {}),\n            } satisfies HarnessV1PendingToolApproval);","sourceCodeStart":825,"sourceCodeEnd":861,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness/src/agent/internal/run-prompt.ts#L825-L861","documentation":"Same family as the 'unknown tool call' error: the harness emitted a `tool-approval-request` whose `toolCallId` is absent from the SDK's parsed-tool-call registry. runPrompt validates every approval request against `toolCallsByToolCallId` and throws when the referenced tool call was never parsed in this run, because the approval cannot be correlated with an actual tool invocation.","triggerScenarios":"A stream value of type 'tool-approval-request' is processed and `toolCallsByToolCallId.get(value.toolCallId)` is null — the harness references a tool call id not present in the current run's stream.","commonSituations":"Adapter id-remapping bugs; approvals emitted before the corresponding tool-call part is streamed; stale approvals replayed after resumption; harnesses that fabricate ids for internally-initiated tool calls.","solutions":["Ensure the harness emits the tool-call part before (or atomically with) its approval request, using identical toolCallId values.","Fix any id remapping in the adapter so model tool call ids are forwarded unchanged.","Suppress/dedupe replayed approval events when resuming a harness session."],"exampleFix":"// before\nconst pending = harness.createApproval(toolCall.internalKey); // remapped id\n\n// after\nconst pending = harness.createApproval(toolCall.toolCallId); // id as streamed","handlingStrategy":"validation","validationCode":"const tracked = new Set(parsedToolCalls.map(c => c.toolCallId));\nif (!tracked.has(approvalRequest.toolCallId)) {\n  throw new Error(`Harness emitted approval for untracked tool call ${approvalRequest.toolCallId}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await agent.run(...);\n} catch (e) {\n  if (e instanceof Error && /for unknown tool call/.test(e.message)) {\n    // capture harness stream, fix adapter id forwarding\n  }\n  throw e;\n}","preventionTips":["Create approval requests only from parsed tool call objects.","Do not remap or regenerate tool call ids inside the adapter.","Cover approval flows in adapter integration tests."],"tags":["harness","tool-approval","protocol-violation","id-mismatch"],"backgroundTag":"unknown-tool-call-id","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}