Skip to content

Commit 14bf8f0

Browse files
committed
fix(mcp): keep request timing, defer protocol behaviour changes
Split the PR along the line the review asked for. The request timing and transport fields stay: every mcp.request log line carries handler_duration_ms, response_serialization_ms, cancelled and timed_out, and a search that reaches its deadline logs status=timeout. The behaviour changes go back to the base text and need a separate maintainer decision: stricter jsonrpc/id parsing, dropping "result":null, NULL returns from the response formatters, leaving the stdio loop on a missing response or an input/output failure, the removed blocking-poll fallback, the HTTP 500 path, the daemon session end on a missing response, and the update-notice warning. Their tests go with them. The list_projects sort guard is dropped as well (main has the same fix). cbm_mcp_server_handle formats its three responses with cbm_jsonrpc_format_response directly; a NULL reply still marks the request as an error. The cbm_log_mcp_request checks in tests/test_log.c are back with the new signature, plus checks for the new fields and for status=timeout. clang-format on the new lines. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 6f17caa commit 14bf8f0

6 files changed

Lines changed: 92 additions & 321 deletions

File tree

‎src/daemon/application.c‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,19 +2144,13 @@ static void application_update_notice_inject(cbm_daemon_application_session_t *s
21442144
char **response_io) {
21452145
cbm_daemon_application_t *application = session->application;
21462146
cbm_mutex_lock(&application->mutex);
2147-
bool should_inject = session->background_eligible && !session->update_notice_delivered &&
2148-
!session->pending_update_notice && application->update_thread_done &&
2149-
application->update_notice[0];
2150-
bool injected = should_inject &&
2151-
cbm_mcp_jsonrpc_response_prepend_notice(response_io,
2152-
application->update_notice);
2153-
if (injected) {
2147+
if (session->background_eligible && !session->update_notice_delivered &&
2148+
!session->pending_update_notice && application->update_thread_done &&
2149+
application->update_notice[0] &&
2150+
cbm_mcp_jsonrpc_response_prepend_notice(response_io, application->update_notice)) {
21542151
session->pending_update_notice = true;
21552152
}
21562153
cbm_mutex_unlock(&application->mutex);
2157-
if (should_inject && !injected) {
2158-
cbm_log_warn("daemon.update_notice.inject_failed", "status", "omitted");
2159-
}
21602154
}
21612155

21622156
static bool application_watch_job_subscription_exists_locked(
@@ -2562,13 +2556,6 @@ static cbm_daemon_runtime_application_status_t application_mcp_request(
25622556
parsed_ok && parsed.has_id && parsed.method && strcmp(parsed.method, "tools/call") == 0;
25632557
char *response = cbm_mcp_server_handle(session->mcp, message);
25642558
free(message);
2565-
if (!response && (!parsed_ok || parsed.has_id)) {
2566-
cbm_log_error("daemon.mcp.response_missing", "status", "error");
2567-
if (parsed_ok) {
2568-
cbm_jsonrpc_request_free(&parsed);
2569-
}
2570-
return CBM_DAEMON_RUNTIME_APPLICATION_HANDLER_ERROR;
2571-
}
25722559
if (initialize_request && application_jsonrpc_success(response)) {
25732560
cbm_mutex_lock(&session->application->mutex);
25742561
session->pending_background_initialize = true;

‎src/foundation/log.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ void cbm_log_mcp_request(const char *method, const char *tool_name, bool is_erro
376376
const char *status = timed_out ? "timeout" : (is_error ? "error" : "ok");
377377
if (tool_name && tool_name[0] != '\0') {
378378
cbm_log(is_error ? CBM_LOG_WARN : CBM_LOG_INFO, "mcp.request", "protocol", "jsonrpc",
379-
"method", method ? method : "", "tool", tool_name, "status", status,
380-
"duration_ms", duration_ms, "handler_duration_ms", handler_duration_ms,
379+
"method", method ? method : "", "tool", tool_name, "status", status, "duration_ms",
380+
duration_ms, "handler_duration_ms", handler_duration_ms,
381381
"response_serialization_ms", response_serialization_ms, "cancelled",
382382
cancelled ? "true" : "false", "timed_out", timed_out ? "true" : "false", NULL);
383383
} else {

0 commit comments

Comments
 (0)