Skip to content

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.

fix(pipeline): one Interface edge split in both venues, explicit overrides

Martin Vogel4a3aac647817
diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c
index 68b66545c..21b9561b3 100644
--- a/src/pipeline/pass_parallel.c
+++ b/src/pipeline/pass_parallel.c
@@ -2539,7 +2539,11 @@ static void resolve_def_inherits(resolve_ctx_t *rc, resolve_worker_state_t *ws,
}
const cbm_gbuf_node_t *bn = cbm_gbuf_find_by_qn(rc->main_gbuf, bqn);
if (bn && node->id != bn->id) {
- cbm_gbuf_insert_edge(ws->local_edge_buf, node->id, bn->id, "INHERITS", "{}");
+ /* Same Interface-label split as the sequential semantic pass —
+ * hardcoding INHERITS here demoted every explicit `implements`
+ * on large (parallel-path) corpora. */
+ cbm_gbuf_insert_edge(ws->local_edge_buf, node->id, bn->id,
+ cbm_semantic_base_edge_type(bn), "{}");
ws->semantic_resolved++;
}
}
@@ -3010,6 +3014,10 @@ int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
/* Go-style implicit interface satisfaction (needs full graph, serial) */
int go_impl = cbm_pipeline_implements_go(ctx);
+ /* Explicit-language override detection (same serial full-graph tail the
+ * sequential pipeline runs — the two venues must emit identical graphs). */
+ total_lsp_overrides += cbm_pipeline_override_explicit(ctx);
+
if (atomic_load(ctx->cancelled)) {
return CBM_NOT_FOUND;
}
diff --git a/src/pipeline/pass_semantic.c b/src/pipeline/pass_semantic.c
index 8a3bb01f0..c77917117 100644
--- a/src/pipeline/pass_semantic.c
+++ b/src/pipeline/pass_semantic.c
@@ -454,12 +454,13 @@ static void sem_process_def_edges(cbm_pipeline_ctx_t *ctx, const CBMDefinition *
if (base_node && node->id != base_node->id) {
/* A base that resolves to an Interface is an IMPLEMENTS relation
* (Java `implements`, C# `: IFace`, TS `implements`); a Class/
- * Type/Enum base is plain INHERITS. */
- const char *base_label = cbm_registry_label_of(ctx->registry, base_qn);
- const char *edge_type = (base_label && strcmp(base_label, "Interface") == 0)
- ? "IMPLEMENTS"
- : "INHERITS";
- cbm_gbuf_insert_edge(ctx->gbuf, node->id, base_node->id, edge_type, "{}");
+ * Type/Enum base is plain INHERITS. Keyed off the target NODE's
+ * label — the graph truth the edge attaches to — so the
+ * sequential and parallel venues cannot diverge (the parallel
+ * path once hardcoded INHERITS and demoted every explicit
+ * implements at scale). */
+ cbm_gbuf_insert_edge(ctx->gbuf, node->id, base_node->id,
+ cbm_semantic_base_edge_type(base_node), "{}");
(*inherits_count)++;
}
}
@@ -576,8 +577,77 @@ int cbm_pipeline_pass_semantic(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *f
int go_impl = cbm_pipeline_implements_go(ctx);
implements_count += go_impl;
+ /* ── Explicit-language override detection (full graph, serial) ── */
+ int overrides = cbm_pipeline_override_explicit(ctx);
+
cbm_log_info("pass.done", "pass", "semantic", "inherits", itoa_log(inherits_count), "decorates",
- itoa_log(decorates_count), "implements", itoa_log(implements_count), "errors",
- itoa_log(errors));
+ itoa_log(decorates_count), "implements", itoa_log(implements_count), "overrides",
+ itoa_log(overrides), "errors", itoa_log(errors));
return 0;
}
+
+const char *cbm_semantic_base_edge_type(const cbm_gbuf_node_t *base_node) {
+ return (base_node && base_node->label && strcmp(base_node->label, "Interface") == 0)
+ ? "IMPLEMENTS"
+ : "INHERITS";
+}
+
+/* Create OVERRIDE edges from one class's methods to same-named methods of one
+ * explicit base (interface or superclass). */
+static int override_match_methods(cbm_pipeline_ctx_t *ctx, const cbm_gbuf_node_t *cls,
+ const cbm_gbuf_node_t *base) {
+ const cbm_gbuf_edge_t **cls_dm = NULL;
+ int cls_dm_count = 0;
+ cbm_gbuf_find_edges_by_source_type(ctx->gbuf, cls->id, "DEFINES_METHOD", &cls_dm,
+ &cls_dm_count);
+ if (cls_dm_count == 0) {
+ return 0;
+ }
+ const cbm_gbuf_edge_t **base_dm = NULL;
+ int base_dm_count = 0;
+ cbm_gbuf_find_edges_by_source_type(ctx->gbuf, base->id, "DEFINES_METHOD", &base_dm,
+ &base_dm_count);
+ int created = 0;
+ for (int c = 0; c < cls_dm_count; c++) {
+ const cbm_gbuf_node_t *cm = cbm_gbuf_find_by_id(ctx->gbuf, cls_dm[c]->target_id);
+ if (!cm || !cm->name) {
+ continue;
+ }
+ for (int b = 0; b < base_dm_count; b++) {
+ const cbm_gbuf_node_t *bm = cbm_gbuf_find_by_id(ctx->gbuf, base_dm[b]->target_id);
+ if (bm && bm->name && cm->id != bm->id && strcmp(cm->name, bm->name) == 0) {
+ cbm_gbuf_insert_edge(ctx->gbuf, cm->id, bm->id, "OVERRIDE", "{}");
+ created++;
+ break;
+ }
+ }
+ }
+ return created;
+}
+
+int cbm_pipeline_override_explicit(cbm_pipeline_ctx_t *ctx) {
+ if (!ctx || !ctx->gbuf) {
+ return 0;
+ }
+ int created = 0;
+ static const char *base_edge_types[] = {"IMPLEMENTS", "INHERITS"};
+ for (size_t t = 0; t < sizeof(base_edge_types) / sizeof(base_edge_types[0]); t++) {
+ const cbm_gbuf_edge_t **edges = NULL;
+ int edge_count = 0;
+ cbm_gbuf_find_edges_by_type(ctx->gbuf, base_edge_types[t], &edges, &edge_count);
+ for (int e = 0; e < edge_count; e++) {
+ const cbm_gbuf_node_t *cls = cbm_gbuf_find_by_id(ctx->gbuf, edges[e]->source_id);
+ const cbm_gbuf_node_t *base = cbm_gbuf_find_by_id(ctx->gbuf, edges[e]->target_id);
+ if (!cls || !base) {
+ continue;
+ }
+ /* Go's implicit satisfaction already emits OVERRIDE with interface
+ * semantics; running both would double-cover .go sources. */
+ if (cls->file_path && fp_ends_with(cls->file_path, ".go")) {
+ continue;
+ }
+ created += override_match_methods(ctx, cls, base);
+ }
+ }
+ return created;
+}
diff --git a/src/pipeline/pipeline_internal.h b/src/pipeline/pipeline_internal.h
index e6c211f44..9886d5718 100644
--- a/src/pipeline/pipeline_internal.h
+++ b/src/pipeline/pipeline_internal.h
@@ -259,6 +259,20 @@ int cbm_compute_change_coupling(const cbm_commit_files_t *commits, int commit_co
* creates IMPLEMENTS + OVERRIDE edges. Returns edge count created. */
int cbm_pipeline_implements_go(cbm_pipeline_ctx_t *ctx);
+/* Edge type for an explicit base-class relation, keyed off the resolved
+ * TARGET node's label: Interface → IMPLEMENTS, anything else → INHERITS.
+ * The single decision point for BOTH the sequential semantic pass and the
+ * parallel per-file resolve — the two venues must never diverge. */
+const char *cbm_semantic_base_edge_type(const cbm_gbuf_node_t *base_node);
+
+/* Explicit-language override detection on the full graph (serial tail).
+ * For every IMPLEMENTS/INHERITS edge whose source is a non-Go class, matches
+ * the class's DEFINES_METHOD children by name against the base's and creates
+ * Method→Method OVERRIDE edges (Java @Override, TS/C#/Kotlin override, PHP
+ * redefinition). Go is excluded: implicit satisfaction already covers it.
+ * Returns edge count created. */
+int cbm_pipeline_override_explicit(cbm_pipeline_ctx_t *ctx);
+
/* ── Git diff helpers (pass_gitdiff.c) ───────────────────────────── */
typedef struct {
diff --git a/tests/test_parallel.c b/tests/test_parallel.c
index 9706db2b7..e55f6e46d 100644
--- a/tests/test_parallel.c
+++ b/tests/test_parallel.c
@@ -70,6 +70,35 @@ static int setup_parallel_repo(void) {
fprintf(f, "package util\n\nfunc Help() {}\n");
fclose(f);
+ /* Java interface/implements/extends trio: the parallel resolve path must
+ * make the same Interface-label edge split (IMPLEMENTS vs INHERITS) as
+ * the sequential semantic pass, and both must emit OVERRIDE for methods
+ * redefined from an explicit base. Without these files the IMPLEMENTS/
+ * INHERITS parity tests compare 0 == 0 and guard nothing (the demotion
+ * bug shipped: elasticsearch had 11k implements-as-INHERITS edges). */
+ snprintf(path, sizeof(path), "%s/probe", g_par_tmpdir);
+ cbm_mkdir(path);
+ snprintf(path, sizeof(path), "%s/probe/Shape.java", g_par_tmpdir);
+ f = fopen(path, "w");
+ if (!f)
+ return -1;
+ fprintf(f, "package probe;\npublic interface Shape {\n double area();\n}\n");
+ fclose(f);
+ snprintf(path, sizeof(path), "%s/probe/Circle.java", g_par_tmpdir);
+ f = fopen(path, "w");
+ if (!f)
+ return -1;
+ fprintf(f, "package probe;\npublic class Circle implements Shape {\n"
+ " @Override\n public double area() { return 1.0; }\n}\n");
+ fclose(f);
+ snprintf(path, sizeof(path), "%s/probe/Base.java", g_par_tmpdir);
+ f = fopen(path, "w");
+ if (!f)
+ return -1;
+ fprintf(f, "package probe;\npublic class Base extends Circle {\n"
+ " @Override\n public double area() { return 0.0; }\n}\n");
+ fclose(f);
+
return 0;
}
@@ -316,6 +345,22 @@ TEST(parallel_implements_parity) {
PASS();
}
+/* Absolute counts on the fixture — parity alone passes vacuously at 0==0,
+ * which is how the parallel-path IMPLEMENTS demotion shipped unnoticed. */
+TEST(parallel_semantic_fixture_expected_counts) {
+ if (ensure_parity_setup() != 0)
+ FAIL("setup failed");
+ /* Circle implements Shape; Base extends Circle — in BOTH venues. */
+ ASSERT_EQ(cbm_gbuf_edge_count_by_type(g_seq_gbuf, "IMPLEMENTS"), 1);
+ ASSERT_EQ(cbm_gbuf_edge_count_by_type(g_par_gbuf, "IMPLEMENTS"), 1);
+ ASSERT_EQ(cbm_gbuf_edge_count_by_type(g_seq_gbuf, "INHERITS"), 1);
+ ASSERT_EQ(cbm_gbuf_edge_count_by_type(g_par_gbuf, "INHERITS"), 1);
+ /* Circle.area overrides Shape.area; Base.area overrides Circle.area. */
+ ASSERT_EQ(cbm_gbuf_edge_count_by_type(g_seq_gbuf, "OVERRIDE"), 2);
+ ASSERT_EQ(cbm_gbuf_edge_count_by_type(g_par_gbuf, "OVERRIDE"), 2);
+ PASS();
+}
+
TEST(parallel_total_edges) {
if (ensure_parity_setup() != 0)
FAIL("setup failed");
@@ -1173,6 +1218,7 @@ SUITE(parallel) {
RUN_TEST(parallel_usage_parity);
RUN_TEST(parallel_inherits_parity);
RUN_TEST(parallel_implements_parity);
+ RUN_TEST(parallel_semantic_fixture_expected_counts);
RUN_TEST(parallel_total_edges);
RUN_TEST(parallel_empty_files);
RUN_TEST(parallel_args_json_no_overflow);