Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(daemon): keep one separator spelling for the session root on Windows
Martin Vogelc1b9c451c7f1
diff --git a/src/daemon/application.c b/src/daemon/application.cindex 69ff52ec7..8e3fea72f 100644--- a/src/daemon/application.c+++ b/src/daemon/application.c@@ -379,6 +379,20 @@ static bool application_canonical_directory_exists(const char *path) {return cbm_path_info_utf8(path, &info) == 0 && info.is_directory;}+/* The daemon's one spelling of a repository root. cbm_canonical_path answers in+ * the platform's native form (backslashes on Windows) while every tool handler+ * normalizes the separators of the paths it canonicalizes. A root kept native+ * is a second name for one directory, and the exact comparison downstream -+ * index-args equality when a request joins the job already running for that+ * root - never matches it. */+static bool application_canonical_root(const char *path, char *out, size_t out_size) {+ if (!cbm_canonical_path(path, out, out_size)) {+ return false;+ }+ cbm_normalize_path_sep(out);+ return true;+}+static cbm_daemon_application_watch_t *application_find_watch_locked(cbm_daemon_application_t *application, const char *project) {for (cbm_daemon_application_watch_t *watch = application->watches; watch; watch = watch->next) {@@ -2355,9 +2369,10 @@ static cbm_daemon_runtime_application_status_t application_set_context(}char canonical_root[APPLICATION_PATH_CAP] = {0};char canonical_allowed[APPLICATION_PATH_CAP] = {0};- bool canonical = cbm_canonical_path(root, canonical_root, sizeof(canonical_root));+ bool canonical = application_canonical_root(root, canonical_root, sizeof(canonical_root));if (canonical && allowed_present) {- canonical = cbm_canonical_path(allowed, canonical_allowed, sizeof(canonical_allowed));+ canonical =+ application_canonical_root(allowed, canonical_allowed, sizeof(canonical_allowed));}canonical = canonical && application_canonical_directory_exists(canonical_root);bool set =@@ -3372,7 +3387,7 @@ static int application_background_index(cbm_daemon_application_t *application,return -1;}char canonical_root[APPLICATION_PATH_CAP];- if (!cbm_canonical_path(root_path, canonical_root, sizeof(canonical_root)) ||+ if (!application_canonical_root(root_path, canonical_root, sizeof(canonical_root)) ||!application_canonical_directory_exists(canonical_root)) {return -1;}diff --git a/src/mcp/mcp.c b/src/mcp/mcp.cindex 3259221c4..14da18e75 100644--- a/src/mcp/mcp.c+++ b/src/mcp/mcp.c@@ -1765,7 +1765,18 @@ bool cbm_mcp_server_set_session_context(cbm_mcp_server_t *srv, const char *sessireturn false;}- char *project = cbm_project_name_from_path(session_root);+ /* Keep both roots in the one spelling every tool handler produces. Each+ * handler normalizes separators after canonicalizing, so a root stored in+ * the platform's native form (backslashes on Windows) is a second name for+ * the same directory - and the daemon compares roots exactly. An explicit+ * index_repository request for this root was refused as an options+ * conflict instead of joining the auto-index job already running for it,+ * because the job's repo_path never matched the request's. */+ char root[sizeof(srv->session_root)];+ snprintf(root, sizeof(root), "%s", session_root);+ cbm_normalize_path_sep(root);++ char *project = cbm_project_name_from_path(root);if (!project || project[0] == '\0' || strlen(project) >= sizeof(srv->session_project)) {free(project);return false;@@ -1776,8 +1787,9 @@ bool cbm_mcp_server_set_session_context(cbm_mcp_server_t *srv, const char *sessifree(project);return false;}+ cbm_normalize_path_sep(allowed_copy);- snprintf(srv->session_root, sizeof(srv->session_root), "%s", session_root);+ snprintf(srv->session_root, sizeof(srv->session_root), "%s", root);snprintf(srv->session_project, sizeof(srv->session_project), "%s", project);free(project);diff --git a/tests/test_daemon.c b/tests/test_daemon.cindex fb0d0095a..ff0bac8cf 100644--- a/tests/test_daemon.c+++ b/tests/test_daemon.c@@ -467,6 +467,26 @@ TEST(daemon_sessions_keep_distinct_roots_and_allowed_root_policy) {PASS();}+/* The daemon canonicalizes a client's root through the platform API, which on+ * Windows answers in backslash form, while every tool handler normalizes the+ * separators of the paths it canonicalizes. Stored in its native form, one+ * directory had two names, and an explicit index_repository request was+ * refused as an options conflict instead of joining the auto-index job already+ * running for that root. Separators fold on every platform, so the check binds+ * wherever the suite runs. */+TEST(daemon_session_context_keeps_one_spelling_of_a_root) {+ cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);+ ASSERT_NOT_NULL(srv);+ cbm_mcp_server_set_background_tasks(srv, false);++ ASSERT_TRUE(cbm_mcp_server_set_session_context(srv, "C:\\repos\\cbm", "C:\\repos"));+ ASSERT_STR_EQ(cbm_mcp_server_session_root(srv), "C:/repos/cbm");+ ASSERT_STR_EQ(cbm_mcp_server_allowed_root(srv), "C:/repos");++ cbm_mcp_server_free(srv);+ PASS();+}+SUITE(daemon) {RUN_TEST(daemon_client_ids_are_connection_bound);RUN_TEST(daemon_shared_job_survives_until_final_subscriber_disconnects);@@ -480,4 +500,5 @@ SUITE(daemon) {RUN_TEST(daemon_bridge_rejects_embedded_nul_body);RUN_TEST(daemon_bridge_rejects_oversized_headers);RUN_TEST(daemon_sessions_keep_distinct_roots_and_allowed_root_policy);+ RUN_TEST(daemon_session_context_keeps_one_spelling_of_a_root);}