{"record":{"id":"e34301b0945751ad","repo":"vercel/ai","slug":"code-mode-interrupt-payload-must-include-a-string","errorCode":null,"errorMessage":"Code mode interrupt payload must include a string kind.","messagePattern":"Code mode interrupt payload must include a string kind\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/code-mode/src/host-interrupt.ts","lineNumber":15,"sourceCode":"import { getHostFunctionContext } from 'run';\nimport type { CodeModeInterruptPayload } from './types.js';\n\nexport function requestCodeModeInterrupt<\n  TPayload extends CodeModeInterruptPayload,\n>(payload: TPayload): never {\n  if (\n    typeof payload !== 'object' ||\n    payload === null ||\n    Array.isArray(payload)\n  ) {\n    throw new TypeError('Code mode interrupt payload must be an object.');\n  }\n  if (typeof payload.kind !== 'string' || payload.kind.length === 0) {\n    throw new TypeError(\n      'Code mode interrupt payload must include a string kind.',\n    );\n  }\n  return getHostFunctionContext().interrupt(payload);\n}\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/code-mode/src/host-interrupt.ts#L1-L21","documentation":"After confirming the interrupt payload is a plain object, requestCodeModeInterrupt requires a non-empty string 'kind' property. The kind discriminates interrupt types on the host side (e.g. tool approval vs custom interrupts), so a missing or empty kind cannot be routed and a TypeError is thrown.","triggerScenarios":"Calling requestCodeModeInterrupt({}) or { kind: '' } from code-mode sandbox code — an object that omits kind or sets it to an empty/non-string value.","commonSituations":"Refactoring code that renamed the discriminating field (e.g. type instead of kind), spreading a payload where kind was overwritten by undefined via { kind: undefined, ...rest }, or LLM-generated code forgetting the kind field entirely.","solutions":["Add a non-empty string kind to the payload object, e.g. { kind: 'approval', … }.","Check for accidental kind: undefined from object spread order and fix property ordering.","If the kind is dynamic, guard it: if (!kind) throw before calling requestCodeModeInterrupt."],"exampleFix":"// before\nrequestCodeModeInterrupt({ ...details });\n// after\nrequestCodeModeInterrupt({ kind: 'user-confirmation', ...details });","handlingStrategy":"validation","validationCode":"function hasKind(p: object): boolean {\n  return typeof (p as { kind?: unknown }).kind === 'string' && (p as { kind: string }).kind.length > 0;\n}\nif (!hasKind(payload)) payload = { kind: 'default', ...payload };","typeGuard":"function hasNonEmptyKind(v: unknown): v is { kind: string } {\n  return typeof v === 'object' && v !== null && typeof (v as { kind?: unknown }).kind === 'string' && (v as { kind: string }).kind.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Put kind first in the payload literal so spread order can't overwrite it with undefined.","Define a union of allowed kind values in one shared constant.","Add a unit test that every code path calling requestCodeModeInterrupt includes kind."],"tags":["code-mode","validation","typeerror","interrupt-payload"],"backgroundTag":"interrupt-payload-shape-invalid","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}