github/copilot-sdk · error · ResponseError
unsupported_type
unsupported_type
Error message
${context.label} contains a function, symbol, or BigInt at ${path} What it means
The strict JSON validator rejects functions, symbols, and BigInts in journaled factory results/steps because none of these have a JSON representation — JSON.stringify would silently drop or throw on them. Throwing up front with the offending path keeps journal data lossless and replayable.
Solutions
- Check the `path` in the error details and remove or convert the function/symbol/BigInt value at that location.
- Convert BigInt to a string (or Number if safely representable) before journaling.
- Build result objects explicitly instead of spreading class instances, so only JSON-safe fields are included.
Example fix
// before
return { id: 9007199254740993n, save: () => persist(state) };
// after
return { id: "9007199254740993" }; Defensive patterns
Strategy: validation
Validate before calling
function assertJsonPrimitives(value, path = "$") {
if (typeof value === "function" || typeof value === "symbol" || typeof value === "bigint")
throw new Error(`Unsupported type at ${path}`);
if (Array.isArray(value)) value.forEach((v, i) => assertJsonPrimitives(v, `${path}[${i}]`));
else if (value && typeof value === "object")
for (const [k, v] of Object.entries(value)) assertJsonPrimitives(v, `${path}.${k}`);
} Type guard
const isJsonSerializable = (v: unknown): boolean => v === null || ["string", "boolean", "number"].includes(typeof v) || (Array.isArray(v) && v.every(isJsonSerializable)) || (v !== null && typeof v === "object" && Object.getPrototypeOf(v) === Object.prototype && Object.values(v).every(isJsonSerializable));
Try / catch
try {
session.runFactory(step);
} catch (e) {
if (e?.details?.category === "unsupported_type") {
console.error(`Remove function/symbol/BigInt at ${e.details.path}`);
} else throw e;
} Prevention
- Convert BigInt ids to strings at the boundary (e.g. right after DB reads).
- Never spread class instances into journaled results; build plain objects explicitly.
- Keep helper closures and callbacks out of result payloads.
When it happens
Trigger: Returning a factory result or step containing a function value (a method, a callback, a class instance method copied onto a plain object), a symbol-keyed value assigned via computed keys, or a BigInt literal/operation result (123n, BigInt(x)).
Common situations: Accidentally spreading an object that includes methods (`{ ...someInstance }` keeps prototype methods on some shapes), using BigInt for IDs from a database driver, and attaching helper closures to result objects.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/b70aa2f207ca3a41.
Report an issue: GitHub.
Appendix: source
Thrown at nodejs/src/session.ts:2335
}
// JSON serializes -0 as "0", so a journaled -0 would come back as 0
// after a resume and break the lossless replay guarantee.
if (Object.is(current, -0)) {
throw strictJsonValidationError(
context,
"negative_zero",
`${context.label} contains negative zero at ${path}; normalize it to 0`,
path
);
}
return;
}
if (
typeof current === "function" ||
typeof current === "symbol" ||
typeof current === "bigint"
) {
throw strictJsonValidationError(
context,
"unsupported_type",
`${context.label} contains a function, symbol, or BigInt at ${path}`,
path
);
}
if (typeof current !== "object") {
throw strictJsonValidationError(
context,
"unsupported_type",
`${context.label} contains a function, symbol, or BigInt at ${path}`,
path
);
}
if (ancestors.has(current)) {
throw strictJsonValidationError(
context,
"cyclic_value",View on GitHub (pinned to cd8cf15dc3)