{"record":{"id":"7e433f89184eefc8","repo":"vercel/ai","slug":"code-mode-protocol-error-7e433f","errorCode":"CODE_MODE_PROTOCOL_ERROR","errorMessage":"Code mode interruption payload is malformed.","messagePattern":"Code mode interruption payload is malformed\\.","errorType":"exception","errorClass":"CodeModeProtocolError","httpStatus":null,"severity":"error","filePath":"packages/code-mode/src/run-code-mode.ts","lineNumber":352,"sourceCode":"    }\n    if (\n      RunError.isInstance(error) ||\n      (error instanceof Error && error.name === 'HostFunctionInterruptSignal')\n    ) {\n      throw error;\n    }\n    throw new RunError('Host tool failed.', 'CODE_MODE_HOST_TOOL_ERROR');\n  }\n}\n\nfunction assertInterruptPayload(value: unknown): CodeModeInterruptPayload {\n  if (\n    typeof value !== 'object' ||\n    value === null ||\n    Array.isArray(value) ||\n    typeof (value as { kind?: unknown }).kind !== 'string'\n  ) {\n    throw new CodeModeProtocolError(\n      'Code mode interruption payload is malformed.',\n    );\n  }\n  return value as CodeModeInterruptPayload;\n}\n\nfunction toRunLimits(\n  policy: ResolvedExecutionPolicy,\n  source: string,\n  userSource: string,\n): RunLimits {\n  return {\n    timeoutMs: policy.timeoutMs,\n    memoryLimitBytes: policy.memoryLimitBytes,\n    maxStackSizeBytes: policy.maxStackSizeBytes,\n    maxResultBytes: expandedSerializationLimit(policy.maxResultBytes),\n    maxConsoleOutputBytes: policy.maxConsoleOutputBytes,\n    maxSourceBytes: withSerializationOverhead(","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/code-mode/src/run-code-mode.ts#L334-L370","documentation":"assertInterruptPayload validates the resume payload attached to a host-function resume (context.resume.payload). It must be a non-null, non-array object with a string kind property; otherwise a CodeModeProtocolError is thrown. This guard protects the resume path from malformed payloads produced by corrupted continuation state or by resume mechanisms not originating from this library.","triggerScenarios":"Resuming a code-mode run where the continuation token's recorded interruption payload is corrupt, truncated, or was produced by a different/incompatible library version lacking the kind field.","commonSituations":"Hand-crafting or editing continuation tokens; decoding signed continuation state with the wrong key or codec version; database round-trips that mangle stored payloads.","solutions":["Regenerate the interrupt by re-running the code-mode program instead of reusing suspect continuation state.","Verify the continuation token is passed through unmodified from the original interrupt result.","Ensure all packages that produce/consume continuations (@ai-sdk/code-mode and the underlying run package) are on compatible versions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function looksLikeInterruptPayload(v: unknown): boolean {\n  return typeof v === 'object' && v !== null && !Array.isArray(v) && typeof (v as { kind?: unknown }).kind === 'string';\n}\n// Validate decoded continuation payloads before resuming.","typeGuard":"function isWellFormedPayload(v: unknown): v is { kind: string; [k: string]: unknown } {\n  return typeof v === 'object' && v !== null && !Array.isArray(v) && typeof (v as { kind?: unknown }).kind === 'string';\n}","tryCatchPattern":"try {\n  await runCodeMode({ js, tools, continuation, interruptResolution });\n} catch (error) {\n  if (CodeModeProtocolError.isInstance(error)) {\n    // discard corrupt continuation state and restart\n  } else throw error;\n}","preventionTips":["Never hand-edit continuation tokens or their decoded payloads.","Use lossless serialization when persisting interrupts.","Keep code-mode and run package versions in sync."],"tags":["code-mode","protocol-error","interrupt-payload","continuation"],"backgroundTag":"interrupt-payload-shape-invalid","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}