{"record":{"id":"7dd418f8cc23b7dc","repo":"nanocoai/nanoclaw","slug":"failed-to-write-ncl-cli-response","errorCode":null,"errorMessage":"Failed to write ncl CLI response","messagePattern":"Failed to write ncl CLI response","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cli/socket-server.ts","lineNumber":103,"sourceCode":"      },\n    });\n    return;\n  }\n\n  // Host caller — connecting to data/ncl.sock requires file-system access\n  // to a 0600 socket owned by the host user, so we treat the socket path\n  // itself as the auth boundary.\n  const ctx: CallerContext = { caller: 'host' };\n  const res = await dispatch(req, ctx);\n  write(conn, res);\n}\n\nfunction write(conn: net.Socket, frame: ResponseFrame): void {\n  try {\n    conn.write(JSON.stringify(frame) + '\\n');\n    conn.end();\n  } catch (err) {\n    log.warn('Failed to write ncl CLI response', { err });\n  }\n}\n\nfunction isRequestFrame(x: unknown): x is RequestFrame {\n  if (!x || typeof x !== 'object') return false;\n  const o = x as Record<string, unknown>;\n  return typeof o.id === 'string' && typeof o.command === 'string' && typeof o.args === 'object' && o.args !== null;\n}\n","sourceCodeStart":85,"sourceCodeEnd":112,"githubUrl":"https://github.com/nanocoai/nanoclaw/blob/294ef2aee85218b23ad30eda9dfe10e590b54a8c/src/cli/socket-server.ts#L85-L112","documentation":"The socket server failed to serialize or write a response frame back to the client and the connection could not be closed cleanly. The client will see a hang or EOF instead of a response; the server itself stays healthy.","triggerScenarios":"`conn.write`/`conn.end` throws — client already disconnected (EPIPE), socket destroyed, or the response frame contains a value JSON.stringify chokes on (circular).","commonSituations":"Client timeout killed the connection before the response arrived; huge response frames on a slow socket.","solutions":["Retry the ncl command — transient disconnects are the usual cause","Narrow large queries with `--json` plus explicit ids or list filters","Check that the client isn't timing out (raise timeout or run on-host)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { conn.write(JSON.stringify(frame)+'\\n'); conn.end(); } catch { /* client gone; nothing to do */ }","preventionTips":["Retry ncl commands that hang — usually a dropped connection","Keep responses small with filters/--json","Set sane client timeouts so dead connections are reaped"],"tags":["ncl","unix-socket","write-failure","transport"],"backgroundTag":"broken-pipe-write-failure","analyzedSha":"294ef2aee85218b23ad30eda9dfe10e590b54a8c","analyzedAt":"2026-08-28T13:59:10.357Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}