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(store): keep unresolved_calls rows out of the missed graph
Martin Vogel8ca839363f41
diff --git a/src/store/store.c b/src/store/store.cindex 112624383..56248eeec 100644--- a/src/store/store.c+++ b/src/store/store.c@@ -4516,6 +4516,18 @@ static void cov_json_escape(char *dst, size_t dstsz, const char *src) {* {kind, detail}. Queryable via query_graph(graph="missed") with zero* cypher-engine changes; the real project's graph gains no rows. Derived* data — rebuilt from the authoritative (post-prune) table contents. */+/* Coverage kinds that never materialize in the miss graph. not_indexed_*+ * rows are by-design exclusions, not failures. unresolved_calls rows (#2265)+ * describe files that WERE indexed; their call evidence is reported by+ * check_index_coverage and trace_path, and as a File row it would also+ * replace a parse_partial row for the same path (rows arrive ordered by+ * rel_path, kind, and the File upsert keeps the last one). */+static bool cov_kind_outside_miss_graph(const char *kind) {+ static const char by_design_prefix[] = "not_indexed";+ return strncmp(kind, by_design_prefix, sizeof(by_design_prefix) - 1) == 0 ||+ strcmp(kind, "unresolved_calls") == 0;+}+/* Fingerprint of the FAILURE rows the shadow graph derives from. When the* set is unchanged since the last rebuild, the wipe-and-rebuild (tens of* thousands of node/edge upserts probing the full-size nodes index -- a@@ -4527,7 +4539,7 @@ static void cov_failure_fingerprint(const cbm_coverage_row_t *rows, int count,cbm_sha256_ctx sha;cbm_sha256_init(&sha);for (int i = 0; i < count; i++) {- if (!rows[i].kind || strncmp(rows[i].kind, "not_indexed", 11) == 0) {+ if (!rows[i].kind || cov_kind_outside_miss_graph(rows[i].kind)) {continue;}const char *rel = rows[i].rel_path ? rows[i].rel_path : "";@@ -4626,11 +4638,11 @@ static int cov_rebuild_shadow_graph(cbm_store_t *s, const char *project) {return CBM_STORE_OK;}/* Only FAILURE rows materialize in the miss graph; a project whose only- * coverage rows are by-design not_indexed_* entries gets NO graph (not- * even a bare root node). */+ * coverage rows are by-design not_indexed_* entries or unresolved_calls+ * evidence gets NO graph (not even a bare root node). */int failure_count = 0;for (int i = 0; i < count; i++) {- if (!rows[i].kind || strncmp(rows[i].kind, "not_indexed", 11) != 0) {+ if (!rows[i].kind || !cov_kind_outside_miss_graph(rows[i].kind)) {failure_count++;}}@@ -4671,8 +4683,10 @@ static int cov_rebuild_shadow_graph(cbm_store_t *s, const char *project) {}/* The missed graph shows FAILURES ("we did not manage") only —* by-design not_indexed_* rows stay out of it, so the UI's- * report-an-edge-case callout never fires for gitignored paths. */- if (rows[i].kind && strncmp(rows[i].kind, "not_indexed", 11) == 0) {+ * report-an-edge-case callout never fires for gitignored paths, and+ * unresolved_calls rows stay out so a parse_partial row for the same+ * file keeps its File node. */+ if (rows[i].kind && cov_kind_outside_miss_graph(rows[i].kind)) {continue;}char pathbuf[CBM_SZ_1K];diff --git a/src/store/store.h b/src/store/store.hindex 36a05d8c4..66ea2079f 100644--- a/src/store/store.h+++ b/src/store/store.h@@ -860,10 +860,11 @@ int cbm_store_observed_lookup(cbm_store_t *s, const char *project, const char *cvoid cbm_store_coverage_meta_clear(cbm_coverage_meta_t *meta);/* Name of the derived miss-graph shadow project ("<project>::missed").- * cbm_store_coverage_replace materializes the coverage rows as a file-+ * cbm_store_coverage_replace materializes the coverage FAILURE rows as a file-* structure graph (Project → Folder → File{kind, detail}) under this project* name — queryable via the normal cypher path without touching the real- * project's graph. */+ * project's graph. By-design not_indexed_* rows and unresolved_calls evidence+ * stay out of it. */void cbm_store_coverage_shadow_project(char *dst, size_t dstsz, const char *project);void cbm_store_free_coverage(cbm_coverage_row_t *rows, int count);diff --git a/tests/test_store_nodes.c b/tests/test_store_nodes.cindex ccd3fc6fa..5d005c00e 100644--- a/tests/test_store_nodes.c+++ b/tests/test_store_nodes.c@@ -2603,6 +2603,109 @@ TEST(store_coverage_replace_rolls_back_when_shadow_rebuild_fails) {PASS();}+/* Copy store_meta's shadow fingerprint for `project` into `out` ("" if absent). */+static void coverage_shadow_fp(cbm_store_t *s, const char *project, char *out, size_t cap) {+ out[0] = '\0';+ char key[256];+ snprintf(key, sizeof(key), "coverage_shadow_fp:%s", project);+ sqlite3_stmt *stmt = NULL;+ if (sqlite3_prepare_v2(cbm_store_get_db(s), "SELECT v FROM store_meta WHERE k = ?1;", -1, &stmt,+ NULL) != SQLITE_OK) {+ return;+ }+ sqlite3_bind_text(stmt, 1, key, -1, SQLITE_TRANSIENT);+ if (sqlite3_step(stmt) == SQLITE_ROW && sqlite3_column_text(stmt, 0)) {+ snprintf(out, cap, "%s", (const char *)sqlite3_column_text(stmt, 0));+ }+ sqlite3_finalize(stmt);+}++/* #2265: unresolved_calls rows describe files that WERE indexed, so they stay+ * out of the "<project>::missed" graph like by-design not_indexed_* rows:+ * (a) a project whose only rows are unresolved_calls gets no shadow graph,+ * (b) a file with parse_partial AND unresolved_calls keeps its parse_partial+ * File node (the later unresolved_calls row used to replace it), and+ * (c) the shadow fingerprint ignores unresolved_calls rows, so the skip gate+ * and store_meta match a project without them. */+TEST(store_coverage_shadow_excludes_unresolved_calls) {+ cbm_store_t *s = cbm_store_open_memory();+ ASSERT_NOT_NULL(s);+ const char *only = "cov-unres-only";+ const char *mixed = "cov-unres-mixed";+ const char *plain = "cov-unres-plain";+ ASSERT_EQ(cbm_store_upsert_project(s, only, "/tmp/cov-unres-only"), CBM_STORE_OK);+ ASSERT_EQ(cbm_store_upsert_project(s, mixed, "/tmp/cov-unres-mixed"), CBM_STORE_OK);+ ASSERT_EQ(cbm_store_upsert_project(s, plain, "/tmp/cov-unres-plain"), CBM_STORE_OK);+ ASSERT_EQ(cbm_store_upsert_file_hash(s, only, "src/a.go", "", 1, 1), CBM_STORE_OK);+ ASSERT_EQ(cbm_store_upsert_file_hash(s, only, "src/b.go", "", 2, 2), CBM_STORE_OK);+ ASSERT_EQ(cbm_store_upsert_file_hash(s, mixed, "src/both.go", "", 3, 3), CBM_STORE_OK);+ ASSERT_EQ(cbm_store_upsert_file_hash(s, mixed, "lib/calls.go", "", 4, 4), CBM_STORE_OK);+ ASSERT_EQ(cbm_store_upsert_file_hash(s, plain, "src/both.go", "", 3, 3), CBM_STORE_OK);++ /* (a) Only unresolved_calls (plus a by-design row): no shadow project. */+ cbm_coverage_row_t only_rows[] = {+ {.rel_path = "src/a.go", .kind = "unresolved_calls", .detail = "[{\"candidate\":\"a.f\"}]"},+ {.rel_path = "src/b.go", .kind = "unresolved_calls", .detail = "[{\"candidate\":\"b.g\"}]"},+ {.rel_path = "vendor", .kind = "not_indexed_dir", .detail = "excluded subtree"},+ };+ ASSERT_EQ(cbm_store_coverage_replace(s, only, only_rows, 3), CBM_STORE_OK);+ cbm_coverage_row_t *got = NULL;+ int n = 0;+ ASSERT_EQ(cbm_store_coverage_get(s, only, &got, &n), CBM_STORE_OK);+ ASSERT_EQ(n, 3); /* the table keeps the evidence; only the view skips it */+ cbm_store_free_coverage(got, n);+ ASSERT_EQ(cbm_store_count_nodes(s, "cov-unres-only::missed"), 0);+ cbm_project_t shadow = {0};+ ASSERT_EQ(cbm_store_get_project(s, "cov-unres-only::missed", &shadow), CBM_STORE_NOT_FOUND);+ cbm_project_free_fields(&shadow);++ /* (b) parse_partial + unresolved_calls on one path, and a second file+ * with unresolved_calls only: the shadow holds exactly the parse_partial+ * File node under src/. */+ cbm_coverage_row_t mixed_rows[] = {+ {.rel_path = "src/both.go", .kind = "parse_partial", .detail = "3-4"},+ {.rel_path = "src/both.go",+ .kind = "unresolved_calls",+ .detail = "[{\"candidate\":\"both.h\"}]"},+ {.rel_path = "lib/calls.go",+ .kind = "unresolved_calls",+ .detail = "[{\"candidate\":\"calls.k\"}]"},+ };+ ASSERT_EQ(cbm_store_coverage_replace(s, mixed, mixed_rows, 3), CBM_STORE_OK);+ cbm_node_t *nodes = NULL;+ int nc = 0;+ ASSERT_EQ(cbm_store_find_nodes_by_label(s, "cov-unres-mixed::missed", "File", &nodes, &nc),+ CBM_STORE_OK);+ ASSERT_EQ(nc, 1);+ ASSERT_STR_EQ(nodes[0].file_path, "src/both.go");+ ASSERT_NOT_NULL(strstr(nodes[0].properties_json, "\"kind\":\"parse_partial\""));+ ASSERT_NOT_NULL(strstr(nodes[0].properties_json, "\"detail\":\"3-4\""));+ ASSERT_NULL(strstr(nodes[0].properties_json, "unresolved_calls"));+ cbm_store_free_nodes(nodes, nc);+ nodes = NULL;+ nc = 0;+ ASSERT_EQ(cbm_store_find_nodes_by_label(s, "cov-unres-mixed::missed", "Folder", &nodes, &nc),+ CBM_STORE_OK);+ ASSERT_EQ(nc, 1);+ ASSERT_STR_EQ(nodes[0].name, "src");+ cbm_store_free_nodes(nodes, nc);++ /* (c) Same failure rows without the unresolved_calls evidence: the stored+ * fingerprints match. */+ cbm_coverage_row_t plain_row = {+ .rel_path = "src/both.go", .kind = "parse_partial", .detail = "3-4"};+ ASSERT_EQ(cbm_store_coverage_replace(s, plain, &plain_row, 1), CBM_STORE_OK);+ char fp_mixed[128];+ char fp_plain[128];+ coverage_shadow_fp(s, mixed, fp_mixed, sizeof(fp_mixed));+ coverage_shadow_fp(s, plain, fp_plain, sizeof(fp_plain));+ ASSERT_TRUE(fp_plain[0] != '\0');+ ASSERT_STR_EQ(fp_mixed, fp_plain);++ cbm_store_close(s);+ PASS();+}+SUITE(store_nodes) {RUN_TEST(store_qn_suffix_is_literal);RUN_TEST(store_qn_suffix_is_unbounded);@@ -2612,6 +2715,7 @@ SUITE(store_nodes) {RUN_TEST(store_coverage_meta_zero_row_truncation_and_delete);RUN_TEST(store_coverage_replace_rejects_invalid_row_arguments);RUN_TEST(store_coverage_replace_rolls_back_when_shadow_rebuild_fails);+ RUN_TEST(store_coverage_shadow_excludes_unresolved_calls);RUN_TEST(sql_label_allowlists_match_cbm_label_is_type_like);RUN_TEST(sql_relation_labels_match_cbm_label_is_relation);RUN_TEST(store_open_memory);