Skip to content

Commit 4788b0d

Browse files
committed
Fix session project name mismatch with indexed project name
detect_session used a two-component path algorithm (e.g. "project_dir- codebase-memory-mcp") while the pipeline used cbm_project_name_from_path with the full absolute path (e.g. "Users-martinvogel-project_dir- codebase-memory-mcp"). This caused session queries to look for a .db file that didn't match the indexed name, silently returning empty results. Fix: use cbm_project_name_from_path in detect_session so both paths produce the same project name. Update integration test to accept guard error after project deletion (correct new behavior from PR #120).
1 parent c788469 commit 4788b0d

2 files changed

Lines changed: 11 additions & 26 deletions

File tree

src/mcp/mcp.c

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,30 +2629,14 @@ static void detect_session(cbm_mcp_server_t *srv) {
26292629
}
26302630
}
26312631

2632-
/* Derive project name from path */
2632+
/* Derive project name from path — must match cbm_project_name_from_path
2633+
* used by the pipeline, otherwise session queries look for a .db file
2634+
* that doesn't match the indexed project name. */
26332635
if (srv->session_root[0]) {
2634-
/* Use last two path components joined by dash, matching Go's ProjectNameFromPath */
2635-
const char *p = srv->session_root;
2636-
const char *last_slash = strrchr(p, '/');
2637-
if (last_slash && last_slash > p) {
2638-
const char *prev = last_slash - 1;
2639-
while (prev > p && *prev != '/') {
2640-
prev--;
2641-
}
2642-
if (*prev == '/') {
2643-
prev++;
2644-
}
2645-
snprintf(srv->session_project, sizeof(srv->session_project), "%.*s",
2646-
(int)(strlen(p) - (size_t)(prev - p)), prev);
2647-
/* Replace / with - */
2648-
for (char *c = srv->session_project; *c; c++) {
2649-
if (*c == '/') {
2650-
*c = '-';
2651-
}
2652-
}
2653-
} else {
2654-
snprintf(srv->session_project, sizeof(srv->session_project), "%s",
2655-
last_slash ? last_slash + 1 : p);
2636+
char *pname = cbm_project_name_from_path(srv->session_root);
2637+
if (pname) {
2638+
snprintf(srv->session_project, sizeof(srv->session_project), "%s", pname);
2639+
free(pname);
26562640
}
26572641
}
26582642
}

tests/test_integration.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,13 @@ TEST(integ_mcp_delete_project) {
406406
ASSERT_NOT_NULL(strstr(resp, "deleted"));
407407
free(resp);
408408

409-
/* After deletion, search should return empty */
409+
/* After deletion, search should return an error (not indexed) or empty results */
410410
snprintf(args, sizeof(args), "{\"label\":\"Function\",\"project\":\"%s\"}", g_project);
411411
resp = call_tool("search_graph", args);
412412
ASSERT_NOT_NULL(resp);
413-
/* Should show 0 results or empty */
414-
ASSERT_NOT_NULL(strstr(resp, "total"));
413+
/* Guard returns "not indexed" error or "no project loaded"; either is correct */
414+
ASSERT_TRUE(strstr(resp, "total") != NULL || strstr(resp, "not indexed") != NULL ||
415+
strstr(resp, "no project loaded") != NULL);
415416
free(resp);
416417
PASS();
417418
}

0 commit comments

Comments
 (0)