{"record":{"id":"dedce679fb080c6d","repo":"mastra-ai/mastra","slug":"unhandled-toolinvocation-state-string-part-tool","errorCode":null,"errorMessage":"Unhandled toolInvocation.state: ${String(part.toolInvocation.state)}","messagePattern":"Unhandled toolInvocation\\.state: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/message-list/adapters/AIV6Adapter.ts","lineNumber":681,"sourceCode":"                'output-available',\n                getDisplayTransform(part.providerMetadata, 'error', part.toolInvocation.result),\n              ),\n            },\n            {\n              preliminary: part.preliminary,\n              approval:\n                part.toolInvocation.approval?.approved === true\n                  ? {\n                      id: part.toolInvocation.approval.id,\n                      approved: true,\n                      reason: part.toolInvocation.approval.reason,\n                    }\n                  : undefined,\n            },\n          ) as AIV6Type.UIMessage['parts'][number];\n\n        default:\n          throw new Error(`Unhandled toolInvocation.state: ${String(part.toolInvocation.state)}`);\n      }\n    }\n\n    if (part.type === 'source-document') {\n      return withOptionalFields(\n        {\n          type: 'source-document',\n          sourceId: part.sourceId,\n          mediaType: part.mediaType,\n          title: part.title,\n        },\n        {\n          filename: part.filename,\n          providerMetadata: part.providerMetadata,\n        },\n      ) as AIV6Type.UIMessage['parts'][number];\n    }\n","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/message-list/adapters/AIV6Adapter.ts#L663-L699","documentation":"Plain Error thrown by toUIPart in the AIV6 adapter when converting a tool part whose toolInvocation.state is not one of the handled states (e.g. 'partial-call', 'call', 'result', or an unexpected value like undefined). The adapter enumerates known invocation states and hits the default branch for anything else, indicating the message contains a toolInvocation in an unrecognized or corrupted state.","triggerScenarios":"Converting an AIV6 message containing a tool-invocation part whose state is undefined/missing, misspelled (e.g. 'complete' instead of 'result'), from a newer/older AI SDK version with an added state variant, or a hand-crafted toolInvocation object without a state field.","commonSituations":"Mixing message versions after upgrading AI SDK (new state enum values not yet handled by the adapter); manually constructing UI messages; persisted messages whose toolInvocation was partially deserialized; streaming interrupted leaving state unset.","solutions":["Ensure every toolInvocation in the message has a valid state: 'partial-call', 'call', or 'result'.","Check that message-producing and message-consuming sides use the same AI SDK v6 type versions; regenerate/normalize old persisted messages.","Inspect String(part.toolInvocation.state) in the thrown message to identify the unexpected value and fix the producer.","If a legitimately new state variant, upgrade @mastra/core to a version that handles it."],"exampleFix":"// before\n{ type: 'tool-invocation', toolInvocation: { toolCallId: 't1', toolName: 'weather' } } // no state\n\n// after\n{ type: 'tool-invocation', toolInvocation: { toolCallId: 't1', toolName: 'weather', state: 'result', result: {...} } }","handlingStrategy":"type-guard","validationCode":"const VALID_STATES = ['partial-call', 'call', 'result'] as const;\nfunction assertValidToolInvocation(part: any): void {\n  if (part?.type === 'tool-invocation' && !VALID_STATES.includes(part.toolInvocation?.state)) {\n    throw new Error(`Unexpected toolInvocation.state: ${String(part.toolInvocation?.state)}`);\n  }\n}","typeGuard":"function hasKnownInvocationState(p: any): p is { type: 'tool-invocation'; toolInvocation: { state: 'partial-call' | 'call' | 'result' } } {\n  return p?.type === 'tool-invocation' && ['partial-call', 'call', 'result'].includes(p.toolInvocation?.state);\n}","tryCatchPattern":"try {\n  const uiMessage = toUIMessage(v6Message);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Unhandled toolInvocation.state')) {\n    logger.warn('Skipping message with unknown toolInvocation state:', e.message);\n    return null;\n  }\n  throw e;\n}","preventionTips":["Keep AI SDK message-producing and consuming packages on matching versions so state enums agree.","Never construct toolInvocation objects by hand without a valid state field.","Normalize/validate persisted messages after upgrading AI SDK versions.","Log String(part.toolInvocation.state) from the error to identify which producer emitted the unknown state."],"tags":["agent","message-conversion","tool-invocation","aiv6"],"backgroundTag":"unhandled-enum-value","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}