{"record":{"id":"6299142cba1b372b","repo":"can1357/oh-my-pi","slug":"invalid-cmux-socket-response-expected-object","errorCode":null,"errorMessage":"Invalid cmux socket response: expected object","messagePattern":"Invalid cmux socket response: expected object","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/browser/cmux/socket-client.ts","lineNumber":394,"sourceCode":"\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;\n\t\tthis.#rejectAll(new ToolError(`cmux socket error: ${err.message}`));\n\t\tthis.#socket?.destroy();\n\t\tthis.#socket = null;","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/browser/cmux/socket-client.ts#L376-L412","documentation":"After a reply line parses as JSON, #parseResponse requires the payload to be a JSON object. Scalars, arrays, strings, or null payloads cannot carry the {ok, result, error} envelope, so this ToolError is thrown. It signals the peer speaks JSON but not the cmux response envelope.","triggerScenarios":"Daemon returns a bare JSON array/string/null for a method; a different JSON-RPC-ish service on the socket replies with non-envelope JSON (e.g. {\"jsonrpc\":\"2.0\",...} without ok, or plain [1,2,3]).","commonSituations":"Pointing the client at a non-cmux JSON service on the same path/port; daemon regression emitting envelopes without ok for some methods; protocol version skew after an upgrade.","solutions":["Confirm the endpoint is the cmux daemon and the method is expected to return the {ok,...} envelope","Upgrade or downgrade the daemon so client/server protocol versions align","Inspect the raw reply (enable socket logging) to see what shape came back, then correct the caller or file a daemon bug"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isCmuxEnvelope(v: unknown): v is { ok: boolean; result?: unknown; error?: { code?: string; message?: string; details?: unknown } } {\n  return typeof v === \"object\" && v !== null && \"ok\" in v && typeof (v as { ok: unknown }).ok === \"boolean\";\n}","tryCatchPattern":"try {\n  return await client.request(method, params);\n} catch (err) {\n  if (err instanceof ToolError && err.message === \"Invalid cmux socket response: expected object\") {\n    // peer is not speaking the cmux envelope: check endpoint and protocol version\n  }\n  throw err;\n}","preventionTips":["Verify the endpoint is the cmux daemon, not another JSON service sharing the path/port","Run matching client/daemon versions so the {ok,result,error} envelope is guaranteed","If you wrap CmuxSocketClient, validate responses with an isCmuxEnvelope-style guard before consuming"],"tags":["json","schema","protocol"],"backgroundTag":"response-schema-mismatch","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}