{"record":{"id":"09084f327bcc548c","repo":"vercel/ai","slug":"code-mode-interrupt-payload-must-be-an-object","errorCode":null,"errorMessage":"Code mode interrupt payload must be an object.","messagePattern":"Code mode interrupt payload must be an object\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/code-mode/src/host-interrupt.ts","lineNumber":12,"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":"requestCodeModeInterrupt lets sandboxed code-mode programs suspend execution and surface an interrupt payload to the host. Before delegating to the host interrupt mechanism, it validates that the payload is a plain, non-null, non-array object. A TypeError is thrown when the payload fails this shape check, because downstream continuation signing and matching require a structured object payload.","triggerScenarios":"Calling requestCodeModeInterrupt(null), requestCodeModeInterrupt(undefined), requestCodeModeInterrupt([…]), or requestCodeModeInterrupt('string') / a number/boolean from inside code-mode JS, instead of passing an object with a string kind field.","commonSituations":"Generated or hand-written sandbox code that builds the payload dynamically and ends up with null/undefined (e.g. a JSON.parse failure or a variable that was never assigned), or that mistakenly passes an array of payloads rather than a single payload object.","solutions":["Ensure the value passed to requestCodeModeInterrupt is a plain object literal, e.g. { kind: 'confirm', … }.","If the payload is computed, add a fallback: payload ?? { kind: 'default' } before calling the interrupt.","Wrap arrays or scalars in an object field (e.g. { kind: 'batch', items }) instead of passing them directly."],"exampleFix":"// before\nrequestCodeModeInterrupt(input?.confirmation);\n// after\nconst payload = input?.confirmation;\nif (payload == null || typeof payload !== 'object' || Array.isArray(payload)) {\n  throw new Error('missing confirmation payload');\n}\nrequestCodeModeInterrupt({ kind: 'confirm', ...payload });","handlingStrategy":"validation","validationCode":"function isValidInterruptPayload(p: unknown): boolean {\n  return typeof p === 'object' && p !== null && !Array.isArray(p);\n}\n// before calling: if (!isValidInterruptPayload(payload)) fix or throw;","typeGuard":"function isInterruptPayload(v: unknown): v is { kind: string; [k: string]: unknown } {\n  return typeof v === 'object' && v !== null && !Array.isArray(v) && typeof (v as any).kind === 'string' && (v as any).kind.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always build interrupt payloads as object literals with an explicit kind field.","Type the payload with CodeModeInterruptPayload so TypeScript rejects scalars and arrays.","Avoid JSON.parse of untrusted data directly into the payload without validation."],"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"}