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
Never mutate the shared Tier-2 cross registry from resolve workers
Martin Vogel036a80ef41a7
diff --git a/internal/cbm/lsp/c_lsp.c b/internal/cbm/lsp/c_lsp.cindex 6e58e373d..41dcdff4b 100644--- a/internal/cbm/lsp/c_lsp.c+++ b/internal/cbm/lsp/c_lsp.c@@ -4143,8 +4143,14 @@ static void c_process_function(CLSPContext *ctx, TSNode func_node) {ctx->enclosing_func_qn = func_qn;// If inside a template, attach type_param_names to the registered function- // so pending template calls can be resolved at call sites.- if (ctx->in_template && ctx->template_param_count > 0) {+ // so pending template calls can be resolved at call sites. NEVER do this+ // against the shared Tier-2 cross registry: resolve workers walk files+ // concurrently, so the write races other readers AND stores a pointer to+ // THIS worker's per-file arena into shared state — once that arena is+ // recycled the registry holds dangling memory (intermittent SIGSEGV+ // indexing bitcoin). Cross-phase template deduction then relies on the+ // positional fallback, which is graceful degradation.+ if (ctx->in_template && ctx->template_param_count > 0 && !ctx->registry_shared) {// Find the registered function and set type_param_namesfor (int ri = 0; ri < ((CBMTypeRegistry *)ctx->registry)->func_count; ri++) {CBMRegisteredFunc *rf = &((CBMTypeRegistry *)ctx->registry)->funcs[ri];@@ -5207,6 +5213,7 @@ void cbm_run_c_lsp_cross_with_registry(CBMArena *arena, const char *source, intCLSPContext ctx;c_lsp_init(&ctx, arena, source, source_len, reg, module_qn, cpp_mode, out);+ ctx.registry_shared = true; /* Tier-2 shared registry: read-only, see flag doc */for (int i = 0; i < include_count; i++) {c_lsp_add_include(&ctx, include_paths[i], include_ns_qns[i]);}diff --git a/internal/cbm/lsp/c_lsp.h b/internal/cbm/lsp/c_lsp.hindex 1da23a5ba..23132555b 100644--- a/internal/cbm/lsp/c_lsp.h+++ b/internal/cbm/lsp/c_lsp.h@@ -71,8 +71,11 @@ typedef struct {int pending_tc_cap;// Flags- bool cpp_mode; // C++ features enabled- bool in_template; // currently inside template declaration+ bool cpp_mode; // C++ features enabled+ bool in_template; // currently inside template declaration+ bool registry_shared; // ctx->registry is the Tier-2 cross registry, shared+ // READ-ONLY across resolve workers — never mutate it+ // (and never store per-worker arena pointers into it)bool debug;int eval_depth; // recursion depth for c_eval_expr_type (crash guard)int eval_steps; // total expression eval calls for current file (hang guard)