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(pipeline): reconcile unresolved call coverage
Pcristin3f7f4d78b572
diff --git a/internal/cbm/cbm.h b/internal/cbm/cbm.hindex 1b5d3f3ef..9b49a3fe4 100644--- a/internal/cbm/cbm.h+++ b/internal/cbm/cbm.h@@ -294,6 +294,10 @@ typedef struct {// (self.compiler.apply_converters()). An object the// class owns, not a parameter: read by the weak-member// guard's unique-name exemption. Default false.+ /* Ephemeral coverage evidence, set only while resolving this file. Capture+ * it before releasing a spilled result; never retain registry pointers. */+ bool coverage_calls_emitted;+ const char *coverage_candidate_qn;} CBMCall;typedef struct {diff --git a/src/mcp/mcp.c b/src/mcp/mcp.cindex f3e700aea..a8acb0b29 100644--- a/src/mcp/mcp.c+++ b/src/mcp/mcp.c@@ -9046,6 +9046,147 @@ static int clamp_mcp_depth(int depth, const char *tool) {return depth;}+typedef struct {+ const cbm_node_t *roots;+ int root_count;+ const cbm_traverse_result_t *outbound;+ const cbm_traverse_result_t *inbound;+ bool include_tests;+ bool do_outbound;+ bool do_inbound;+} trace_coverage_scope_t;++typedef struct {+ CBMHashTable *callers;+ CBMHashTable *targets;+ bool unresolved_out;+ bool unresolved_in;+} trace_coverage_match_t;++static bool trace_coverage_add_node(CBMHashTable *table, const cbm_node_t *node) {+ if (!table || !node->qualified_name) {+ return true;+ }+ cbm_ht_set(table, node->qualified_name, (void *)node);+ return cbm_ht_has(table, node->qualified_name);+}++static bool trace_coverage_add_visited(CBMHashTable *table, const cbm_traverse_result_t *tr,+ bool include_tests) {+ if (!table) {+ return true;+ }+ for (int i = 0; i < tr->visited_count; i++) {+ const cbm_node_t *node = &tr->visited[i].node;+ if ((include_tests || !is_test_file(node->file_path)) &&+ !trace_coverage_add_node(table, node)) {+ return false;+ }+ }+ return true;+}++static bool trace_coverage_build_sets(trace_coverage_match_t *match,+ const trace_coverage_scope_t *scope) {+ for (int i = 0; i < scope->root_count; i++) {+ if (!trace_coverage_add_node(match->callers, &scope->roots[i]) ||+ !trace_coverage_add_node(match->targets, &scope->roots[i])) {+ return false;+ }+ }+ return trace_coverage_add_visited(match->callers, scope->outbound, scope->include_tests) &&+ trace_coverage_add_visited(match->targets, scope->inbound, scope->include_tests);+}++static void trace_coverage_match_site(trace_coverage_match_t *match, const char *rel_path,+ yyjson_val *site) {+ const char *caller = yyjson_get_str(yyjson_obj_get(site, "caller"));+ const char *candidate = yyjson_get_str(yyjson_obj_get(site, "candidate"));+ const cbm_node_t *caller_node =+ match->callers && caller ? cbm_ht_get(match->callers, caller) : NULL;+ int line = yyjson_get_int(yyjson_obj_get(site, "line"));+ /* The producer joins the exact byte span to the extractor's innermost+ * caller. Check its file and source range too; never match a containing+ * factory merely because its range overlaps. */+ if (caller_node && caller_node->file_path && strcmp(caller_node->file_path, rel_path) == 0 &&+ (line <= 0 || (line >= caller_node->start_line && line <= caller_node->end_line))) {+ match->unresolved_out = true;+ }+ /* A short-name collision is not evidence that the resolver considered+ * this traced target. */+ if (match->targets && candidate && cbm_ht_has(match->targets, candidate)) {+ match->unresolved_in = true;+ }+}++static void trace_coverage_match_row(trace_coverage_match_t *match, const cbm_coverage_row_t *row,+ const trace_coverage_scope_t *scope) {+ yyjson_doc *detail = yyjson_read(row->detail, strlen(row->detail), 0);+ yyjson_val *sites = detail ? yyjson_doc_get_root(detail) : NULL;+ if (!yyjson_is_arr(sites)) {+ match->unresolved_out = scope->do_outbound;+ match->unresolved_in = scope->do_inbound;+ } else {+ size_t idx;+ size_t max;+ yyjson_val *site;+ yyjson_arr_foreach(sites, idx, max, site) {+ trace_coverage_match_site(match, row->rel_path, site);+ }+ }+ if (detail) {+ yyjson_doc_free(detail);+ }+}++static bool trace_coverage_scan_rows(cbm_store_t *store, const char *project,+ trace_coverage_match_t *match,+ const trace_coverage_scope_t *scope) {+ cbm_coverage_row_t *rows = NULL;+ int row_count = 0;+ if (cbm_store_coverage_get_unresolved_calls(store, project, &rows, &row_count) !=+ CBM_STORE_OK) {+ return false;+ }+ for (int i = 0; i < row_count; i++) {+ if ((!scope->do_outbound || match->unresolved_out) &&+ (!scope->do_inbound || match->unresolved_in)) {+ break;+ }+ trace_coverage_match_row(match, &rows[i], scope);+ }+ cbm_store_free_coverage(rows, row_count);+ return true;+}++static bool trace_coverage_meta_available(cbm_store_t *store, const char *project) {+ cbm_coverage_meta_t meta = {0};+ int rc = cbm_store_coverage_meta_get(store, project, &meta);+ bool available = rc == CBM_STORE_OK &&+ meta.coverage_version >= CBM_UNRESOLVED_CALL_COVERAGE_VERSION &&+ meta.recording_status && strcmp(meta.recording_status, "unavailable") != 0;+ cbm_store_coverage_meta_clear(&meta);+ return available;+}++static void trace_call_coverage(cbm_store_t *store, const char *project,+ const trace_coverage_scope_t *scope, bool includes_calls,+ bool *unresolved_out, bool *unresolved_in) {+ if (!includes_calls) {+ return;+ }+ trace_coverage_match_t match = {.callers = scope->do_outbound ? cbm_ht_create(0) : NULL,+ .targets = scope->do_inbound ? cbm_ht_create(0) : NULL};+ bool ok = trace_coverage_meta_available(store, project) &&+ (!scope->do_outbound || match.callers) && (!scope->do_inbound || match.targets) &&+ trace_coverage_build_sets(&match, scope) &&+ trace_coverage_scan_rows(store, project, &match, scope);+ *unresolved_out = ok ? match.unresolved_out : scope->do_outbound;+ *unresolved_in = ok ? match.unresolved_in : scope->do_inbound;+ cbm_ht_free(match.callers);+ cbm_ht_free(match.targets);+}+static char *handle_trace_call_path(cbm_mcp_server_t *srv, const char *args) {char *func_name = cbm_mcp_get_string_arg(args, "function_name");char *project = get_project_arg(args);@@ -9381,90 +9522,15 @@ static char *handle_trace_call_path(cbm_mcp_server_t *srv, const char *args) {}bool unresolved_out = false;bool unresolved_in = false;- if (trace_includes_calls) {- cbm_coverage_meta_t coverage_meta = {0};- int meta_rc = cbm_store_coverage_meta_get(store, project, &coverage_meta);- if (meta_rc == CBM_STORE_OK) {- if (coverage_meta.coverage_version < CBM_UNRESOLVED_CALL_COVERAGE_VERSION ||- !coverage_meta.recording_status ||- strcmp(coverage_meta.recording_status, "unavailable") == 0) {- unresolved_out = do_outbound;- unresolved_in = do_inbound;- }- } else {- unresolved_out = do_outbound;- unresolved_in = do_inbound;- }- cbm_store_coverage_meta_clear(&coverage_meta);- if ((do_outbound && !unresolved_out) || (do_inbound && !unresolved_in)) {- CBMHashTable *callers = do_outbound ? cbm_ht_create(0) : NULL;- CBMHashTable *leaves = do_inbound ? cbm_ht_create(0) : NULL;- if ((do_outbound && !callers) || (do_inbound && !leaves)) {- unresolved_out = do_outbound;- unresolved_in = do_inbound;- } else {- bool key_set_failed = false;- for (int i = 0; i < node_count; i++) {- if (callers && nodes[i].qualified_name) {- cbm_ht_set(callers, nodes[i].qualified_name, (void *)1);- key_set_failed |= !cbm_ht_has(callers, nodes[i].qualified_name);- }- if (leaves && nodes[i].name) {- cbm_ht_set(leaves, nodes[i].name, (void *)1);- key_set_failed |= !cbm_ht_has(leaves, nodes[i].name);- }- }- for (int i = 0; callers && i < tr_out.visited_count; i++) {- const cbm_node_t *node = &tr_out.visited[i].node;- if ((include_tests || !is_test_file(node->file_path)) && node->qualified_name) {- cbm_ht_set(callers, node->qualified_name, (void *)1);- key_set_failed |= !cbm_ht_has(callers, node->qualified_name);- }- }- for (int i = 0; leaves && i < tr_in.visited_count; i++) {- const cbm_node_t *node = &tr_in.visited[i].node;- if ((include_tests || !is_test_file(node->file_path)) && node->name) {- cbm_ht_set(leaves, node->name, (void *)1);- key_set_failed |= !cbm_ht_has(leaves, node->name);- }- }- cbm_coverage_row_t *rows = NULL;- int row_count = 0;- if (key_set_failed || cbm_store_coverage_get_unresolved_calls(- store, project, &rows, &row_count) != CBM_STORE_OK) {- unresolved_out = do_outbound;- unresolved_in = do_inbound;- } else {- for (int i = 0; i < row_count && ((!unresolved_out && do_outbound) ||- (!unresolved_in && do_inbound));- i++) {- yyjson_doc *detail = yyjson_read(rows[i].detail, strlen(rows[i].detail), 0);- yyjson_val *sites = detail ? yyjson_doc_get_root(detail) : NULL;- if (!yyjson_is_arr(sites)) {- unresolved_out = do_outbound;- unresolved_in = do_inbound;- } else {- size_t idx, max;- yyjson_val *site;- yyjson_arr_foreach(sites, idx, max, site) {- const char *caller = yyjson_get_str(yyjson_obj_get(site, "caller"));- const char *leaf = yyjson_get_str(yyjson_obj_get(site, "leaf"));- if (callers && caller && cbm_ht_has(callers, caller))- unresolved_out = true;- if (leaves && leaf && cbm_ht_has(leaves, leaf))- unresolved_in = true;- }- }- if (detail)- yyjson_doc_free(detail);- }- }- cbm_store_free_coverage(rows, row_count);- }- cbm_ht_free(callers);- cbm_ht_free(leaves);- }- }+ trace_coverage_scope_t coverage_scope = {.roots = nodes,+ .root_count = node_count,+ .outbound = &tr_out,+ .inbound = &tr_in,+ .include_tests = include_tests,+ .do_outbound = do_outbound,+ .do_inbound = do_inbound};+ trace_call_coverage(store, project, &coverage_scope, trace_includes_calls, &unresolved_out,+ &unresolved_in);const char *out_relation = unresolved_out ? "unknown" : (tr_out.truncated ? "gte" : "eq");const char *in_relation = unresolved_in ? "unknown" : (tr_in.truncated ? "gte" : "eq");@@ -10215,11 +10281,12 @@ static bool is_parse_unusable(const cbm_file_error_t *e) {return e->phase && strcmp(e->phase, "parse_unusable") == 0;}-/* Either coverage phase. Both mean the file WAS indexed, so both must stay out+/* All coverage phases mean the file WAS indexed, so they must stay out* of skipped[] — a reader who sees a file there believes it is absent from the* graph entirely. */-static bool is_parse_coverage(const cbm_file_error_t *e) {- return is_parse_partial(e) || is_parse_unusable(e);+static bool is_indexed_coverage(const cbm_file_error_t *e) {+ return is_parse_partial(e) || is_parse_unusable(e) ||+ (e->phase && strcmp(e->phase, "unresolved_calls") == 0);}/* Attach a summary of per-file skips (Stage 2 / Track B). Always emits a@@ -10229,17 +10296,20 @@ static bool is_parse_coverage(const cbm_file_error_t *e) {* and, if a per-run logfile was written, "logfile": "<path>".* The run status stays "indexed" — a skipped file is the expected handled* outcome, not a failure. errs[] is borrowed (copied into doc) and may contain- * parse_partial and parse_unusable entries, which are filtered out here (both- * reported separately by add_parse_partial_summary). */+ * parse_partial, parse_unusable, and unresolved_calls entries. These describe+ * indexed files and are counted separately from skips. */static void add_skipped_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,const cbm_file_error_t *errs, int count, const char *logfile) {int skips = 0;+ int unresolved = 0;for (int i = 0; i < count; i++) {- if (!is_parse_coverage(&errs[i])) {+ unresolved += errs[i].phase && strcmp(errs[i].phase, "unresolved_calls") == 0;+ if (!is_indexed_coverage(&errs[i])) {skips++;}}yyjson_mut_obj_add_int(doc, root, "skipped_count", skips);+ yyjson_mut_obj_add_int(doc, root, "unresolved_calls_count", unresolved);if (logfile && logfile[0]) {yyjson_mut_obj_add_strcpy(doc, root, "logfile", logfile);}@@ -10250,7 +10320,7 @@ static void add_skipped_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,yyjson_mut_val *files = yyjson_mut_arr(doc);int shown = 0;for (int i = 0; i < count && shown < INDEX_SKIPPED_FILE_CAP; i++) {- if (is_parse_coverage(&errs[i])) {+ if (is_indexed_coverage(&errs[i])) {continue;}yyjson_mut_val *fe = yyjson_mut_obj(doc);diff --git a/src/pipeline/pass_calls.c b/src/pipeline/pass_calls.cindex 84958954c..e8257f880 100644--- a/src/pipeline/pass_calls.c+++ b/src/pipeline/pass_calls.c@@ -205,7 +205,7 @@ static void free_import_map(const char **keys, const char **vals, int count) {}/* Handle a route registration call: create Route node + HANDLES edge. */-static void handle_route_registration(cbm_pipeline_ctx_t *ctx, const CBMCall *call,+static void handle_route_registration(cbm_pipeline_ctx_t *ctx, CBMCall *call,const cbm_gbuf_node_t *source_node, const char *module_qn,const char **imp_keys, const char **imp_vals, int imp_count) {const char *method = cbm_service_pattern_route_method(call->callee_name);@@ -225,7 +225,9 @@ static void handle_route_registration(cbm_pipeline_ctx_t *ctx, const CBMCall *casnprintf(props, sizeof(props),"{\"callee\":\"%s\",\"url_path\":\"%s\",\"via\":\"route_registration\"}", esc_cn,esc_fa);- cbm_gbuf_insert_edge(ctx->gbuf, source_node->id, route_id, "CALLS", props);+ if (cbm_gbuf_insert_edge(ctx->gbuf, source_node->id, route_id, "CALLS", props) > 0) {+ call->coverage_calls_emitted = true;+ }if (call->second_arg_name != NULL && call->second_arg_name[0] != '\0') {cbm_resolution_t hres = cbm_registry_resolve(ctx->registry, call->second_arg_name,module_qn, imp_keys, imp_vals, imp_count);@@ -284,7 +286,7 @@ static int64_t create_svc_route_node(cbm_pipeline_ctx_t *ctx, const char *url, c* this, so data_flow mode had no argument expressions to surface for small* (< 50 file) repos that take the sequential path (#514). Mirrors the parallel* path's append_args_json shape so both pipelines agree. */-static void calls_append_args(char *props, size_t cap, const CBMCall *call) {+static void calls_append_args(char *props, size_t cap, CBMCall *call) {if (!call || call->arg_count <= 0) {return;}@@ -331,7 +333,7 @@ static void calls_append_args(char *props, size_t cap, const CBMCall *call) {}static void calls_emit_edge(cbm_gbuf_t *gbuf, int64_t src, int64_t tgt, const char *type,- char *props, size_t cap, const CBMCall *call) {+ char *props, size_t cap, CBMCall *call) {if (call && call->start_line > 0 && strcmp(type, "CALLS") == 0) {size_t len = strlen(props);if (len >= SKIP_ONE && props[len - SKIP_ONE] == '}' && len + CBM_SZ_32 < cap) {@@ -342,10 +344,13 @@ static void calls_emit_edge(cbm_gbuf_t *gbuf, int64_t src, int64_t tgt, const chif (call && strcmp(type, "CALLS") == 0) {calls_append_args(props, cap, call);}- cbm_gbuf_insert_edge(gbuf, src, tgt, type, props);+ if (cbm_gbuf_insert_edge(gbuf, src, tgt, type, props) > 0 && call &&+ strcmp(type, "CALLS") == 0) {+ call->coverage_calls_emitted = true;+ }}-static void emit_http_async_edge(cbm_pipeline_ctx_t *ctx, const CBMCall *call,+static void emit_http_async_edge(cbm_pipeline_ctx_t *ctx, CBMCall *call,const cbm_gbuf_node_t *source, const cbm_gbuf_node_t *target,const cbm_resolution_t *res, cbm_svc_kind_t svc,bool suppress_plain_calls) {@@ -414,7 +419,7 @@ static void emit_http_async_edge(cbm_pipeline_ctx_t *ctx, const CBMCall *call,* match, #592/#606), the route/HTTP/ASYNC/CONFIG service classifications below* still run — only the plain CALLS fall-through is skipped, so a fabricated* project edge is dropped while every service edge stays main-identical. */-static void emit_classified_edge(cbm_pipeline_ctx_t *ctx, const CBMCall *call,+static void emit_classified_edge(cbm_pipeline_ctx_t *ctx, CBMCall *call,const cbm_gbuf_node_t *source, const cbm_gbuf_node_t *target,const cbm_resolution_t *res, const char *module_qn,const char **imp_keys, const char **imp_vals, int imp_count,@@ -504,7 +509,8 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,res.qualified_name = target_node->qualified_name;res.confidence = lsp->confidence;res.strategy = lsp->strategy;- res.candidate_count = 1;+ res.candidate_count = CBM_ALLOC_ONE;+ call->coverage_candidate_qn = target_node->qualified_name;emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys,imp_vals, imp_count, false);return SKIP_ONE;@@ -682,6 +688,7 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,if (cbm_suppress_cross_language_suffix_match(lang, target_node->file_path, res.strategy)) {return 0;}+ call->coverage_candidate_qn = target_node->qualified_name;emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys, imp_vals,imp_count, drop_plain_call);return SKIP_ONE;diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.cindex e85ad015f..e081c3c3a 100644--- a/src/pipeline/pass_parallel.c+++ b/src/pipeline/pass_parallel.c@@ -1916,7 +1916,7 @@ static int format_call_arg(char *buf, size_t bufsize, const CBMCallArg *a, constreturn snprintf(buf, bufsize, "{\"i\":%d,\"e\":\"%s\"}", a->index, esc_e);}-static size_t append_args_json(char *buf, size_t bufsize, size_t pos, const CBMCall *call) {+static size_t append_args_json(char *buf, size_t bufsize, size_t pos, CBMCall *call) {if (call->arg_count == 0 || pos >= bufsize - PP_ARGS_MARGIN) {return pos;}@@ -1972,7 +1972,7 @@ static bool is_route_path_shaped(const char *val) {return val && val[0] == '/' && !cbm_service_pattern_is_comment_text(val);}-static const char *find_route_path_in_args(const CBMCall *call, const char **out_handler) {+static const char *find_route_path_in_args(CBMCall *call, const char **out_handler) {*out_handler = NULL;/* 1. First string arg starting with / */if (is_route_path_shaped(call->first_string_arg)) {@@ -2012,7 +2012,7 @@ static const char *find_route_path_in_args(const CBMCall *call, const char **out/* Build props JSON, append args, close brace, emit edge. */static void finalize_and_emit(cbm_gbuf_t *gbuf, int64_t src_id, int64_t tgt_id,- const char *edge_type, char *props, int n, const CBMCall *call) {+ const char *edge_type, char *props, int n, CBMCall *call) {if (n > 0 && (size_t)n < CBM_SZ_2K - PP_ESC_SPACE) {size_t pos = append_args_json(props, CBM_SZ_2K, (size_t)n, call);if (call->start_line > 0 && strcmp(edge_type, "CALLS") == 0 &&@@ -2027,7 +2027,10 @@ static void finalize_and_emit(cbm_gbuf_t *gbuf, int64_t src_id, int64_t tgt_id,props[pos + SKIP_ONE] = '\0';}}- cbm_gbuf_insert_edge(gbuf, src_id, tgt_id, edge_type, props);+ if (cbm_gbuf_insert_edge(gbuf, src_id, tgt_id, edge_type, props) > 0 &&+ strcmp(edge_type, "CALLS") == 0) {+ call->coverage_calls_emitted = true;+ }}/* Build Route node QN and properties for HTTP/async service edges. */@@ -2057,7 +2060,7 @@ static int64_t build_service_route(cbm_gbuf_t *gbuf, const char *arg, const char/* Emit HTTP_CALLS or ASYNC_CALLS edge via Route node. */static void emit_http_async_service_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,- const CBMCall *call, const cbm_resolution_t *res,+ CBMCall *call, const cbm_resolution_t *res,cbm_svc_kind_t svc, const char *arg) {const char *edge_type = (svc == CBM_SVC_HTTP) ? "HTTP_CALLS" : "ASYNC_CALLS";const char *method =@@ -2084,7 +2087,7 @@ static void emit_http_async_service_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t/* Emit CONFIGURES edge. */static void emit_config_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,- const cbm_gbuf_node_t *target, const CBMCall *call,+ const cbm_gbuf_node_t *target, CBMCall *call,const cbm_resolution_t *res, const char *arg) {/* emit_service_edge may be reached with target==NULL on the HTTP/ASYNC* external-client bypass (#523); a CONFIGURES edge needs a real target, so@@ -2104,7 +2107,7 @@ static void emit_config_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,/* Emit normal CALLS edge. */static void emit_normal_calls_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,- const cbm_gbuf_node_t *target, const CBMCall *call,+ const cbm_gbuf_node_t *target, CBMCall *call,const cbm_resolution_t *res) {/* A CALLS edge needs a real target; the HTTP/ASYNC external-client bypass* (#523) can reach emit_service_edge with target==NULL, so guard the deref. */@@ -2123,11 +2126,11 @@ static void emit_normal_calls_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *sour/* Classify a resolved call by library identity and emit the appropriate edge. *//* Create Route node + CALLS + HANDLES edges for a route registration call. */-static void emit_route_registration(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,- const CBMCall *call, const char *route_path,- const char *handler_ref, const char *module_qn,- const cbm_registry_t *registry, const cbm_gbuf_t *main_gbuf,- const char **ik, const char **iv, int ic) {+static void emit_route_registration(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, CBMCall *call,+ const char *route_path, const char *handler_ref,+ const char *module_qn, const cbm_registry_t *registry,+ const cbm_gbuf_t *main_gbuf, const char **ik, const char **iv,+ int ic) {const char *method = cbm_service_pattern_route_method(call->callee_name);char rqn[CBM_ROUTE_QN_SIZE];char cpath[CBM_SZ_256];@@ -2144,7 +2147,9 @@ static void emit_route_registration(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *sousnprintf(props, sizeof(props),"{\"callee\":\"%s\",\"url_path\":\"%s\",\"via\":\"route_registration\"}", esc_cn,esc_rp);- cbm_gbuf_insert_edge(gbuf, source->id, rid, "CALLS", props);+ if (cbm_gbuf_insert_edge(gbuf, source->id, rid, "CALLS", props) > 0) {+ call->coverage_calls_emitted = true;+ }if (handler_ref && handler_ref[0] != '\0') {cbm_resolution_t hres = cbm_registry_resolve(registry, handler_ref, module_qn, ik, iv, ic);if (hres.qualified_name && hres.qualified_name[0] != '\0') {@@ -2212,8 +2217,7 @@ static bool normalize_url_arg(const char *url, char *norm, int norm_sz) {}/* Detect API paths in call arguments and create HTTP_CALLS edges. */-static void detect_url_in_args(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,- const CBMCall *call) {+static void detect_url_in_args(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, CBMCall *call) {for (int ai = 0; ai < call->arg_count; ai++) {const CBMCallArg *ca = &call->args[ai];/* A slash-prefixed raw expression is not a URL string. In JS/TS this@@ -2318,7 +2322,7 @@ bool extract_grpc_service_method(const char *callee, char *service, size_t srv_s}/* Emit GRPC_CALLS edge via gRPC Route node. */-static void emit_grpc_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, const CBMCall *call,+static void emit_grpc_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, CBMCall *call,const cbm_resolution_t *res) {char service[CBM_SZ_256];char method[CBM_SZ_256];@@ -2355,7 +2359,7 @@ static void emit_grpc_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, cons}/* Emit GRAPHQL_CALLS edge. Extract operation from first string arg if available. */-static void emit_graphql_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, const CBMCall *call,+static void emit_graphql_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, CBMCall *call,const cbm_resolution_t *res) {const char *op = call->first_string_arg;if (!op || !op[0]) {@@ -2392,7 +2396,7 @@ static void emit_graphql_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, c}/* Emit TRPC_CALLS edge. Extract procedure path from callee chain. */-static void emit_trpc_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, const CBMCall *call,+static void emit_trpc_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, CBMCall *call,const cbm_resolution_t *res) {/* tRPC calls: trpc.user.getById.query() → extract "user.getById" */const char *callee = call->callee_name;@@ -2435,7 +2439,7 @@ static void emit_trpc_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, cons* a verb-suffix HTTP client (api.patch('/x')), broker, or route registration* keeps its edge; only the fabricated project CALLS edge is dropped. */static void emit_service_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,- const cbm_gbuf_node_t *target, const CBMCall *call,+ const cbm_gbuf_node_t *target, CBMCall *call,const cbm_resolution_t *res, const char *module_qn,const cbm_registry_t *registry, const cbm_gbuf_t *main_gbuf,const char **imp_keys, const char **imp_vals, int imp_count,@@ -2692,7 +2696,7 @@ static bool lsp_idx_insert_leaf(CBMHashTable *index, CBMResolvedCall *candidate,return inserted;}-static const CBMResolvedCall *lsp_idx_lookup(const CBMHashTable *index, const CBMCall *call,+static const CBMResolvedCall *lsp_idx_lookup(const CBMHashTable *index, CBMCall *call,bool exact_site, bool *key_built, bool *ambiguous) {if (key_built) {*key_built = false;@@ -3049,6 +3053,7 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB}continue;}+ call->coverage_candidate_qn = target_node->qualified_name;_rc_t0 = extract_now_ns();emit_service_edge(ws->local_edge_buf, source_node, target_node, call, &res, module_qn,rc->registry, rc->main_gbuf, imp_keys, imp_vals, imp_count,@@ -3449,6 +3454,28 @@ static bool pp_has_pending_lsp_site(const CBMFileResult *result) {return false;}+static CBMFileResult *resolve_load_result(resolve_ctx_t *rc, resolve_worker_state_t *ws,+ int file_idx) {+ if (ws->loaded) {+ cbm_free_result(ws->loaded);+ ws->loaded = NULL;+ }+ CBMFileResult *result = rc->result_cache[file_idx];+ if (!result && rc->pctx && rc->pctx->spill && cbm_result_spill_has(rc->pctx->spill, file_idx)) {+ result = cbm_result_spill_load(rc->pctx->spill, file_idx);+ ws->loaded = result;+ if (!result) {+ cbm_pipeline_mark_unresolved_capture_failed(rc->pctx->pipeline);+ }+ }+ return result;+}++static void resolve_capture_coverage(const resolve_ctx_t *rc, const char *rel,+ const CBMFileResult *result) {+ cbm_pipeline_record_unresolved_calls(rc->pctx ? rc->pctx->pipeline : NULL, rel, result);+}+static void resolve_worker(int worker_id, void *ctx_ptr) {resolve_ctx_t *rc = ctx_ptr;resolve_worker_state_t *ws = &rc->workers[worker_id];@@ -3482,16 +3509,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {uint64_t _loop_t0 = extract_now_ns();- if (ws->loaded) {- cbm_free_result(ws->loaded);- ws->loaded = NULL;- }- CBMFileResult *result = rc->result_cache[file_idx];- if (!result && rc->pctx && rc->pctx->spill &&- cbm_result_spill_has(rc->pctx->spill, file_idx)) {- result = cbm_result_spill_load(rc->pctx->spill, file_idx);- ws->loaded = result;- }+ CBMFileResult *result = resolve_load_result(rc, ws, file_idx);if (!result) {atomic_fetch_add_explicit(&rc->time_ns_total_loop, extract_now_ns() - _loop_t0,memory_order_relaxed);@@ -3547,6 +3565,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {if (result->calls.count == 0 && result->usages.count == 0 && result->throws.count == 0 &&result->rw.count == 0 && result->defs.count == 0 && result->impl_traits.count == 0 &&!cross_lsp_eligible) {+ resolve_capture_coverage(rc, rel, result);continue;}@@ -3695,6 +3714,10 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {atomic_fetch_add_explicit(&rc->time_ns_semantic, extract_now_ns() - _ph_t0,memory_order_relaxed);+ /* The cross-file additions and actual emitted-site evidence live in+ * this result, including when it was loaded from the spill store. */+ resolve_capture_coverage(rc, rel, result);+cbm_registry_reach_cache_end();cbm_registry_import_map_cache_end();cbm_registry_resolve_cache_end();diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.cindex 9d12c55d9..3e6952490 100644--- a/src/pipeline/pipeline.c+++ b/src/pipeline/pipeline.c@@ -42,6 +42,7 @@ enum { CBM_DIR_PERMS = 0755, PL_RING = 4, PL_RING_MASK = 3, PL_SEQ_PASSES = 6 };#include "foundation/mem.h"#include "foundation/mem_core.h"#include "result_spill.h"+#include "cbm.h"#include "foundation/secure_random.h"#include "yyjson/yyjson.h"@@ -265,7 +266,9 @@ struct cbm_pipeline {/* Per-file unresolved invocation diagnostics, published as coverage rows. */cbm_coverage_row_t *unresolved_rows;int unresolved_count;- bool unresolved_capture_failed;+ int unresolved_capacity;+ atomic_bool unresolved_capture_failed;+ cbm_mutex_t unresolved_mutex; /* one append per file, after parallel resolution *//* Deterministic test-only seam at the final publication boundary. Kept* per pipeline so concurrent test/process activity cannot cross-trigger. */@@ -360,6 +363,8 @@ cbm_pipeline_t *cbm_pipeline_new(const char *repo_path, const char *db_path,p->committed_nodes = -1;p->committed_edges = -1;atomic_init(&p->cancelled_storage, 0);+ atomic_init(&p->unresolved_capture_failed, false);+ cbm_mutex_init(&p->unresolved_mutex);p->cancelled = &p->cancelled_storage;return p;@@ -454,63 +459,236 @@ static void unresolved_json_free(void *ctx, void *ptr) {cbm_free(CBM_MEM_CLASS_DUMP, ptr);}+enum { UNRESOLVED_KEY_OVERHEAD = 128, UNRESOLVED_INITIAL_ROWS = 64, UNRESOLVED_ROW_GROWTH = 2 };++static char *unresolved_site_key(const char *caller, const char *leaf, uint32_t start, uint32_t end,+ CBMSourceOrigin origin) {+ size_t cn = strlen(caller);+ size_t ln = strlen(leaf);+ size_t cap = cn + ln + UNRESOLVED_KEY_OVERHEAD;+ char *key = cbm_alloc(CBM_MEM_CLASS_DUMP, cap);+ if (key) {+ (void)snprintf(key, cap, "%zu:%s|%zu:%s|%u:%u:%u", cn, caller, ln, leaf, start, end,+ (unsigned)origin);+ }+ return key;+}++typedef struct {+ const CBMCall *call;+} unresolved_carrier_t;++typedef struct {+ yyjson_mut_doc *doc;+ yyjson_mut_val *sites;+ CBMHashTable *carriers;+ CBMHashTable *seen;+} unresolved_capture_t;++static void unresolved_carrier_free(const char *key, void *value, void *ctx) {+ (void)ctx;+ cbm_free(CBM_MEM_CLASS_DUMP, (void *)key);+ cbm_free(CBM_MEM_CLASS_DUMP, value);+}++static void unresolved_key_free(const char *key, void *value, void *ctx) {+ (void)value;+ (void)ctx;+ cbm_free(CBM_MEM_CLASS_DUMP, (void *)key);+}++static void unresolved_capture_free(unresolved_capture_t *capture) {+ if (capture->carriers) {+ cbm_ht_foreach(capture->carriers, unresolved_carrier_free, NULL);+ cbm_ht_free(capture->carriers);+ }+ if (capture->seen) {+ cbm_ht_foreach(capture->seen, unresolved_key_free, NULL);+ cbm_ht_free(capture->seen);+ }+ if (capture->doc) {+ yyjson_mut_doc_free(capture->doc);+ }+}++static bool unresolved_call_is_missing(const CBMResolvedCall *rc) {+ return rc->kind == CBM_RESOLVED_INVOCATION && rc->strategy &&+ strcmp(rc->strategy, "lsp_unresolved") == 0 && rc->caller_qn && rc->callee_qn;+}++static bool unresolved_has_missing_calls(const CBMFileResult *result) {+ for (int i = 0; i < result->resolved_calls.count; i++) {+ if (unresolved_call_is_missing(&result->resolved_calls.items[i])) {+ return true;+ }+ }+ return false;+}++static bool unresolved_add_carrier(CBMHashTable *carriers, const CBMCall *call) {+ if (!call->callee_name || call->site_end_byte <= call->site_start_byte) {+ return true;+ }+ char *key =+ unresolved_site_key("", cbm_lsp_bare_segment(call->callee_name), call->site_start_byte,+ call->site_end_byte, call->source_origin);+ if (!key) {+ return false;+ }+ if (cbm_ht_has(carriers, key)) {+ /* Ambiguous extractor occurrences must never erase a diagnostic. */+ unresolved_carrier_t *carrier = cbm_ht_get(carriers, key);+ carrier->call = NULL;+ cbm_free(CBM_MEM_CLASS_DUMP, key);+ return true;+ }+ unresolved_carrier_t *carrier = cbm_alloc(CBM_MEM_CLASS_DUMP, sizeof(*carrier));+ if (!carrier) {+ cbm_free(CBM_MEM_CLASS_DUMP, key);+ return false;+ }+ carrier->call = call;+ cbm_ht_set(carriers, key, carrier);+ if (!cbm_ht_has(carriers, key)) {+ cbm_free(CBM_MEM_CLASS_DUMP, key);+ cbm_free(CBM_MEM_CLASS_DUMP, carrier);+ return false;+ }+ return true;+}++static bool unresolved_build_carriers(CBMHashTable *carriers, const CBMFileResult *result) {+ /* Caller names in the TS LSP walk can denote an outer factory. The+ * extractor's exact occurrence is the authoritative enclosing function.+ * Index by span AND leaf: two receiver calls on one line remain distinct. */+ for (int i = 0; i < result->calls.count; i++) {+ if (!unresolved_add_carrier(carriers, &result->calls.items[i])) {+ return false;+ }+ }+ return true;+}++static bool unresolved_append_site(unresolved_capture_t *capture, const CBMResolvedCall *rc,+ const CBMCall *call, const char *caller, const char *leaf) {+ yyjson_mut_doc *doc = capture->doc;+ yyjson_mut_val *site = yyjson_mut_obj(doc);+ bool ok =+ site && yyjson_mut_obj_add_strcpy(doc, site, "caller", caller) &&+ yyjson_mut_obj_add_strcpy(doc, site, "leaf", leaf) &&+ yyjson_mut_obj_add_uint(doc, site, "start_byte", rc->site_start_byte) &&+ yyjson_mut_obj_add_uint(doc, site, "end_byte", rc->site_end_byte) &&+ yyjson_mut_obj_add_uint(doc, site, "source_origin", rc->source_origin) &&+ yyjson_mut_obj_add_strcpy(doc, site, "reason", rc->reason ? rc->reason : "unresolved");+ if (ok && call && call->start_line > 0) {+ ok = yyjson_mut_obj_add_int(doc, site, "line", call->start_line);+ }+ if (ok && call && call->coverage_candidate_qn) {+ ok = yyjson_mut_obj_add_strcpy(doc, site, "candidate", call->coverage_candidate_qn);+ }+ return ok && yyjson_mut_arr_add_val(capture->sites, site);+}++static bool unresolved_collect_site(unresolved_capture_t *capture, const CBMResolvedCall *rc) {+ const char *leaf = cbm_lsp_bare_segment(rc->callee_qn);+ char *lookup =+ unresolved_site_key("", leaf, rc->site_start_byte, rc->site_end_byte, rc->source_origin);+ if (!lookup) {+ return false;+ }+ const unresolved_carrier_t *carrier = cbm_ht_get(capture->carriers, lookup);+ const CBMCall *call = carrier ? carrier->call : NULL;+ cbm_free(CBM_MEM_CLASS_DUMP, lookup);+ /* This exact occurrence emitted a real CALLS edge, possibly via the+ * registry after LSP failure. Never suppress a different occurrence. */+ if (call && call->coverage_calls_emitted) {+ return true;+ }+ const char *caller = call && call->enclosing_func_qn ? call->enclosing_func_qn : rc->caller_qn;+ char *key = unresolved_site_key(caller, leaf, rc->site_start_byte, rc->site_end_byte,+ rc->source_origin);+ if (!key) {+ return false;+ }+ if (cbm_ht_has(capture->seen, key)) {+ cbm_free(CBM_MEM_CLASS_DUMP, key);+ return true;+ }+ cbm_ht_set(capture->seen, key, key);+ if (!cbm_ht_has(capture->seen, key)) {+ cbm_free(CBM_MEM_CLASS_DUMP, key);+ return false;+ }+ return unresolved_append_site(capture, rc, call, caller, leaf);+}++static bool unresolved_collect_sites(unresolved_capture_t *capture, const CBMFileResult *result) {+ for (int i = 0; i < result->resolved_calls.count; i++) {+ const CBMResolvedCall *rc = &result->resolved_calls.items[i];+ if (unresolved_call_is_missing(rc) && !unresolved_collect_site(capture, rc)) {+ return false;+ }+ }+ return true;+}++/* Caller holds unresolved_mutex. Ownership transfers only on success. */+static bool unresolved_append_row(cbm_pipeline_t *p, const char *path, const char *detail) {+ if (!detail || !path || p->unresolved_capture_failed) {+ return false;+ }+ if (p->unresolved_count == p->unresolved_capacity) {+ int capacity = p->unresolved_capacity ? p->unresolved_capacity * UNRESOLVED_ROW_GROWTH+ : UNRESOLVED_INITIAL_ROWS;+ cbm_coverage_row_t *rows =+ cbm_realloc(CBM_MEM_CLASS_DUMP, p->unresolved_rows, (size_t)capacity * sizeof(*rows));+ if (!rows) {+ return false;+ }+ p->unresolved_rows = rows;+ p->unresolved_capacity = capacity;+ }+ p->unresolved_rows[p->unresolved_count++] =+ (cbm_coverage_row_t){.rel_path = path, .kind = "unresolved_calls", .detail = detail};+ return true;+}+void cbm_pipeline_record_unresolved_calls(cbm_pipeline_t *p, const char *rel_path,const CBMFileResult *result) {- if (!p || !rel_path || !result || result->resolved_calls.count == 0 ||- p->unresolved_capture_failed) {+ if (!p || !rel_path || !result || p->unresolved_capture_failed) {return;}- yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);- if (!doc) {- p->unresolved_capture_failed = true;+ if (!unresolved_has_missing_calls(result)) {return;}- yyjson_mut_val *sites = yyjson_mut_arr(doc);- yyjson_mut_doc_set_root(doc, sites);- int count = 0;- for (int i = 0; i < result->resolved_calls.count; i++) {- const CBMResolvedCall *rc = &result->resolved_calls.items[i];- if (rc->kind != CBM_RESOLVED_INVOCATION || !rc->strategy ||- strcmp(rc->strategy, "lsp_unresolved") != 0 || !rc->caller_qn || !rc->callee_qn) {- continue;- }- const char *leaf = strrchr(rc->callee_qn, '.');- leaf = leaf ? leaf + 1 : rc->callee_qn;- yyjson_mut_val *site = yyjson_mut_obj(doc);- yyjson_mut_obj_add_strcpy(doc, site, "caller", rc->caller_qn);- yyjson_mut_obj_add_strcpy(doc, site, "leaf", leaf);- yyjson_mut_obj_add_uint(doc, site, "start_byte", rc->site_start_byte);- yyjson_mut_obj_add_uint(doc, site, "end_byte", rc->site_end_byte);- yyjson_mut_obj_add_strcpy(doc, site, "reason", rc->reason ? rc->reason : "unresolved");- yyjson_mut_arr_add_val(sites, site);- count++;- }- if (count > 0) {- yyjson_alc allocator = {.malloc = unresolved_json_alloc,- .realloc = unresolved_json_realloc,- .free = unresolved_json_free};- char *detail = yyjson_mut_write_opts(doc, 0, &allocator, NULL, NULL);+ yyjson_alc allocator = {.malloc = unresolved_json_alloc,+ .realloc = unresolved_json_realloc,+ .free = unresolved_json_free};+ unresolved_capture_t capture = {.doc = yyjson_mut_doc_new(&allocator),+ .carriers = cbm_ht_create(0),+ .seen = cbm_ht_create(0)};+ capture.sites = capture.doc ? yyjson_mut_arr(capture.doc) : NULL;+ bool ok = capture.doc && capture.carriers && capture.seen && capture.sites;+ if (capture.doc) {+ yyjson_mut_doc_set_root(capture.doc, capture.sites);+ }+ ok = ok && unresolved_build_carriers(capture.carriers, result) &&+ unresolved_collect_sites(&capture, result);+ if (ok && yyjson_mut_arr_size(capture.sites) > 0) {+ char *detail = yyjson_mut_write_opts(capture.doc, 0, &allocator, NULL, NULL);char *path = cbm_mem_strdup(CBM_MEM_CLASS_DUMP, rel_path);- if (!detail || !path) {- p->unresolved_capture_failed = true;+ cbm_mutex_lock(&p->unresolved_mutex);+ ok = unresolved_append_row(p, path, detail);+ cbm_mutex_unlock(&p->unresolved_mutex);+ if (!ok) {cbm_free(CBM_MEM_CLASS_DUMP, detail);cbm_free(CBM_MEM_CLASS_DUMP, path);- } else {- cbm_coverage_row_t *rows =- cbm_realloc(CBM_MEM_CLASS_DUMP, p->unresolved_rows,- (size_t)(p->unresolved_count + 1) * sizeof(*rows));- if (!rows) {- p->unresolved_capture_failed = true;- cbm_free(CBM_MEM_CLASS_DUMP, detail);- cbm_free(CBM_MEM_CLASS_DUMP, path);- } else {- p->unresolved_rows = rows;- p->unresolved_rows[p->unresolved_count++] = (cbm_coverage_row_t){- .rel_path = path, .kind = "unresolved_calls", .detail = detail};- }}}- yyjson_mut_doc_free(doc);+ if (!ok) {+ p->unresolved_capture_failed = true;+ }+ unresolved_capture_free(&capture);}void cbm_pipeline_mark_unresolved_capture_failed(cbm_pipeline_t *p) {@@ -563,6 +741,7 @@ void cbm_pipeline_free(cbm_pipeline_t *p) {cbm_free(CBM_MEM_CLASS_DUMP, (char *)p->unresolved_rows[i].detail);}cbm_free(CBM_MEM_CLASS_DUMP, p->unresolved_rows);+ cbm_mutex_destroy(&p->unresolved_mutex);cbm_git_context_free(&p->git_ctx);/* gbuf, store, registry freed during/after run *//* Defensively free userconfig in case run() was never called or panicked */@@ -1799,18 +1978,6 @@ static int run_parallel_pipeline(cbm_pipeline_t *p, cbm_pipeline_ctx_t *ctx,cbm_clock_gettime(CLOCK_MONOTONIC, t);rc = cbm_parallel_resolve(ctx, files, file_count, cache, &shared_ids, worker_count, all_defs,def_count, def_modules, module_def_index, &cross_registries);- if (rc == 0) {- for (int i = 0; i < file_count; i++) {- bool loaded = false;- CBMFileResult *result = cbm_pipeline_result_acquire(ctx, cache, i, NULL, &loaded);- if (result) {- cbm_pipeline_record_unresolved_calls(p, files[i].rel_path, result);- } else if (ctx->spill && cbm_result_spill_has(ctx->spill, i)) {- cbm_pipeline_mark_unresolved_capture_failed(p);- }- cbm_pipeline_result_release(result, loaded);- }- }cbm_log_info("pass.timing", "pass", "parallel_resolve", "elapsed_ms",itoa_buf((int)elapsed_ms(*t)));pipeline_phase_mark("parallel_resolve");diff --git a/src/pipeline/pipeline_incremental.c b/src/pipeline/pipeline_incremental.cindex f0953764e..9d34ff241 100644--- a/src/pipeline/pipeline_incremental.c+++ b/src/pipeline/pipeline_incremental.c@@ -1352,19 +1352,6 @@ static int run_extract_resolve(cbm_pipeline_ctx_t *ctx, cbm_file_info_t *changedrc = cbm_parallel_resolve(ctx, changed_files, ci, cache, &shared_ids, worker_count,all_defs, all_def_count, closure ? closure->def_modules : NULL,module_def_index, registries_arg);- if (rc == 0) {- for (int i = 0; i < ci; i++) {- bool loaded = false;- CBMFileResult *result = cbm_pipeline_result_acquire(ctx, cache, i, NULL, &loaded);- if (result) {- cbm_pipeline_record_unresolved_calls(ctx->pipeline, changed_files[i].rel_path,- result);- } else if (ctx->spill && cbm_result_spill_has(ctx->spill, i)) {- cbm_pipeline_mark_unresolved_capture_failed(ctx->pipeline);- }- cbm_pipeline_result_release(result, loaded);- }- }if (module_def_index) {cbm_pxc_free_module_def_index(module_def_index);}diff --git a/src/store/store.h b/src/store/store.hindex 82489255e..2163eed09 100644--- a/src/store/store.h+++ b/src/store/store.h@@ -650,9 +650,9 @@ typedef struct {const char *detail;} cbm_coverage_row_t;-/* Older generations have no unresolved-call records, so their exact trace- * totals cannot be trusted after this signal becomes part of coverage. */-enum { CBM_UNRESOLVED_CALL_COVERAGE_VERSION = 4 };+/* Older generations lack precise caller attribution and resolver candidates,+ * so their exact trace totals cannot be trusted until the project is reindexed. */+enum { CBM_UNRESOLVED_CALL_COVERAGE_VERSION = 5 };/* Metadata describing how completely one index run recorded the best-effort* coverage signal. `recording_status` is "complete", "truncated", ordiff --git a/tests/test_mcp.c b/tests/test_mcp.cindex 02cb9db01..2f8b41eb2 100644--- a/tests/test_mcp.c+++ b/tests/test_mcp.c@@ -7462,7 +7462,9 @@ TEST(tool_trace_path_marks_unresolved_call_totals_unknown) {.rel_path = "service.js",.kind = "unresolved_calls",.detail = "[{\"caller\":\"unresolved-trace.service.run\",\"leaf\":\"buscar\","- "\"start_byte\":42,\"end_byte\":59,\"reason\":\"method_not_in_registry\"}]"};+ "\"start_byte\":42,\"end_byte\":59,\"line\":3,"+ "\"candidate\":\"unresolved-trace.client.buscar\","+ "\"reason\":\"method_not_in_registry\"}]"};cbm_coverage_meta_t meta = {.generation = "fixture",.index_mode = "full",.recorded_at = "2026-09-24T00:00:00Z",@@ -7489,6 +7491,20 @@ TEST(tool_trace_path_marks_unresolved_call_totals_unknown) {ASSERT_NOT_NULL(strstr(txt, "\"callers_total_relation\":\"unknown\""));free(txt);free(out);+ /* The same leaf in an unrelated module was never a resolver candidate. */+ cbm_node_t unrelated = callee;+ unrelated.qualified_name = "unresolved-trace.other.buscar";+ unrelated.file_path = "other.js";+ ASSERT_GT(cbm_store_upsert_node(st, &unrelated), 0);+ out = cbm_mcp_server_handle(+ srv, "{\"jsonrpc\":\"2.0\",\"id\":20,\"method\":\"tools/call\","+ "\"params\":{\"name\":\"trace_path\",\"arguments\":{\"project\":"+ "\"unresolved-trace\",\"function_name\":\"unresolved-trace.other.buscar\","+ "\"direction\":\"inbound\",\"format\":\"json\"}}}");+ txt = extract_text_content(out);+ ASSERT_NOT_NULL(strstr(txt, "\"callers_total_relation\":\"eq\""));+ free(txt);+ free(out);out = cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",""\"params\":{\"name\":\"check_index_coverage\",\"arguments\":{\"project\":"@@ -7512,6 +7528,62 @@ TEST(tool_trace_path_marks_unresolved_call_totals_unknown) {PASS();}+TEST(tool_index_unresolved_nested_functions_are_indexed) {+ char tmp[256] = "/tmp/cbm-mcp-unresolved-XXXXXX";+ char cache[256] = "/tmp/cbm-mcp-unresolved-cache-XXXXXX";+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));+ ASSERT_NOT_NULL(cbm_mkdtemp(cache));+ const char *saved = getenv("CBM_CACHE_DIR");+ char *saved_copy = saved ? strdup(saved) : NULL;+ cbm_setenv("CBM_CACHE_DIR", cache, 1);+ char path[512];+ snprintf(path, sizeof(path), "%s/service.js", tmp);+ FILE *f = fopen(path, "w");+ ASSERT_NOT_NULL(f);+ fputs("export function factory({ client }) {\n"+ " function inner(id) {\n"+ " return client.buscar(id);\n"+ " }\n return { inner };\n}\n",+ f);+ fclose(f);+ cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);+ ASSERT_NOT_NULL(srv);+ char args[1024];+ snprintf(args, sizeof(args), "{\"repo_path\":\"%s\",\"mode\":\"full\"}", tmp);+ char *out = cbm_mcp_handle_tool(srv, "index_repository", args);+ ASSERT_NOT_NULL(out);+ ASSERT(response_contains_json_fragment(out, "\"status\":\"indexed\""));+ ASSERT(response_contains_json_fragment(out, "\"skipped_count\":0"));+ free(out);+ char *project = cbm_project_name_from_path(tmp);+ ASSERT_NOT_NULL(project);+ snprintf(args, sizeof(args),+ "{\"project\":\"%s\",\"function_name\":\"inner\","+ "\"direction\":\"outbound\",\"format\":\"json\"}",+ project);+ out = cbm_mcp_handle_tool(srv, "trace_path", args);+ ASSERT_NOT_NULL(out);+ ASSERT(response_contains_json_fragment(out, "\"callees_total_relation\":\"unknown\""));+ free(out);+ snprintf(args, sizeof(args),+ "{\"project\":\"%s\",\"function_name\":\"factory\","+ "\"direction\":\"outbound\",\"format\":\"json\"}",+ project);+ out = cbm_mcp_handle_tool(srv, "trace_path", args);+ ASSERT_NOT_NULL(out);+ ASSERT(response_contains_json_fragment(out, "\"callees_total_relation\":\"eq\""));+ free(out);+ cbm_mcp_server_free(srv);+ cleanup_project_db(cache, project);+ restore_cache_dir(saved_copy);+ free(saved_copy);+ free(project);+ remove(path);+ cbm_rmdir(tmp);+ cbm_rmdir(cache);+ PASS();+}+/* Edge-data lookup must follow the traversal direction and shortest-path hop.* The induced edge set contains a same-hop cross edge whose source is the row* node and sorts before its real inbound predecessor. An arbitrary incident-@@ -20741,6 +20813,7 @@ SUITE(mcp) {RUN_TEST(trace_evidence_strategy_class_vocabulary_is_closed);RUN_TEST(tool_trace_path_evidence_is_opt_in_and_class_mapped);RUN_TEST(tool_trace_path_marks_unresolved_call_totals_unknown);+ RUN_TEST(tool_index_unresolved_nested_functions_are_indexed);RUN_TEST(tool_trace_path_evidence_columns_match_header_issue1542);RUN_TEST(tool_trace_path_unreadable_confidence_reports_not_recorded);RUN_TEST(tool_trace_path_edge_details_use_canonical_predecessor);diff --git a/tests/test_pipeline.c b/tests/test_pipeline.cindex 9a072cd83..fd8ddd127 100644--- a/tests/test_pipeline.c+++ b/tests/test_pipeline.c@@ -765,6 +765,108 @@ TEST(pipeline_adr_survives_full_reindex) {PASS();}+static int pipeline_unresolved_review_case(int padding, bool spill) {+ char tmp[256] = "/tmp/cbm_unresolved_review_XXXXXX";+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));+ char db[512], path[512];+ const char *names[] = {"cliente.js", "servicio.js", "ayudante.js",+ "directo.js", "missing.js", "route.js"};+ const char *sources[] = {+ "export function crearCliente() { function buscar(id) { return id; } return { buscar }; "+ "}\n",+ "export function crearServicio({ cliente }) {\n"+ " function procesar(id) {\n"+ " cliente.buscar(id); return cliente.buscar(id + 1);\n"+ " }\n return { procesar };\n}\n",+ "export function ayudante(id) { return id; }\n",+ "import { ayudante } from './ayudante.js';\n"+ "export function usarDirecto(id) { ayudante(id); return ayudante(id + 1); }\n",+ "import { absent } from './ayudante.js';\n"+ "export function missing(id) { return absent(id); }\n",+ "export function setup({ app }) { app.get('/x', handler); }\n"+ "function handler() { return 1; }\n"};+ for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); i++) {+ snprintf(path, sizeof(path), "%s/%s", tmp, names[i]);+ FILE *f = fopen(path, "w");+ ASSERT_NOT_NULL(f);+ fputs(sources[i], f);+ fclose(f);+ }+ for (int i = 0; i < padding; i++) {+ snprintf(path, sizeof(path), "%s/pad%d.js", tmp, i);+ FILE *f = fopen(path, "w");+ ASSERT_NOT_NULL(f);+ fprintf(f, "export function pad%d() { return %d; }\n", i, i);+ fclose(f);+ }+ snprintf(db, sizeof(db), "%s/index.db", tmp);+ if (spill)+ cbm_setenv("CBM_MEM_SPILL", "1", 1);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ int rc = cbm_pipeline_run(p);+ if (spill)+ cbm_unsetenv("CBM_MEM_SPILL");+ ASSERT_EQ(rc, 0);+ char project[256];+ snprintf(project, sizeof(project), "%s", cbm_pipeline_project_name(p));+ cbm_pipeline_free(p);+ cbm_store_t *st = cbm_store_open_path(db);+ ASSERT_NOT_NULL(st);+ cbm_coverage_row_t *rows = NULL;+ int count = 0;+ ASSERT_EQ(cbm_store_coverage_get_path(st, project, "directo.js", &rows, &count), CBM_STORE_OK);+ for (int i = 0; i < count; i++)+ ASSERT_FALSE(strcmp(rows[i].kind, "unresolved_calls") == 0);+ cbm_store_free_coverage(rows, count);+ rows = NULL;+ count = 0;+ ASSERT_EQ(cbm_store_coverage_get_path(st, project, "route.js", &rows, &count), CBM_STORE_OK);+ for (int i = 0; i < count; i++)+ ASSERT_FALSE(strcmp(rows[i].kind, "unresolved_calls") == 0);+ cbm_store_free_coverage(rows, count);+ rows = NULL;+ count = 0;+ ASSERT_EQ(cbm_store_coverage_get_path(st, project, "servicio.js", &rows, &count), CBM_STORE_OK);+ ASSERT_EQ(count, 1);+ yyjson_doc *doc = yyjson_read(rows[0].detail, strlen(rows[0].detail), 0);+ ASSERT_NOT_NULL(doc);+ yyjson_val *sites = yyjson_doc_get_root(doc);+ ASSERT_EQ(yyjson_arr_size(sites), 2);+ for (size_t i = 0; i < 2; i++) {+ yyjson_val *site = yyjson_arr_get(sites, i);+ const char *caller = yyjson_get_str(yyjson_obj_get(site, "caller"));+ ASSERT_NOT_NULL(caller);+ ASSERT_NOT_NULL(strstr(caller, ".procesar"));+ ASSERT_EQ(yyjson_get_int(yyjson_obj_get(site, "line")), 3);+ ASSERT_NOT_NULL(yyjson_get_str(yyjson_obj_get(site, "candidate")));+ }+ yyjson_doc_free(doc);+ cbm_store_free_coverage(rows, count);+ rows = NULL;+ count = 0;+ ASSERT_EQ(cbm_store_coverage_get_path(st, project, "missing.js", &rows, &count), CBM_STORE_OK);+ ASSERT_EQ(count, 1);+ doc = yyjson_read(rows[0].detail, strlen(rows[0].detail), 0);+ ASSERT_NOT_NULL(doc);+ ASSERT_EQ(yyjson_arr_size(yyjson_doc_get_root(doc)), 1);+ yyjson_doc_free(doc);+ cbm_store_free_coverage(rows, count);+ cbm_store_close(st);+ rm_rf(tmp);+ PASS();+}++TEST(pipeline_unresolved_review_sequential) {+ return pipeline_unresolved_review_case(0, false);+}+TEST(pipeline_unresolved_review_parallel) {+ return pipeline_unresolved_review_case(55, false);+}+TEST(pipeline_unresolved_review_spill) {+ return pipeline_unresolved_review_case(55, true);+}+TEST(pipeline_records_unresolved_injected_call_sites) {char tmp[256] = "/tmp/cbm_unresolved_calls_XXXXXX";ASSERT_NOT_NULL(cbm_mkdtemp(tmp));@@ -15939,6 +16041,9 @@ SUITE(pipeline) {RUN_TEST(pipeline_adr_survives_full_reindex);RUN_TEST(pipeline_export_error_snapshot_on_artifact_failure);RUN_TEST(pipeline_records_unresolved_injected_call_sites);+ RUN_TEST(pipeline_unresolved_review_sequential);+ RUN_TEST(pipeline_unresolved_review_parallel);+ RUN_TEST(pipeline_unresolved_review_spill);RUN_TEST(pipeline_structure_edges);RUN_TEST(pipeline_branch_root_structure);RUN_TEST(pipeline_project_name_derived);