{"record":{"id":"c6aa01e641a9299d","repo":"can1357/oh-my-pi","slug":"unexpected-broker-response-result-op","errorCode":null,"errorMessage":"Unexpected broker response ${result.op}","messagePattern":"Unexpected broker response (.+?)","errorType":"console","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/ps-cli.ts","lineNumber":166,"sourceCode":"\t}\n}\n\n// ---------------------------------------------------------------------------\n// Named actions\n// ---------------------------------------------------------------------------\n\nasync function actionClient(flags: PsCommandArgs[\"flags\"]): Promise<DaemonBrokerClient> {\n\tif (flags.global) return daemonClientForGlobal(flags.global);\n\treturn daemonClientForProject(flags.dir ?? getProjectDir());\n}\n\nasync function runAction(cmd: PsCommandArgs, name: string): Promise<void> {\n\tconst client = await actionClient(cmd.flags);\n\ttry {\n\t\tswitch (cmd.action) {\n\t\t\tcase \"info\": {\n\t\t\t\tconst result = await client.request({ op: \"describe\", name });\n\t\t\t\tif (result.op !== \"describe\") throw new Error(`Unexpected broker response ${result.op}`);\n\t\t\t\tif (cmd.flags.json) {\n\t\t\t\t\tconsole.log(JSON.stringify({ ...result.daemon, spec: result.spec }, null, 2));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst daemon = result.daemon;\n\t\t\t\tconsole.log(daemonLabel(daemon));\n\t\t\t\tconsole.log(`  command:  ${formatCommand(result.spec)}`);\n\t\t\t\tconsole.log(`  cwd:      ${result.spec.cwd}`);\n\t\t\t\tif (!TERMINAL_STATES[daemon.state])\n\t\t\t\t\tconsole.log(`  uptime:   ${formatDuration(Date.now() - daemon.startedAt)}`);\n\t\t\t\tif (daemon.exitReason) console.log(`  exit:     ${daemon.exitReason}`);\n\t\t\t\tconsole.log(`  restarts: ${daemon.restartCount} (policy: ${result.spec.restart})`);\n\t\t\t\tconsole.log(\n\t\t\t\t\t`  pty: ${result.spec.pty}  persist: ${result.spec.persist}  detached: ${result.spec.detached}  owner: ${daemon.owner ?? \"-\"}`,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"logs\":","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/ps-cli.ts#L148-L184","documentation":"`omp ps info` sends a `{op:\"describe\", name}` request to the daemon broker and expects a describe reply back. This guard throws when the broker answers with any other response variant, meaning the wire contract between the CLI and the broker was violated (the request and reply ops no longer line up). It is a defensive protocol-mismatch check, not a user-facing condition caused by the daemon itself.","triggerScenarios":"Calling `runAction` with action \"info\" while `client.request({op:\"describe\", name})` returns a response whose `op` field is anything other than \"describe\" — e.g. an error-shaped response, a `not-found` variant, or a broker from a different omp version replying with an older/newer message shape.","commonSituations":"Running an `omp` CLI binary that is older or newer than the broker process it connects to (version skew after an upgrade while a long-lived broker from the previous version is still running); a proxy/wrapper intercepting the broker socket; a broker bug replying with an error op instead of describe.","solutions":["Restart the broker (or reboot the machine / kill the stale broker process) so the broker and CLI come from the same omp version.","Reinstall/upgrade omp so the CLI and the daemon runtime match (`bun install` or the install script for both).","Run with `--json` after the versions match; if it still reproduces, capture the actual `result.op` value and file a bug against the launch/protocol code."],"exampleFix":"// before\nconst result = await client.request({ op: \"describe\", name });\nif (result.op !== \"describe\") throw new Error(`Unexpected broker response ${result.op}`);\n// after\nconst result = await client.request({ op: \"describe\", name });\nif (result.op === \"error\") throw new Error(`Broker error: ${result.message}`);\nif (result.op !== \"describe\") throw new Error(`Unexpected broker response ${result.op}`);","handlingStrategy":"type-guard","validationCode":"const brokerAlive = await Bun.file(scope.runtimeDir + \"/broker.json\").exists().catch(() => false);\nif (!brokerAlive) throw new Error(\"Broker not running; it will be revived on next command\");","typeGuard":"function isDescribeResponse(r: { op: string }): r is { op: \"describe\"; daemon: DaemonSnapshot; spec: DaemonSpec } {\n  return r.op === \"describe\";\n}","tryCatchPattern":"try {\n  const result = await client.request({ op: \"describe\", name });\n  if (!isDescribeResponse(result)) throw new Error(`Unexpected broker response ${result.op}`);\n} catch (err) {\n  console.error(chalk.red(err instanceof Error ? err.message : String(err)));\n}","preventionTips":["Keep CLI and broker on the same omp version; restart stale brokers after upgrading.","Narrow responses with a discriminated-union type guard instead of ad-hoc string comparisons.","Map known error ops (e.g. not-found) to friendly messages before the generic guard."],"tags":["ipc","protocol-mismatch","version-skew"],"backgroundTag":"unexpected-response-op","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}