can1357/oh-my-pi · error
Invalid ${label}
Error message
Invalid ${label} What it means
The lightweight runtime validator in packages/utils/src/acp/schema.ts wraps a boolean check function with a Zod-compatible surface. Its 'parse' method throws Error(`Invalid ${label}`) when the value fails the structural check for the labeled schema (e.g. a session/prompt response shape). safeParse returns the same message as an issue without throwing.
Source
Thrown at packages/utils/src/acp/schema.ts:37
export interface ValidationFailure {
success: false;
error: ValidationError;
}
/** Runtime validator compatible with the used schema call shape. */
export interface Validator<T> {
safeParse(value: unknown): ValidationSuccess<T> | ValidationFailure;
parse(value: unknown): T;
}
function validator<T>(check: (value: unknown) => boolean, label: string): Validator<T> {
return {
safeParse(value) {
return check(value)
? { success: true, data: value as T }
: { success: false, error: { issues: [{ path: [], message: `Invalid ${label}` }] } };
},
parse(value) {
if (!check(value)) throw new Error(`Invalid ${label}`);
return value as T;
},
};
}
function objectWithString(value: unknown, key: string): boolean {
return typeof value === "object" && value !== null && typeof (value as Record<string, unknown>)[key] === "string";
}
function validModes(value: unknown): boolean {
if (value === undefined || value === null) return true;
if (typeof value !== "object" || value === null) return false;
const modes = value as Record<string, unknown>;
return (
typeof modes.currentModeId === "string" &&
Array.isArray(modes.availableModes) &&
modes.availableModes.every(mode => objectWithString(mode, "id") && objectWithString(mode, "name"))
);View on GitHub (pinned to 9690622007)
Solutions
- Log/inspect the raw value passed to parse and compare it against the schema's required fields.
- Use safeParse instead of parse to get a structured failure (issues array) instead of a throw, and branch on success.
- Upgrade or align the peer (agent/client) so both sides speak the same ACP protocol revision.
- Handle protocol error responses before handing payloads to the schema validator.
Example fix
// before
const response = schema.parse(raw);
// after
const result = schema.safeParse(raw);
if (!result.success) throw new Error(`Bad agent response: ${result.error.issues[0]?.message}`);
const response = result.data; Defensive patterns
Strategy: validation
Validate before calling
const result = schema.safeParse(raw);
if (!result.success) {
console.error("ACP response rejected:", result.error.issues);
return null;
}
const response = result.data; Type guard
function isObjectWithString(v: unknown, key: string): v is Record<string, string> {
return typeof v === "object" && v !== null && !Array.isArray(v) && typeof (v as Record<string, unknown>)[key] === "string";
} Try / catch
try {
return schema.parse(raw);
} catch (err) {
if (err instanceof Error && err.message.startsWith("Invalid ")) {
throw new Error(`ACP schema violation: ${err.message}; payload=${JSON.stringify(raw).slice(0, 200)}`);
}
throw err;
} Prevention
- Prefer safeParse so failures are structured data rather than throws.
- Pin/align ACP protocol versions between client and agent peers.
- Log the offending raw payload whenever validation fails to spot field drift quickly.
When it happens
Trigger: Calling parse(value) on an ACP protocol response (NewSessionResponse, LoadSessionResponse, PromptResponse, ForkSessionResponse, SessionNotification) that is missing required string fields, is not an object, is an array, or has malformed nested structures (e.g. modes.currentModeId not a string, availableModes entries lacking string id/name).
Common situations: An ACP agent or client peer returning a non-conformant response after a version drift between protocol revisions; a custom agent implementation missing required response fields; response JSON parsed from stdout lines that contains an error object instead of the expected success shape.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Invalid JSON-RPC message
- tasks must be a list
- cycle_model response did not include a model
- ready.supportedProtocolVersions must be integers
- Replacement text is not valid UTF-8: {err}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/bea5f22477754237.
Report an issue: GitHub.