{"record":{"id":"87021b19b835ef4d","repo":"can1357/oh-my-pi","slug":"invalid-cmux-socket-json-response-err-instanceo","errorCode":null,"errorMessage":"Invalid cmux socket JSON response: ${err instanceof Error ? err.message : String(err)}","messagePattern":"Invalid cmux socket JSON response: (.+?)","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/browser/cmux/socket-client.ts","lineNumber":391,"sourceCode":"\t\t\tlet line = this.#buffer.slice(0, newlineIndex);\n\t\t\tthis.#buffer = this.#buffer.slice(newlineIndex + 1);\n\t\t\tif (line.endsWith(\"\\r\")) {\n\t\t\t\tline = line.slice(0, -1);\n\t\t\t}\n\t\t\tconst waiter = this.#lineWaiters.shift();\n\t\t\twaiter?.resolve(line);\n\t\t}\n\t}\n\n\t#parseResponse(line: string): Record<string, unknown> {\n\t\tif (line.startsWith(\"ERROR:\")) {\n\t\t\tthrow new ToolError(line);\n\t\t}\n\t\tlet payload: unknown;\n\t\ttry {\n\t\t\tpayload = JSON.parse(line);\n\t\t} catch (err) {\n\t\t\tthrow new ToolError(`Invalid cmux socket JSON response: ${err instanceof Error ? err.message : String(err)}`);\n\t\t}\n\t\tif (!payload || typeof payload !== \"object\") {\n\t\t\tthrow new ToolError(\"Invalid cmux socket response: expected object\");\n\t\t}\n\t\tconst response = payload as { ok?: unknown; result?: unknown; error?: CmuxErrorPayload };\n\t\tif (response.ok === true) {\n\t\t\treturn (response.result ?? {}) as Record<string, unknown>;\n\t\t}\n\t\tif (response.ok === false) {\n\t\t\tthrow new ToolError(formatCmuxError(response.error));\n\t\t}\n\t\tthrow new ToolError(\"Invalid cmux socket response: missing ok flag\");\n\t}\n\n\t#handleSocketFailure(err: Error): void {\n\t\tif (this.#disposed) return;\n\t\tthis.#connected = false;\n\t\tthis.#connectPromise = null;","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/browser/cmux/socket-client.ts#L373-L409","documentation":"#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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: pointing at a random debug socket\nnew CmuxSocketClient({ socketPath: \"/tmp/app.sock\" })\n// after: the cmux daemon's control socket\nnew CmuxSocketClient({ socketPath: cmuxControlSocketPath })","handlingStrategy":"try-catch","validationCode":"// preflight: confirm the socket answers with a framed JSON line\nconst probe = net.createConnection({ path: socketPath });\n// if it's a TCP relay endpoint use { host: '127.0.0.1', port } instead","typeGuard":"function looksLikeJsonLine(s: string): boolean {\n  try { const v = JSON.parse(s); return typeof v === \"object\" && v !== null; } catch { return false; }\n}","tryCatchPattern":"try {\n  return await client.request(method, params);\n} catch (err) {\n  if (err instanceof ToolError && err.message.startsWith(\"Invalid cmux socket JSON response\")) {\n    // wrong endpoint or daemon fault: verify socketPath, restart daemon, retry once\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["json","protocol","malformed-response"],"backgroundTag":"invalid-json-response","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}