Skip to content

Commit 3b1ea58

Browse files
metehanulusoyclaude
andcommitted
fix(mcp): ignore ::missed shadow rows when resolving a db's project name
The miss-graph pass inserts a second `projects` row ("<name>::missed") so its nodes satisfy the FK on nodes.project. Since DeusData#704, db_internal_project_name required the projects table to hold exactly one row, so any project with a miss graph vanished from list_projects and the graph UI, and the fallback-scan resolve path failed — the index looked empty while fully present. Filter out internal shadow rows (names containing "::") and require exactly one primary row instead. Adds a reproduce-first regression test modeled on the DeusData#704 fixture (red on the old code: 150 passed, 1 failed; green with the fix: 151 passed). Fixes DeusData#1044 Signed-off-by: metehanulusoy <ulusoy.metehan03@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 8c9ac98 commit 3b1ea58

2 files changed

Lines changed: 93 additions & 4 deletions

File tree

‎src/mcp/mcp.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,10 +1335,23 @@ static bool db_internal_project_name(const char *full_path, char *name_out, size
13351335
cbm_project_t *projs = NULL;
13361336
int n = 0;
13371337
bool ok = false;
1338-
if (cbm_store_list_projects(st, &projs, &n) == CBM_STORE_OK && n == 1 && projs[0].name &&
1339-
projs[0].name[0]) {
1340-
snprintf(name_out, name_sz, "%s", projs[0].name);
1341-
ok = true;
1338+
if (cbm_store_list_projects(st, &projs, &n) == CBM_STORE_OK) {
1339+
/* Ignore internal shadow projects ("<name>::missed" miss-graph rows):
1340+
* they share the db with the primary project and must not make it
1341+
* unresolvable — requiring n == 1 over ALL rows made every project
1342+
* with a miss graph vanish from list_projects and the UI (#1044). */
1343+
int primary = -1;
1344+
int primary_count = 0;
1345+
for (int i = 0; i < n; i++) {
1346+
if (projs[i].name && projs[i].name[0] && !strstr(projs[i].name, "::")) {
1347+
primary = i;
1348+
primary_count++;
1349+
}
1350+
}
1351+
if (primary_count == 1) {
1352+
snprintf(name_out, name_sz, "%s", projs[primary].name);
1353+
ok = true;
1354+
}
13421355
}
13431356
cbm_store_free_projects(projs, n);
13441357
if (ok && out_store) {

‎tests/test_mcp.c‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4134,6 +4134,81 @@ TEST(tool_resolve_store_by_internal_name_issue704) {
41344134
PASS();
41354135
}
41364136

4137+
/* ── #1044: a "<name>::missed" shadow row must not hide the project ──
4138+
*
4139+
* The miss-graph pass inserts a second `projects` row ("<name>::missed") so
4140+
* its nodes satisfy the FK on nodes.project. db_internal_project_name
4141+
* required the projects table to hold EXACTLY ONE row, so any project with
4142+
* a miss graph vanished from list_projects and the graph UI, and the
4143+
* fallback-scan resolve path failed.
4144+
*
4145+
* RED on buggy code / GREEN on the fix:
4146+
* A. list_projects still advertises "delta1044" while the shadow row exists.
4147+
* B. the shadow name itself is never advertised.
4148+
* C. search_graph(project="delta1044") still resolves and returns the node.
4149+
*/
4150+
TEST(tool_list_projects_ignores_missed_shadow_issue1044) {
4151+
char cache[256];
4152+
snprintf(cache, sizeof(cache), "/tmp/cbm-issue1044-XXXXXX");
4153+
if (!cbm_mkdtemp(cache)) {
4154+
PASS(); /* skip if mkdtemp fails — not a #1044 signal */
4155+
}
4156+
4157+
const char *saved = getenv("CBM_CACHE_DIR");
4158+
char *saved_copy = saved ? strdup(saved) : NULL;
4159+
cbm_setenv("CBM_CACHE_DIR", cache, 1);
4160+
4161+
ASSERT_TRUE(issue704_make_db(cache, "delta1044.db", "delta1044", "deltaFunc1044"));
4162+
4163+
/* Add the shadow row exactly the way the miss-graph pass does. */
4164+
char db_path[700];
4165+
snprintf(db_path, sizeof(db_path), "%s/delta1044.db", cache);
4166+
cbm_store_t *st = cbm_store_open_path(db_path);
4167+
ASSERT_NOT_NULL(st);
4168+
ASSERT_EQ(cbm_store_upsert_project(st, "delta1044::missed", ""), CBM_STORE_OK);
4169+
cbm_store_close(st);
4170+
4171+
cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
4172+
ASSERT_NOT_NULL(srv);
4173+
4174+
/* ── A + B: primary advertised, shadow hidden ─────────────────── */
4175+
char *list =
4176+
cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\","
4177+
"\"params\":{\"name\":\"list_projects\",\"arguments\":{}}}");
4178+
ASSERT_NOT_NULL(list);
4179+
ASSERT_NOT_NULL(strstr(list, "delta1044")); /* RED before: db skipped as ghost */
4180+
ASSERT_NULL(strstr(list, "::missed")); /* shadow never advertised */
4181+
free(list);
4182+
4183+
/* ── C: the project still resolves and returns its node ───────── */
4184+
char *q = cbm_mcp_server_handle(
4185+
srv, "{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/call\","
4186+
"\"params\":{\"name\":\"search_graph\",\"arguments\":{"
4187+
"\"project\":\"delta1044\",\"name_pattern\":\"deltaFunc1044\",\"limit\":5}}}");
4188+
ASSERT_NOT_NULL(q);
4189+
ASSERT_NOT_NULL(strstr(q, "deltaFunc1044"));
4190+
ASSERT_NULL(strstr(q, "not found"));
4191+
free(q);
4192+
4193+
cbm_mcp_server_free(srv);
4194+
4195+
/* ── cleanup ───────────────────────────────────────────────────── */
4196+
if (saved_copy) {
4197+
cbm_setenv("CBM_CACHE_DIR", saved_copy, 1);
4198+
free(saved_copy);
4199+
} else {
4200+
cbm_unsetenv("CBM_CACHE_DIR");
4201+
}
4202+
cbm_unlink(db_path);
4203+
char side1044[740];
4204+
snprintf(side1044, sizeof(side1044), "%s-wal", db_path);
4205+
cbm_unlink(side1044);
4206+
snprintf(side1044, sizeof(side1044), "%s-shm", db_path);
4207+
cbm_unlink(side1044);
4208+
cbm_rmdir(cache);
4209+
PASS();
4210+
}
4211+
41374212
/* ══════════════════════════════════════════════════════════════════
41384213
* QUERY STORE READ-ONLY (data-integrity reproductions)
41394214
*
@@ -5763,6 +5838,7 @@ SUITE(mcp) {
57635838
RUN_TEST(tool_bad_project_name_no_overflow_issue235);
57645839
RUN_TEST(tool_bad_project_error_valid_json_issue235);
57655840
RUN_TEST(tool_resolve_store_by_internal_name_issue704);
5841+
RUN_TEST(tool_list_projects_ignores_missed_shadow_issue1044);
57665842

57675843
/* auto_watch gate (distilled from PR #625) */
57685844
RUN_TEST(mcp_auto_watch_default_registers_watcher_on_connect);

0 commit comments

Comments
 (0)