{"record":{"id":"f29af7c5464ebbde","repo":"moeru-ai/airi","slug":"the-selected-invocation-does-not-match-the-tool-name","errorCode":null,"errorMessage":"The selected invocation does not match the tool name.","messagePattern":"The selected invocation does not match the tool name\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/stage-ui/src/stores/tool-call-rerun.ts","lineNumber":136,"sourceCode":" * The resolver is injected so callers can choose the runtime-specific tool list\n * without coupling this helper to app-local stores, Electron IPC, or browser state.\n */\nexport async function executeToolCallRerun<TToolset extends string = string>(\n  options: ExecuteToolCallRerunOptions<TToolset>,\n): Promise<ChatHistoryItem[]> {\n  const { messages, payload } = options\n  const targetIndex = findTargetMessageIndex(messages, payload)\n  const targetMessage = messages[targetIndex]\n\n  if (targetMessage?.role !== 'assistant')\n    throw new Error('Tool call rerun target must be an assistant message.')\n\n  if (!hasMatchingToolCall(targetMessage, payload))\n    throw new Error(`Assistant message does not contain tool call \"${payload.toolCallId}\" for \"${payload.toolName}\".`)\n\n  const invocation = findInvocation(targetMessage, payload.toolCallId, payload.invocationId)\n  if (invocation && invocation.call.name !== payload.toolName)\n    throw new Error('The selected invocation does not match the tool name.')\n\n  const replaceTargetMessage = (result: ToolCallResultInput) => messages.map((item, itemIndex) => {\n    if (itemIndex !== targetIndex)\n      return item\n\n    return replaceToolCallResult(targetMessage, result, payload.invocationId)\n  })\n\n  const tools = await options.resolveTools()\n  const tool = tools.find(candidate => toolNameFrom(candidate) === payload.toolName)\n  if (tool == null) {\n    return replaceTargetMessage({\n      id: payload.toolCallId,\n      isError: true,\n      result: `Tool \"${payload.toolName}\" is not available for rerun in this runtime.`,\n    })\n  }\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/moeru-ai/airi/blob/438a067dde47aa0bdb46c2323d1fe293dc805218/packages/stage-ui/src/stores/tool-call-rerun.ts#L118-L154","documentation":"executeToolCallRerun verifies that a resolved invocation (found via invocationId) actually belongs to the tool named in the payload. A mismatch means the invocationId points to an invocation of a different tool, so rerunning would execute the wrong tool; it throws to prevent that.","triggerScenarios":"Calling executeToolCallRerun with a payload whose invocationId resolves to an invocation whose call.name differs from payload.toolName, even though the toolCallId exists in the target message.","commonSituations":"Stale UI state after editing a message: the stored invocationId now maps to a different tool's call (e.g. after swapping or reordering tool calls), or a copy-paste of rerun parameters between different tool calls.","solutions":["Correct payload.toolName to match the invocation's actual call name, or pass the invocationId belonging to payload.toolName.","Re-derive the rerun payload from the current message state instead of cached values.","Clear stale rerun state in the UI after any message edit."],"exampleFix":"// before\nrerun({ toolCallId: 'call_1', toolName: 'search', invocationId: 'inv_of_translate' })\n// after\nrerun({ toolCallId: 'call_1', toolName: 'search', invocationId: 'inv_of_search' })","handlingStrategy":"validation","validationCode":"const invocation = message.toolCalls.find(c => c.id === payload.toolCallId && c.invocationId === payload.invocationId)\nif (invocation && invocation.name !== payload.toolName)\n  throw new Error('invocation/toolName mismatch before rerun')","typeGuard":null,"tryCatchPattern":"try {\n  await executeToolCallRerun(payload)\n} catch (e) {\n  if (e.message.includes('does not match the tool name')) {\n    // rebuild payload from current message state and retry once\n  }\n}","preventionTips":["Derive toolName and invocationId from the same source (the current message), never from separate caches.","Re-validate rerun payloads after any message edit.","Reset rerun form state when the target message changes."],"tags":["tool-call","type-mismatch","rerun"],"backgroundTag":"invalid-argument-value","analyzedSha":"438a067dde47aa0bdb46c2323d1fe293dc805218","analyzedAt":"2026-09-17T01:14:42.644Z","contentChangedAt":"2026-09-17T01:14:42.644Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}