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(ci): restore vendored mimalloc, hoist enum out of struct, format
Martin Vogela46627d6ee06
diff --git a/src/daemon/runtime.c b/src/daemon/runtime.cindex 784c0e108..c11bcd0a7 100644--- a/src/daemon/runtime.c+++ b/src/daemon/runtime.c@@ -1868,7 +1868,6 @@ static void runtime_connection_serve(cbm_daemon_runtime_worker_t *worker) {return;}-/* One persistent thread per pooled slot. It parks on work_ready between* connections instead of being recreated, so the process keeps a constant set* of allocator thread-heaps (#581). */@@ -1933,8 +1932,7 @@ static void runtime_reap_completed_workers(cbm_daemon_runtime_service_t *service* it parks for the next connection, which is the whole point of the* pool. Threads are joined once, at service shutdown. */bool reap = worker->in_use && worker->thread_started && !worker->joining &&- !worker->has_work &&- atomic_load_explicit(&worker->done, memory_order_acquire);+ !worker->has_work && atomic_load_explicit(&worker->done, memory_order_acquire);if (reap) {runtime_worker_reset_after_join(worker);}diff --git a/src/foundation/compat_thread.c b/src/foundation/compat_thread.cindex 9dcc3a4ef..cb7d0d179 100644--- a/src/foundation/compat_thread.c+++ b/src/foundation/compat_thread.c@@ -49,10 +49,10 @@ static bool thread_release_heap_enabled(void) {static int state = -1;if (state < 0) {char buf[CBM_SZ_16];- state = (cbm_safe_getenv("CBM_MI_THREAD_DONE", buf, sizeof(buf), NULL) != NULL &&- buf[0] == '0')- ? 0- : 1;+ state =+ (cbm_safe_getenv("CBM_MI_THREAD_DONE", buf, sizeof(buf), NULL) != NULL && buf[0] == '0')+ ? 0+ : 1;}return state == 1;}diff --git a/src/foundation/diagnostics.c b/src/foundation/diagnostics.cindex 6047b50e5..b09578522 100644--- a/src/foundation/diagnostics.c+++ b/src/foundation/diagnostics.c@@ -146,8 +146,8 @@ static void diag_write_allocator_stats(void) {* owner-private with anchored (openat-based) writes on POSIX, which a plain* path-based open does not satisfy. This file is a developer diagnostic, so* a predictable temp path keeps it working identically on every platform. */- int written = snprintf(path, sizeof(path), "%s/cbm-allocator-stats-%d.txt", cbm_tmpdir(),- (int)getpid());+ int written =+ snprintf(path, sizeof(path), "%s/cbm-allocator-stats-%d.txt", cbm_tmpdir(), (int)getpid());if (written <= 0 || (size_t)written >= sizeof(path)) {return;}diff --git a/src/foundation/mem.c b/src/foundation/mem.cindex 24374b4c7..7ccdec690 100644--- a/src/foundation/mem.c+++ b/src/foundation/mem.c@@ -295,12 +295,12 @@ void cbm_mem_init_with_cap(double ram_fraction, size_t hard_cap_bytes) {* mean freed pages will not come back. */char classes[CBM_SZ_256];int length = 0;- for (int i = 0; i < CBM_MEM_OWNERSHIP_CLASSES && length >= 0 &&- (size_t)length < sizeof(classes);+ for (int i = 0;+ i < CBM_MEM_OWNERSHIP_CLASSES && length >= 0 && (size_t)length < sizeof(classes);i++) {if (audit.allocated[i] && !audit.owned[i]) {- int written = snprintf(classes + length, sizeof(classes) - (size_t)length,- "%s%zu", length ? "," : "", audit.probe_bytes[i]);+ int written = snprintf(classes + length, sizeof(classes) - (size_t)length, "%s%zu",+ length ? "," : "", audit.probe_bytes[i]);if (written < 0) {break;}@@ -358,9 +358,8 @@ void cbm_mem_init_with_cap(double ram_fraction, size_t hard_cap_bytes) {char profile_threshold[CBM_SZ_32];(void)snprintf(profile_threshold, sizeof(profile_threshold), "%zu",cbm_mem_profile_threshold());- cbm_log_info("mem.profile.gate", "enabled",- cbm_mem_profile_enabled() ? "true" : "false", "threshold",- profile_threshold);+ cbm_log_info("mem.profile.gate", "enabled", cbm_mem_profile_enabled() ? "true" : "false",+ "threshold", profile_threshold);}cbm_log_info("mem.init", "budget_mb", budget_mb, "total_ram_mb", ram_mb, "source",resolved.source);@@ -766,7 +765,7 @@ bool cbm_mem_win_census(cbm_mem_win_census_t *out) {} else {out->private_large_bytes += mbi.RegionSize;out->private_large_count++;- if (out->large_tracked < 6) {+ if (out->large_tracked < CBM_MEM_TRACKED_REGIONS) {out->large_base[out->large_tracked] = mbi.BaseAddress;out->large_size[out->large_tracked] = mbi.RegionSize;out->large_tracked++;@@ -827,17 +826,6 @@ bool cbm_mem_win_census(cbm_mem_win_census_t *out) {#endif}-#ifdef _WIN32-/* Defined in the vendored allocator's Windows primitives (see the note there):- * how often a decommit was attempted, how often it failed, and the last error.- * A non-zero failure count means the allocator's "purged" accounting is- * fiction and the OS still charges us for those pages. */-extern size_t mi_cbm_decommit_calls;-extern size_t mi_cbm_decommit_failures;-extern size_t mi_cbm_decommit_last_error;-extern size_t mi_cbm_decommit_bytes;-#endif-/* mi_stats_print_out hands us one chunk at a time; append each to the file. */static void mem_stats_writer(const char *text, void *arg) {FILE *out = arg;@@ -897,22 +885,6 @@ void cbm_mem_census_log(const char *tag) {(void)strncat(large_map, one, sizeof(large_map) - strlen(large_map) - 1);}(void)snprintf(heaps, sizeof(heaps), "%u", census.heap_walk_ok ? census.crt_heap_count : 0);- char dc_calls[CBM_SZ_32];- char dc_fail[CBM_SZ_32];- char dc_err[CBM_SZ_32];- char dc_mb[CBM_SZ_32];-#ifdef _WIN32- (void)snprintf(dc_calls, sizeof(dc_calls), "%zu", mi_cbm_decommit_calls);- (void)snprintf(dc_fail, sizeof(dc_fail), "%zu", mi_cbm_decommit_failures);- (void)snprintf(dc_err, sizeof(dc_err), "%zu", mi_cbm_decommit_last_error);- (void)snprintf(dc_mb, sizeof(dc_mb), "%zu",- mi_cbm_decommit_bytes / ((size_t)CBM_SZ_1K * CBM_SZ_1K));-#else- (void)snprintf(dc_calls, sizeof(dc_calls), "n/a");- (void)snprintf(dc_fail, sizeof(dc_fail), "n/a");- (void)snprintf(dc_err, sizeof(dc_err), "n/a");- (void)snprintf(dc_mb, sizeof(dc_mb), "n/a");-#endif/* Attribution alongside the pool totals: the census says which pool holds* the memory, the profile says which call sites put it there. Emitting* both from one place keeps the two views on the same sample. */@@ -937,18 +909,17 @@ void cbm_mem_census_log(const char *tag) {(void)snprintf(prof_sites, sizeof(prof_sites), "%zu", profile.sites);(void)snprintf(prof_total_kb, sizeof(prof_total_kb), "%zu", profile.total_bytes / CBM_SZ_1K);(void)snprintf(prof_lost, sizeof(prof_lost), "%zu",- profile.site_table_full + profile.pointer_table_full +- profile.capture_failed);+ profile.site_table_full + profile.pointer_table_full + profile.capture_failed);char profile_path[CBM_SZ_1K];if (cbm_safe_getenv("CBM_MEM_PROFILE_OUT", profile_path, sizeof(profile_path), NULL) != NULL) {(void)cbm_mem_profile_dump(profile_path, tag ? tag : "?");}- cbm_log_info("mem.census", "at", tag ? tag : "?",- "prof_live_kb", prof_live_kb, "mi_area_kb", map_area_kb, "mi_live_kb", map_live_kb, "prof_sites", prof_sites, "prof_total_kb", prof_total_kb, "prof_lost", prof_lost, "priv_kb", priv_kb, "crt_kb", crt_kb,+ cbm_log_info("mem.census", "at", tag ? tag : "?", "prof_live_kb", prof_live_kb, "mi_area_kb",+ map_area_kb, "mi_live_kb", map_live_kb, "prof_sites", prof_sites, "prof_total_kb",+ prof_total_kb, "prof_lost", prof_lost, "priv_kb", priv_kb, "crt_kb", crt_kb,"crt_busy_kb", busy_kb, "mapped_kb", mapped_kb, "rss_kb", rss_kb, "biggest_kb",biggest_kb, "regions", regions, "big_regions", big_regions, "heaps", heaps,- "decommit_calls", dc_calls, "decommit_fails", dc_fail, "decommit_err", dc_err,- "decommit_mb", dc_mb, "biggest_base", base, "priv_small_kb", psmall, "priv_med_kb", pmed,+ "biggest_base", base, "priv_small_kb", psmall, "priv_med_kb", pmed,"priv_large_kb", plarge, "priv_counts", pcounts, "large_map", large_map);/* The phase table answers WHICH bracketed path the committed bytes stayed* in. Emitted once at the end rather than per request: it is cumulative,diff --git a/src/foundation/mem.h b/src/foundation/mem.hindex e3cb45aea..38a290adb 100644--- a/src/foundation/mem.h+++ b/src/foundation/mem.h@@ -223,12 +223,14 @@ int cbm_mem_phase_report_json(char *out, size_t size);* Windows-only; returns false everywhere else so callers must handle absence* rather than silently reading zeros as "nothing there".*/+enum { CBM_MEM_TRACKED_REGIONS = 6 };+typedef struct {- size_t committed_total; /* all MEM_COMMIT regions */- size_t committed_private; /* MEM_PRIVATE: heaps, stacks, raw VirtualAlloc */- size_t committed_mapped; /* MEM_MAPPED: file/section views */- size_t committed_image; /* MEM_IMAGE: loaded modules */- size_t reserved_total; /* MEM_RESERVE, uncommitted */+ size_t committed_total; /* all MEM_COMMIT regions */+ size_t committed_private; /* MEM_PRIVATE: heaps, stacks, raw VirtualAlloc */+ size_t committed_mapped; /* MEM_MAPPED: file/section views */+ size_t committed_image; /* MEM_IMAGE: loaded modules */+ size_t reserved_total; /* MEM_RESERVE, uncommitted */size_t crt_heap_committed; /* committed bytes across all CRT heaps */size_t crt_heap_busy; /* bytes in live allocations inside them */unsigned crt_heap_count;@@ -249,9 +251,8 @@ typedef struct {/* Identity, not just size: base and extent of the largest private regions,* so they can be matched against the allocator's arena addresses instead of* guessed at by toggling options one at a time. */- enum { CBM_MEM_TRACKED_REGIONS = 6 };- void *large_base[6];- size_t large_size[6];+ void *large_base[CBM_MEM_TRACKED_REGIONS];+ size_t large_size[CBM_MEM_TRACKED_REGIONS];unsigned large_tracked;size_t largest_private_region;unsigned private_regions_1mb;diff --git a/src/foundation/mem_profile.h b/src/foundation/mem_profile.hindex 8ed6d1512..44613a45b 100644--- a/src/foundation/mem_profile.h+++ b/src/foundation/mem_profile.h@@ -43,8 +43,8 @@ void cbm_mem_profile_alloc_at(void *block, size_t size, void *caller);void cbm_mem_profile_free(void *block);typedef struct {- size_t sites; /* distinct call sites seen */- size_t live_bytes; /* currently retained, attributed */+ size_t sites; /* distinct call sites seen */+ size_t live_bytes; /* currently retained, attributed */size_t live_blocks;size_t total_bytes; /* cumulative allocated at/above threshold */size_t untracked_frees; /* frees whose pointer was not in the table */diff --git a/src/store/store.c b/src/store/store.cindex 81e874d2d..ca476752d 100644--- a/src/store/store.c+++ b/src/store/store.c@@ -753,8 +753,8 @@ void cbm_store_configure_pagecache(void) {/* Fail loud rather than silently reverting to per-connection cache* allocation, which is the behaviour that produced #581. Not fatal:* the store still works, it just fragments — so say so clearly. */- cbm_log_warn("store.pagecache.config_failed", "rc", rc == SQLITE_MISUSE ? "misuse" : "error",- "detail",+ cbm_log_warn("store.pagecache.config_failed", "rc",+ rc == SQLITE_MISUSE ? "misuse" : "error", "detail","shared SQLite page-cache slab was refused (SQLite already initialised?); ""page cache will be served from the general allocator and may fragment");}diff --git a/vendored/mimalloc/src/prim/windows/prim.c b/vendored/mimalloc/src/prim/windows/prim.cindex 647515aa0..51ad3104f 100644--- a/vendored/mimalloc/src/prim/windows/prim.c+++ b/vendored/mimalloc/src/prim/windows/prim.c@@ -382,26 +382,8 @@ int _mi_prim_commit(void* addr, size_t size, bool* is_zero) {return 0;}-// cbm diagnostic (#581): a failed decommit is assumed successful below, so the-// allocator decrements its own committed counter while the OS keeps charging-// for the pages. That divergence is invisible in mi_stats and was the reason a-// Windows daemon ratcheted commit charge while reporting a small heap. These-// counters are read by the process census; they are diagnostic only, so a-// racing update that loses a count is acceptable.-size_t mi_cbm_decommit_calls = 0;-size_t mi_cbm_decommit_failures = 0;-size_t mi_cbm_decommit_last_error = 0;-size_t mi_cbm_decommit_bytes = 0;-int _mi_prim_decommit(void* addr, size_t size, bool* needs_recommit) {BOOL ok = VirtualFree(addr, size, MEM_DECOMMIT);- mi_cbm_decommit_calls++;- if (ok) {- mi_cbm_decommit_bytes += size;- } else {- mi_cbm_decommit_failures++;- mi_cbm_decommit_last_error = (size_t)GetLastError();- }*needs_recommit = true; // for safety, assume always decommitted even in the case of an error.return (ok ? 0 : (int)GetLastError());}