A client that cannot reach the daemon must SAY SO, in the caller's own * protocol. An MCP client speaks JSON-RPC over stdout, and the old path * returned EXIT_FAILURE having written nothing at all: agents saw a transport * that closed mid-handshake and reported "Connection closed" with no cause, * while the real reason (image rejection, startup timeout, conflict) sat in * bootstrap_result.mes
| 1758 | * cannot start always says why", so it belongs on every client-path exit, not |
| 1759 | * just the one that happened to be fixed first. */ |
| 1760 | static void main_report_client_failure(cbm_daemon_process_role_t role, const char *detail) { |
| 1761 | if (cbm_daemon_process_role_requires_client(role)) { |
| 1762 | char escaped[MAIN_CLIENT_FAILURE_DETAIL_CAP * 2]; |
| 1763 | size_t out = 0; |
| 1764 | for (size_t i = 0; detail[i] && out + 2 < sizeof(escaped); i++) { |
| 1765 | unsigned char c = (unsigned char)detail[i]; |
| 1766 | if (c == '"' || c == '\\') { |
| 1767 | escaped[out++] = '\\'; |
| 1768 | escaped[out++] = (char)c; |
| 1769 | } else if (c < 0x20) { |
| 1770 | escaped[out++] = ' '; |
| 1771 | } else { |
| 1772 | escaped[out++] = (char)c; |
| 1773 | } |
| 1774 | } |
| 1775 | escaped[out] = '\0'; |
| 1776 | (void)fprintf(stdout, |
| 1777 | "{\"jsonrpc\":\"2.0\",\"id\":null,\"error\":{\"code\":-32001," |
| 1778 | "\"message\":\"%s\"}}\n", |
| 1779 | escaped); |
| 1780 | (void)fflush(stdout); |
| 1781 | } |
| 1782 | (void)fprintf(stderr, "codebase-memory-mcp: %s\n", detail); |
| 1783 | } |
| 1784 | |
| 1785 | static void main_report_client_bootstrap_failure(cbm_daemon_process_role_t role, |
| 1786 | const cbm_daemon_bootstrap_result_t *result) { |
no test coverage detected