can1357/oh-my-pi · error · ToolError
Invalid cmux socket JSON response: ${err instanceof Error ?
Error message
Invalid cmux socket JSON response: ${err instanceof Error ? err.message : String(err)} What it means
#parseResponse JSON.parses each reply line from the cmux socket; when parsing fails it throws this ToolError embedding the JSON parse error message. It means the daemon (or something on the socket) returned a line that is not valid JSON and not an 'ERROR:' line, so the client cannot interpret the response envelope.
Source
Thrown at packages/coding-agent/src/tools/browser/cmux/socket-client.ts:391
let line = this.#buffer.slice(0, newlineIndex);
this.#buffer = this.#buffer.slice(newlineIndex + 1);
if (line.endsWith("\r")) {
line = line.slice(0, -1);
}
const waiter = this.#lineWaiters.shift();
waiter?.resolve(line);
}
}
#parseResponse(line: string): Record<string, unknown> {
if (line.startsWith("ERROR:")) {
throw new ToolError(line);
}
let payload: unknown;
try {
payload = JSON.parse(line);
} catch (err) {
throw new ToolError(`Invalid cmux socket JSON response: ${err instanceof Error ? err.message : String(err)}`);
}
if (!payload || typeof payload !== "object") {
throw new ToolError("Invalid cmux socket response: expected object");
}
const response = payload as { ok?: unknown; result?: unknown; error?: CmuxErrorPayload };
if (response.ok === true) {
return (response.result ?? {}) as Record<string, unknown>;
}
if (response.ok === false) {
throw new ToolError(formatCmuxError(response.error));
}
throw new ToolError("Invalid cmux socket response: missing ok flag");
}
#handleSocketFailure(err: Error): void {
if (this.#disposed) return;
this.#connected = false;
this.#connectPromise = null;View on GitHub (pinned to 9690622007)
Solutions
- Verify the socketPath points at the cmux daemon's JSON line socket, not another service
- Restart the cmux daemon and retry — a truncated response usually follows a daemon-side fault
- Check daemon logs for crashes/corruption around the failing request
- Upgrade client and daemon together so framing/version conventions match
Example fix
// before: pointing at a random debug socket
new CmuxSocketClient({ socketPath: "/tmp/app.sock" })
// after: the cmux daemon's control socket
new CmuxSocketClient({ socketPath: cmuxControlSocketPath }) Defensive patterns
Strategy: try-catch
Validate before calling
// preflight: confirm the socket answers with a framed JSON line
const probe = net.createConnection({ path: socketPath });
// if it's a TCP relay endpoint use { host: '127.0.0.1', port } instead Type guard
function looksLikeJsonLine(s: string): boolean {
try { const v = JSON.parse(s); return typeof v === "object" && v !== null; } catch { return false; }
} Try / catch
try {
return await client.request(method, params);
} catch (err) {
if (err instanceof ToolError && err.message.startsWith("Invalid cmux socket JSON response")) {
// wrong endpoint or daemon fault: verify socketPath, restart daemon, retry once
}
throw err;
} Prevention
- Point socketPath strictly at the cmux daemon's control socket
- Keep client and daemon versions aligned (framing conventions change between versions)
- Treat the first invalid-JSON response after a daemon restart as a signal to reconnect, not to retry in-place
When it happens
Trigger: Server emits a banner, log line, or partial/interleaved output on the socket; response truncated by an early close; a proxy or wrong service bound to the socket path returns non-JSON (HTML, plaintext); multi-line JSON payloads sent without newline framing the client expects.
Common situations: Version-mismatched daemon speaking a different framing; connecting the client to the wrong unix socket/port (another daemon's protocol); server crash mid-response leaving a partial line.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
- Replacement text is not valid UTF-8: {err}
- Anthropic cache refresh returned a malformed response
- rpc frame must be an object
- Invalid cmux socket response: expected object
- Invalid cmux socket response: missing ok flag
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/87021b19b835ef4d.
Report an issue: GitHub.