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): bound the overview entries so Django-sized graphs render
Bernhard Jackiewicz41f73838c75b
diff --git a/src/store/architecture_projection.c b/src/store/architecture_projection.cindex 6c8751749..b2df238ba 100644--- a/src/store/architecture_projection.c+++ b/src/store/architecture_projection.c@@ -19,7 +19,12 @@ enum {AP_ARGUMENT_LIMIT = 8,AP_SIGNATURE_BYTES = 4096,AP_VALUE_BYTES = 1024,- AP_PARAMETER_LIMIT = 64+ AP_PARAMETER_LIMIT = 64,+ /* Overview entries carry a full representative symbol (about 1.3 KB of+ * mutable JSON each). Django 5.2.7 has 12,700 components: listing all of+ * them took half of AP_JSON_BUDGET before any other section. Keep it at+ * least the max_components ceiling (512) so displayed parts stay listed. */+ AP_OVERVIEW_COMPONENTS = 4096};enum { AP_EVIDENCE_CONTEXT, AP_EVIDENCE_CORRIDOR, AP_EVIDENCE_PATH, AP_EVIDENCE_SCOPES };@@ -68,7 +73,7 @@ static const char *const ap_types[] = {"IMPLEMENTS", "INHERITS", "CONFIGURES", "WRITES", "READS", "USAGE","PUBLISHES", "SUBSCRIBES", "DEFINES", "DEFINES_METHOD", "CONTAINS", "EMITS","LISTENS_ON", "HANDLES", "DATA_FLOWS", "INFRA_MAPS"};-enum { AP_DEFINES = 14, AP_METHOD = 15, AP_CONTAINS = 16 };+enum { AP_DEFINES = 14, AP_METHOD = 15, AP_CONTAINS = 16, AP_HANDLES = 19 };typedef struct {int64_t id;@@ -89,6 +94,7 @@ typedef struct {typedef struct {int root, members, files, atoms, representative, degree, displayed;int overview_group;+ bool listed;char *directory;int samples[AP_REPRESENTATIVES], sample_count;} ap_component;@@ -1278,7 +1284,7 @@ static int ap_overview(ap_context *c, yyjson_mut_doc *doc, yyjson_mut_val *root)yyjson_mut_obj_add_val(doc, overview, "connections", connections);yyjson_mut_obj_add_val(doc, overview, "totals", totals);yyjson_mut_obj_add_val(doc, overview, "limits", limits);- int connection_count = 0, shown = 0;+ int connection_count = 0, shown = 0, omitted_parts = 0;if (!c->limited) {for (int g = 0; g < c->group_count; g++) {ap_overview_group *group = &c->groups[g];@@ -1309,8 +1315,14 @@ static int ap_overview(ap_context *c, yyjson_mut_doc *doc, yyjson_mut_val *root)if (ap_stopped(c))return CBM_STORE_ERR;}+ /* Groups above keep every component id and count; only the detailed+ * entries are bounded, in display rank order. */for (int i = 0; i < c->component_count; i++) {ap_component *part = &c->components[i];+ if (!part->listed) {+ omitted_parts++;+ continue;+ }yyjson_mut_val *value = yyjson_mut_obj(doc), *reps = yyjson_mut_arr(doc);char id[48];ap_component_id(c, i, id);@@ -1369,12 +1381,14 @@ static int ap_overview(ap_context *c, yyjson_mut_doc *doc, yyjson_mut_val *root)}free(edges);}- yyjson_mut_obj_add_bool(doc, overview, "complete", !c->limited && shown == connection_count);+ yyjson_mut_obj_add_bool(doc, overview, "complete",+ !c->limited && shown == connection_count && !omitted_parts);yyjson_mut_obj_add_int(doc, totals, "groups", c->limited ? 0 : c->group_count);yyjson_mut_obj_add_int(doc, totals, "components", c->limited ? 0 : c->component_count);yyjson_mut_obj_add_int(doc, totals, "accounted_nodes", c->limited ? 0 : c->accounted);yyjson_mut_obj_add_int(doc, totals, "connections", connection_count);yyjson_mut_obj_add_int(doc, limits, "omitted_connections", connection_count - shown);+ yyjson_mut_obj_add_int(doc, limits, "omitted_components", omitted_parts);return CBM_STORE_OK;}@@ -1732,30 +1746,35 @@ static int ap_render(ap_context *c, const char *project, char **out_json) {bool paths_truncated = false;int rc = CBM_STORE_OK;ap_dep *deps = NULL;- if (ap_overview(c, doc, root) != CBM_STORE_OK) {- rc = CBM_STORE_ERR;- goto done;- }if (!c->limited) {/* Prefer the largest connected candidates, retaining deterministic IDs.- * Never relabel discarded components as a single invented component. */+ * Never relabel discarded components as a single invented component.+ * The same rank bounds the overview entries, which therefore always+ * include every displayed component. */ap_rank *ranks = malloc(((size_t)c->component_count + 1) * sizeof(*ranks));if (!ranks) {rc = CBM_STORE_ERR;goto done;}- for (int i = 0; i < c->component_count; i++) {- c->components[i].displayed = -1;+ for (int i = 0; i < c->component_count; i++)ranks[i] = (ap_rank){i, c->components[i].members, c->components[i].degree};- }qsort(ranks, (size_t)c->component_count, sizeof(*ranks), ap_rank_compare);- for (int pick = 0; pick < c->options.max_components && pick < c->component_count; pick++)- c->components[ranks[pick].index].displayed = shown++;+ for (int pick = 0; pick < c->component_count; pick++) {+ ap_component *part = &c->components[ranks[pick].index];+ part->displayed = pick < c->options.max_components ? shown++ : -1;+ part->listed = pick < AP_OVERVIEW_COMPONENTS;+ }free(ranks);if (ap_stopped(c)) {rc = CBM_STORE_ERR;goto done;}+ }+ if (ap_overview(c, doc, root) != CBM_STORE_OK) {+ rc = CBM_STORE_ERR;+ goto done;+ }+ if (!c->limited) {for (int i = 0; i < c->component_count; i++) {ap_component *p = &c->components[i];if (p->displayed < 0)diff --git a/tests/test_architecture_projection.c b/tests/test_architecture_projection.cindex 4e93ed30a..f169fe339 100644--- a/tests/test_architecture_projection.c+++ b/tests/test_architecture_projection.c@@ -1140,6 +1140,72 @@ TEST(projection_repeated_behavior_evidence_preserves_base_graph_under_budget) {PASS();}+/* Shaped like Django 5.2.7 (12,700 mostly single-symbol components, far below+ * the node and edge budgets): one full overview entry per component used to+ * exceed the 32 MB response budget, so the whole projection came back+ * limited and empty. The overview now lists a bounded, ranked subset and+ * still accounts for every component through its groups and totals. */+TEST(projection_many_small_components_stay_within_response_budget) {+ cbm_store_t *store = projection_store();+ ASSERT_NOT_NULL(store);+ enum { parts = 14000 };+ char padding[161];+ memset(padding, 'x', sizeof(padding) - 1);+ padding[sizeof(padding) - 1] = '\0';+ ASSERT_EQ(cbm_store_begin(store), CBM_STORE_OK);+ for (int i = 0; i < parts; i++) {+ char qn[256], file[256];+ snprintf(qn, sizeof(qn), "projection.area%d.%s%05d.Part", i % 8, padding, i);+ snprintf(file, sizeof(file), "src/area%d/%.*s%05d.py", i % 8, 120, padding, i);+ ASSERT_TRUE(projection_node(store, "Class", qn, file, false) > 0);+ }+ ASSERT_EQ(cbm_store_commit(store), CBM_STORE_OK);+ char *json = NULL;+ ASSERT_EQ(cbm_store_architecture_projection(store, "projection", NULL, &json), CBM_STORE_OK);+ ASSERT_NULL(strstr(json, "exceeded its memory budget"));+ /* architecture_jobs.c rejects results above 8 MiB. */+ ASSERT_TRUE(strlen(json) < 8 * 1024 * 1024);+ yyjson_doc *doc = yyjson_read(json, strlen(json), 0);+ ASSERT_NOT_NULL(doc);+ ASSERT_STR_EQ(yyjson_get_str(projection_field(doc, "status")), "ready");+ ASSERT_EQ(yyjson_get_int(yyjson_obj_get(projection_field(doc, "totals"), "components")), parts);+ yyjson_val *displayed = projection_field(doc, "components");+ ASSERT_EQ(yyjson_arr_size(displayed), 256);+ yyjson_val *overview = projection_field(doc, "overview"),+ *listed = yyjson_obj_get(overview, "components"),+ *groups = yyjson_obj_get(overview, "groups");+ size_t listed_count = yyjson_arr_size(listed);+ ASSERT_TRUE(listed_count >= 512);+ ASSERT_TRUE(listed_count < parts);+ ASSERT_FALSE(yyjson_get_bool(yyjson_obj_get(overview, "complete")));+ ASSERT_EQ(+ yyjson_get_int(yyjson_obj_get(yyjson_obj_get(overview, "limits"), "omitted_components")),+ parts - (int)listed_count);+ ASSERT_EQ(yyjson_get_int(yyjson_obj_get(yyjson_obj_get(overview, "totals"), "components")),+ parts);+ /* Every displayed component keeps its overview entry. */+ for (size_t i = 0; i < yyjson_arr_size(displayed); i++) {+ const char *id = yyjson_get_str(yyjson_obj_get(yyjson_arr_get(displayed, i), "id"));+ bool found = false;+ for (size_t j = 0; j < listed_count && !found; j++)+ found = !strcmp(id, yyjson_get_str(yyjson_obj_get(yyjson_arr_get(listed, j), "id")));+ ASSERT_TRUE(found);+ }+ size_t membership = 0;+ int members = 0;+ for (size_t i = 0; i < yyjson_arr_size(groups); i++) {+ yyjson_val *group = yyjson_arr_get(groups, i);+ membership += yyjson_arr_size(yyjson_obj_get(group, "component_ids"));+ members += yyjson_get_int(yyjson_obj_get(group, "member_count"));+ }+ ASSERT_EQ(membership, parts);+ ASSERT_EQ(members, parts);+ yyjson_doc_free(doc);+ free(json);+ cbm_store_close(store);+ PASS();+}+SUITE(architecture_projection) {RUN_TEST(projection_accounts_for_isolated_nodes_and_files);RUN_TEST(projection_preserves_typed_edges_and_contiguous_paths);@@ -1165,4 +1231,5 @@ SUITE(architecture_projection) {RUN_TEST(projection_missing_corrupt_and_noncall_arguments_remain_unknown);RUN_TEST(projection_oversized_evidence_is_omitted_without_truncating_values);RUN_TEST(projection_repeated_behavior_evidence_preserves_base_graph_under_budget);+ RUN_TEST(projection_many_small_components_stay_within_response_budget);}