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(output): preserve compact output safety signals

Martin Vogel5f58e233dc5b
diff --git a/README.md b/README.md
index f370d512b..5e306cacb 100644
--- a/README.md
+++ b/README.md
@@ -735,7 +735,7 @@ codebase-memory-mcp config reset auto_index # reset to default
| `CBM_CACHE_DIR` | `~/.cache/codebase-memory-mcp` | Override the database storage directory. All project indexes and config are stored here. One account can use only one canonical cache root at a time; close active CBM sessions/commands before switching it. |
| `CBM_DIAGNOSTICS` | `false` | Set to `1` or `true` to enable the shared daemon's periodic `snapshot.json` and retained `trajectory.ndjson` below a fresh owner-private directory in the system temp directory. Exact paths are logged by `diagnostics.start`. |
| `CBM_DOWNLOAD_URL` | *(GitHub releases)* | Override the download URL for updates. Used for testing or self-hosted deployments. |
-| `CBM_LOG_LEVEL` | `info` | Set the minimum log level. Accepted values (case-insensitive): `debug`, `info`, `warn`, `error`, `none` — or their numeric equivalents `0`–`4` matching the internal enum. Thin-frontend messages go to that session's stderr; detached daemon events go to `${CBM_CACHE_DIR}/logs/cbm-daemon.log`. Stdout is reserved for MCP JSON-RPC. |
+| `CBM_LOG_LEVEL` | role-aware | Set the minimum log level. Thin MCP/CLI/hook frontends default to `warn`; the detached daemon and its supervised index workers default to `info` so lifecycle and liveness records remain available. Accepted values (case-insensitive): `debug`, `info`, `warn`, `error`, `none` — or their numeric equivalents `0`–`4`. A physical worker retains INFO liveness records even under a stricter override because its private log drives the supervisor's no-progress timeout. Frontend messages go to that session's stderr; detached daemon events go to `${CBM_CACHE_DIR}/logs/cbm-daemon.log`. Stdout is reserved for MCP JSON-RPC. |
| `CBM_WORKERS` | *(detected)* | Override the parallel-indexing worker count returned by `cbm_default_worker_count`. Useful inside containers where `sysconf(_SC_NPROCESSORS_ONLN)` reports host CPUs rather than the cgroup's effective quota. Range 1–256; invalid values are ignored with a warning. |
| `CBM_MEM_BUDGET_MB` | *(detected)* | Override the in-memory graph budget with an explicit cap in MiB, taking precedence over the `ram_fraction × total_RAM` default. Useful on bare-metal hosts without a cgroup limit, or to pin a budget *below* the cgroup limit so headroom is left for sibling processes. Must be a positive integer; it is clamped to detected total RAM (logged as `mem.budget.clamped`), and non-numeric or non-positive values are ignored with a warning (`mem.budget.env.invalid`). |
| `CBM_DUMP_VERIFY_MIN_RATIO` | `0.5` | After indexing, compare persisted SQLite node count to the in-memory dump count. When persisted nodes fall below this fraction of committed nodes (and committed > 50), `index_repository` returns `status:"degraded"` instead of silent `indexed`. Range 0–1; set `0` to disable. Invalid values are ignored with a warning. |
diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md
index fe9c24a7b..862d591c3 100644
--- a/docs/CONFIGURATION.md
+++ b/docs/CONFIGURATION.md
@@ -149,7 +149,7 @@ These environment variables affect runtime behavior:
| `CBM_CACHE_DIR` | `~/.cache/codebase-memory-mcp` | Override the cache directory used for indexes, `_config.db`, and UI `config.json`. |
| `CBM_DIAGNOSTICS` | `false` | Enable periodic `snapshot.json` and retained `trajectory.ndjson` below a fresh owner-private directory in the system temp directory. The daemon records the randomized paths in the `diagnostics.start` discovery record (a single JSON line) in `${CBM_CACHE_DIR}/logs/cbm-daemon.log`; that one record is emitted even when `CBM_LOG_LEVEL` suppresses ordinary logging, so the paths always remain discoverable. |
| `CBM_DOWNLOAD_URL` | GitHub releases | Override the update download URL. |
-| `CBM_LOG_LEVEL` | `info` | Set the log level to `debug`, `info`, `warn`, `error`, or `none` (or `0`-`4`). Thin-frontend messages use that session's stderr; detached daemon events use `${CBM_CACHE_DIR}/logs/cbm-daemon.log`. |
+| `CBM_LOG_LEVEL` | role-aware | Set the log level to `debug`, `info`, `warn`, `error`, or `none` (or `0`-`4`). Thin MCP/CLI/hook frontends default to `warn`; the detached daemon and supervised index workers default to `info`. Physical workers retain INFO liveness records because their private logs drive the supervisor's no-progress timeout. Frontend messages use that session's stderr; detached daemon events use `${CBM_CACHE_DIR}/logs/cbm-daemon.log`. |
| `CBM_RUNTIME_DIR` | `%LOCALAPPDATA%` (Windows), `/private/tmp` (macOS), `/tmp` (other) | Parent directory for the daemon/CLI rendezvous directory, which CBM creates inside it as `cbm-daemon-<uid>` (`cbm-daemon-<key>` on Windows). Set it when the default ancestry cannot pass the private-directory check — see below. `CBM_CACHE_DIR` does **not** move the rendezvous. |
| `CBM_WORKERS` | auto-detected | Override the indexing worker count. |
diff --git a/graph-ui/tsconfig.tsbuildinfo b/graph-ui/tsconfig.tsbuildinfo
index 5f1f5e115..0da71675b 100644
--- a/graph-ui/tsconfig.tsbuildinfo
+++ b/graph-ui/tsconfig.tsbuildinfo
@@ -1 +1 @@
-{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/rpc.ts","./src/components/controltab.tsx","./src/components/displaysettingsmenu.tsx","./src/components/edgelines.tsx","./src/components/errorboundary.tsx","./src/components/filterpanel.tsx","./src/components/graphloader.tsx","./src/components/graphscene.test.ts","./src/components/graphscene.tsx","./src/components/graphtab.deadcode.test.tsx","./src/components/graphtab.filters.test.tsx","./src/components/graphtab.test.ts","./src/components/graphtab.tsx","./src/components/missedcallout.tsx","./src/components/nodecloud.tsx","./src/components/nodedetailpanel.test.tsx","./src/components/nodedetailpanel.tsx","./src/components/nodelabels.tsx","./src/components/nodetooltip.tsx","./src/components/projectcard.tsx","./src/components/resizehandle.tsx","./src/components/sidebar.tsx","./src/components/statstab.test.tsx","./src/components/statstab.tsx","./src/components/tabbar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/card.tsx","./src/components/ui/checkbox.tsx","./src/components/ui/input.tsx","./src/components/ui/scroll-area.tsx","./src/components/ui/separator.tsx","./src/hooks/usegraphdata.test.ts","./src/hooks/usegraphdata.ts","./src/hooks/useprojects.test.tsx","./src/hooks/useprojects.ts","./src/lib/colors.ts","./src/lib/density.test.ts","./src/lib/density.ts","./src/lib/i18n.test.ts","./src/lib/i18n.ts","./src/lib/types.ts","./src/lib/utils.ts"],"version":"5.9.3"}
\ No newline at end of file
+{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/rpc.ts","./src/components/controltab.tsx","./src/components/edgelines.tsx","./src/components/errorboundary.tsx","./src/components/filterpanel.tsx","./src/components/graphscene.test.ts","./src/components/graphscene.tsx","./src/components/graphtab.test.ts","./src/components/graphtab.tsx","./src/components/nodecloud.tsx","./src/components/nodedetailpanel.tsx","./src/components/nodelabels.tsx","./src/components/nodetooltip.tsx","./src/components/projectcard.tsx","./src/components/resizehandle.tsx","./src/components/sidebar.tsx","./src/components/statstab.test.tsx","./src/components/statstab.tsx","./src/components/tabbar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/card.tsx","./src/components/ui/checkbox.tsx","./src/components/ui/input.tsx","./src/components/ui/scroll-area.tsx","./src/components/ui/separator.tsx","./src/hooks/usegraphdata.test.ts","./src/hooks/usegraphdata.ts","./src/hooks/useprojects.ts","./src/lib/colors.ts","./src/lib/i18n.test.ts","./src/lib/i18n.ts","./src/lib/types.ts","./src/lib/utils.ts"],"version":"5.9.3"}
\ No newline at end of file
diff --git a/src/cli/progress_sink.c b/src/cli/progress_sink.c
index 23868f2b2..f21c87f9f 100644
--- a/src/cli/progress_sink.c
+++ b/src/cli/progress_sink.c
@@ -33,6 +33,7 @@ static int s_gbuf_nodes = NOT_SET;
static int s_gbuf_edges = NOT_SET;
static CBMLogLevel s_previous_log_level = CBM_LOG_WARN;
static bool s_raised_log_level;
+static bool s_preserve_details;
static cbm_mutex_t s_sink_mutex;
static atomic_int s_sink_mutex_state = ATOMIC_VAR_INIT(LOCK_UNINITIALIZED);
@@ -187,6 +188,7 @@ void cbm_progress_sink_init(FILE *out) {
s_gbuf_nodes = NOT_SET;
s_gbuf_edges = NOT_SET;
s_previous_log_level = cbm_log_get_level();
+ s_preserve_details = s_previous_log_level <= CBM_LOG_INFO;
s_raised_log_level = s_previous_log_level > CBM_LOG_INFO;
if (s_raised_log_level) {
/* Progress is an explicit INFO opt-in. The replacement sink below
@@ -210,6 +212,7 @@ void cbm_progress_sink_fini(void) {
cbm_log_set_level(s_previous_log_level);
s_raised_log_level = false;
}
+ s_preserve_details = false;
cbm_mutex_unlock(&s_sink_mutex);
}
@@ -352,9 +355,10 @@ static const event_handler_t handlers[] = {
enum { HANDLER_COUNT = sizeof(handlers) / sizeof(handlers[0]) };
/* The progress sink replaces normal logger output. Preserve actionable
- * failures verbatim, but keep routine worker chatter out of the human progress
- * view. Logger callbacks do not include a trailing newline. */
-static void passthrough_failure(const char *line) {
+ * failures verbatim and, when INFO/DEBUG was already selected before progress
+ * initialization, preserve unrecognized diagnostic lines as well. Logger
+ * callbacks do not include a trailing newline. */
+static void passthrough_line(const char *line) {
flush_carriage();
(void)fputs(line, s_out);
size_t line_len = strlen(line);
@@ -377,7 +381,14 @@ void cbm_progress_sink_fn(const char *line) {
return;
}
if (strcmp(level, "warn") == 0 || strcmp(level, "error") == 0) {
- passthrough_failure(line);
+ passthrough_line(line);
+ cbm_mutex_unlock(&s_sink_mutex);
+ return;
+ }
+ if (strcmp(level, "debug") == 0) {
+ if (s_preserve_details) {
+ passthrough_line(line);
+ }
cbm_mutex_unlock(&s_sink_mutex);
return;
}
@@ -398,5 +409,8 @@ void cbm_progress_sink_fn(const char *line) {
return;
}
}
+ if (s_preserve_details) {
+ passthrough_line(line);
+ }
cbm_mutex_unlock(&s_sink_mutex);
}
diff --git a/src/foundation/log.c b/src/foundation/log.c
index 2179bfdcc..73d4695c6 100644
--- a/src/foundation/log.c
+++ b/src/foundation/log.c
@@ -106,6 +106,14 @@ parse_format:;
* silently change the operator-selected output shape. */
}
+void cbm_log_init_for_process(bool quiet_by_default, bool require_info_liveness) {
+ cbm_log_set_level(quiet_by_default ? CBM_LOG_WARN : CBM_LOG_INFO);
+ cbm_log_init_from_env();
+ if (require_info_liveness && cbm_log_get_level() > CBM_LOG_INFO) {
+ cbm_log_set_level(CBM_LOG_INFO);
+ }
+}
+
void cbm_log_set_sink(cbm_log_sink_fn fn) {
cbm_log_set_sink_ex(fn, CBM_LOG_SINK_REPLACE);
}
diff --git a/src/foundation/log.h b/src/foundation/log.h
index ae85a3bce..9ed8532df 100644
--- a/src/foundation/log.h
+++ b/src/foundation/log.h
@@ -44,7 +44,14 @@ typedef enum {
* unchanged. Call once at startup before any threads or log lines. */
void cbm_log_init_from_env(void);
-/* Set minimum log level (default: WARN; INFO is opt-in). */
+/* Apply a role-aware startup policy, then the environment override. Thin
+ * frontends pass quiet_by_default=true; detached daemons pass false. Physical
+ * workers also pass require_info_liveness=true because their private log is
+ * the supervisor's no-progress heartbeat, so WARN/NONE cannot suppress INFO
+ * lifecycle records and turn a healthy long index into a false hang. */
+void cbm_log_init_for_process(bool quiet_by_default, bool require_info_liveness);
+
+/* Set minimum log level (raw process default: WARN; startup policy is role-aware). */
void cbm_log_set_level(CBMLogLevel level);
/* Get current log level. */
diff --git a/src/main.c b/src/main.c
index ebb3de065..e8ad4e5c7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2541,7 +2541,13 @@ int main(int argc, char **argv) {
cbm_cli_set_version(CBM_VERSION);
cbm_profile_init();
- cbm_log_init_from_env();
+ /* The raw logger starts WARN so allocator setup cannot pollute protocol or
+ * CLI output before argv is classified. Detached daemons retain INFO
+ * lifecycle records; physical workers require INFO because those records
+ * are their supervisor's quiet-timeout heartbeat. */
+ bool quiet_log_default =
+ role != CBM_DAEMON_PROCESS_DAEMON && role != CBM_DAEMON_PROCESS_WORKER;
+ cbm_log_init_for_process(quiet_log_default, role == CBM_DAEMON_PROCESS_WORKER);
cbm_mcp_tool_profile_t tool_profile = CBM_MCP_TOOL_PROFILE_ALL;
if (role == CBM_DAEMON_PROCESS_MCP_CLIENT &&
diff --git a/src/mcp/compact_out.c b/src/mcp/compact_out.c
index c18c474fc..29745b925 100644
--- a/src/mcp/compact_out.c
+++ b/src/mcp/compact_out.c
@@ -216,6 +216,19 @@ static void append_value(cbm_sb_t *sb, const char *s) {
}
}
+/* Object keys and table column names share the compact tree's structural
+ * line. Keep common identifier-like names bare, but quote anything that can
+ * be confused with a delimiter or escape sequence. Unlike a value cell, an
+ * empty key must remain the lossless string "" rather than the missing-value
+ * placeholder "-". */
+static void append_key(cbm_sb_t *sb, const char *s) {
+ if (!s || !*s || needs_quotes(s) || strpbrk(s, ":()\\")) {
+ append_quoted(sb, s ? s : "");
+ } else {
+ cbm_sb_append(sb, s);
+ }
+}
+
/* ── Scalars ────────────────────────────────────────────────────── */
void cbm_tree_scalar_str(cbm_sb_t *sb, const char *key, const char *val) {
@@ -802,7 +815,7 @@ static void json_tree_object_table(cbm_sb_t *sb, const char *key_name, yyjson_va
return;
}
json_tree_indent(sb, depth);
- cbm_sb_append(sb, key_name);
+ append_key(sb, key_name);
char count[48];
snprintf(count, sizeof(count), ": %zu (cols:", yyjson_arr_size(array));
cbm_sb_append(sb, count);
@@ -813,7 +826,7 @@ static void json_tree_object_table(cbm_sb_t *sb, const char *key_name, yyjson_va
yyjson_val *unused;
yyjson_obj_foreach(first, key_index, key_maximum, column, unused) {
cbm_sb_append_n(sb, " ", 1);
- cbm_sb_append(sb, yyjson_get_str(column));
+ append_key(sb, yyjson_get_str(column));
}
cbm_sb_append_n(sb, ")\n", 2);
@@ -843,7 +856,7 @@ static void json_tree_array(cbm_sb_t *sb, const char *key_name, yyjson_val *arra
}
json_tree_indent(sb, depth);
- cbm_sb_append(sb, key_name);
+ append_key(sb, key_name);
char count[48];
snprintf(count, sizeof(count), ": %zu\n", yyjson_arr_size(array));
cbm_sb_append(sb, count);
@@ -875,7 +888,7 @@ static void json_tree_array(cbm_sb_t *sb, const char *key_name, yyjson_val *arra
static void json_tree_value(cbm_sb_t *sb, const char *key_name, yyjson_val *value, int depth) {
if (depth >= JSON_TREE_MAX_DEPTH) {
json_tree_indent(sb, depth);
- cbm_sb_append(sb, key_name);
+ append_key(sb, key_name);
cbm_sb_append(sb, ": ");
char *encoded = yyjson_val_write(value, 0, NULL);
append_value(sb, encoded ? encoded : "null");
@@ -885,7 +898,7 @@ static void json_tree_value(cbm_sb_t *sb, const char *key_name, yyjson_val *valu
}
if (yyjson_is_obj(value)) {
json_tree_indent(sb, depth);
- cbm_sb_append(sb, key_name);
+ append_key(sb, key_name);
cbm_sb_append(sb, ":\n");
size_t index;
size_t maximum;
@@ -899,12 +912,12 @@ static void json_tree_value(cbm_sb_t *sb, const char *key_name, yyjson_val *valu
} else if (yyjson_is_str(value) &&
(strchr(yyjson_get_str(value), '\n') || strchr(yyjson_get_str(value), '\r'))) {
json_tree_indent(sb, depth);
- cbm_sb_append(sb, key_name);
+ append_key(sb, key_name);
cbm_sb_append(sb, ": ");
json_tree_block_string(sb, yyjson_get_str(value), depth);
} else {
json_tree_indent(sb, depth);
- cbm_sb_append(sb, key_name);
+ append_key(sb, key_name);
cbm_sb_append(sb, ": ");
json_tree_scalar(sb, value);
cbm_sb_append_n(sb, "\n", 1);
diff --git a/tests/test_cli.c b/tests/test_cli.c
index 8d691f128..f4f53c6a5 100644
--- a/tests/test_cli.c
+++ b/tests/test_cli.c
@@ -151,6 +151,28 @@ TEST(cli_progress_sink_suppresses_noise_and_preserves_failures) {
PASS();
}
+TEST(cli_progress_sink_preserves_explicit_verbose_diagnostics) {
+ FILE *out = tmpfile();
+ ASSERT_NOT_NULL(out);
+ CBMLogLevel previous_level = cbm_log_get_level();
+ cbm_log_set_level(CBM_LOG_DEBUG);
+
+ cbm_progress_sink_init(out);
+ cbm_log_info("cli.daemon.spawned", "hint", "keep-info");
+ cbm_log_debug("cli.detail", "value", "keep-debug");
+ cbm_progress_sink_fini();
+ cbm_log_set_level(previous_level);
+
+ ASSERT_EQ(fseek(out, 0, SEEK_SET), 0);
+ char rendered[1024] = {0};
+ size_t rendered_size = fread(rendered, 1, sizeof(rendered) - 1, out);
+ (void)fclose(out);
+ ASSERT_TRUE(rendered_size > 0);
+ ASSERT_NOT_NULL(strstr(rendered, "msg=cli.daemon.spawned"));
+ ASSERT_NOT_NULL(strstr(rendered, "msg=cli.detail"));
+ PASS();
+}
+
enum { CLI_PROGRESS_RACE_THREADS = 4, CLI_PROGRESS_RACE_ROUNDS = 32 };
typedef struct {
@@ -14168,6 +14190,7 @@ SUITE(cli) {
RUN_TEST(cli_progress_sink_accepts_worker_json_logs);
RUN_TEST(cli_progress_sink_enables_lifecycle_info_then_restores_quiet_default);
RUN_TEST(cli_progress_sink_suppresses_noise_and_preserves_failures);
+ RUN_TEST(cli_progress_sink_preserves_explicit_verbose_diagnostics);
RUN_TEST(cli_progress_sink_serializes_concurrent_callbacks);
RUN_TEST(cli_sha256_file_matches_known_vector);
RUN_TEST(cli_checksum_manifest_requires_exact_filename_and_accepts_star);
diff --git a/tests/test_diagnostics.c b/tests/test_diagnostics.c
index f00caf041..269e32431 100644
--- a/tests/test_diagnostics.c
+++ b/tests/test_diagnostics.c
@@ -360,6 +360,7 @@ static bool diagnostics_discovery_value(const char *key, char *out, size_t out_s
TEST(diagnostics_discovery_record_survives_suppressed_log_level) {
diagnostics_discovery_records = 0;
diagnostics_discovery_line[0] = '\0';
+ CBMLogLevel previous_log_level = cbm_log_get_level();
cbm_log_set_level(CBM_LOG_NONE);
cbm_log_set_sink_ex(diagnostics_discovery_sink, CBM_LOG_SINK_REPLACE);
ASSERT_EQ(cbm_setenv("CBM_DIAGNOSTICS", "1", 1), 0);
@@ -369,7 +370,7 @@ TEST(diagnostics_discovery_record_survives_suppressed_log_level) {
cbm_diag_stop();
(void)cbm_unsetenv("CBM_DIAGNOSTICS");
cbm_log_set_sink(NULL);
- cbm_log_set_level(CBM_LOG_INFO);
+ cbm_log_set_level(previous_log_level);
char recorded_snapshot[1024] = "";
char recorded_trajectory[1024] = "";
diff --git a/tests/test_index_supervisor.c b/tests/test_index_supervisor.c
index c67f61fc4..8a65a4c03 100644
--- a/tests/test_index_supervisor.c
+++ b/tests/test_index_supervisor.c
@@ -643,6 +643,50 @@ TEST(index_supervisor_terminal_log_lifecycle_matches_outcome_and_profiling) {
PASS();
}
+TEST(index_supervisor_worker_keeps_default_info_liveness_heartbeat) {
+ char cache[INDEX_SUPERVISOR_TEST_PATH_CAP];
+ (void)snprintf(cache, sizeof(cache), "%s/cbm-index-heartbeat-XXXXXX", cbm_tmpdir());
+ ASSERT_NOT_NULL(cbm_mkdtemp(cache));
+ const char *old_cache = getenv("CBM_CACHE_DIR");
+ const char *old_log_level = getenv("CBM_LOG_LEVEL");
+ char *saved_cache = old_cache ? cbm_strdup(old_cache) : NULL;
+ char *saved_log_level = old_log_level ? cbm_strdup(old_log_level) : NULL;
+ (void)cbm_setenv("CBM_CACHE_DIR", cache, 1);
+ (void)cbm_unsetenv("CBM_LOG_LEVEL");
+
+ cbm_index_worker_handle_t *handle = NULL;
+ int start_rc = cbm_index_worker_start("{\"__cbm_test_worker\":\"heartbeat\"}", 0, false,
+ NULL, NULL, &handle);
+ char log_path[INDEX_SUPERVISOR_TEST_PATH_CAP] = {0};
+ if (handle) {
+ (void)snprintf(log_path, sizeof(log_path), "%s", cbm_index_worker_log_path(handle));
+ }
+ bool ready = log_path[0] && index_supervisor_test_wait_file_text(
+ log_path, "async worker heartbeat probe ready",
+ INDEX_SUPERVISOR_TEST_READY_MS);
+ bool heartbeat = ready && index_supervisor_test_wait_file_text(
+ log_path, "msg=pipeline.discover", 1000);
+ const cbm_index_worker_result_t *result = NULL;
+ bool terminal = handle && index_supervisor_test_poll_terminal(
+ handle, INDEX_SUPERVISOR_TEST_TERMINAL_MS, &result);
+ bool clean = terminal && result && result->outcome == CBM_PROC_CLEAN && result->response;
+ if (terminal) {
+ cbm_index_worker_destroy(handle);
+ } else {
+ index_supervisor_test_dump("heartbeat worker log", log_path);
+ index_supervisor_test_cleanup_handle(handle);
+ }
+ index_supervisor_test_restore_env("CBM_LOG_LEVEL", saved_log_level);
+ index_supervisor_test_restore_env("CBM_CACHE_DIR", saved_cache);
+ (void)th_rmtree(cache);
+
+ ASSERT_EQ(start_rc, 0);
+ ASSERT_TRUE(ready);
+ ASSERT_TRUE(heartbeat);
+ ASSERT_TRUE(clean);
+ PASS();
+}
+
TEST(index_supervisor_drains_terminal_backlog_into_request_progress_callback) {
char cache[INDEX_SUPERVISOR_TEST_PATH_CAP];
(void)snprintf(cache, sizeof(cache), "%s/cbm-index-relay-XXXXXX", cbm_tmpdir());
@@ -854,6 +898,7 @@ SUITE(index_supervisor) {
RUN_TEST(index_supervisor_async_jobs_are_isolated_cancellable_and_terminal_cached);
RUN_TEST(index_supervisor_sync_wrapper_forwards_cancel_and_drains_tree);
RUN_TEST(index_supervisor_terminal_log_lifecycle_matches_outcome_and_profiling);
+ RUN_TEST(index_supervisor_worker_keeps_default_info_liveness_heartbeat);
RUN_TEST(index_supervisor_drains_terminal_backlog_into_request_progress_callback);
RUN_TEST(index_supervisor_oversized_response_is_contained_and_log_is_retained);
RUN_TEST(index_supervisor_killed_worker_log_is_never_empty_and_names_the_run);
diff --git a/tests/test_log.c b/tests/test_log.c
index 3dcfd35d4..d52d27c88 100644
--- a/tests/test_log.c
+++ b/tests/test_log.c
@@ -55,7 +55,7 @@ static const char *capture_end(void) {
}
TEST(log_level_default) {
- /* Routine informational output is opt-in; libraries start quiet. */
+ /* Raw startup is quiet until main applies its role-aware policy. */
ASSERT_EQ(cbm_log_get_level(), CBM_LOG_WARN);
PASS();
}
@@ -74,6 +74,27 @@ TEST(log_level_env_keeps_info_and_debug_opt_in) {
PASS();
}
+TEST(log_startup_policy_keeps_frontends_quiet_and_workers_live) {
+ cbm_unsetenv("CBM_LOG_LEVEL");
+ cbm_log_init_for_process(true, false);
+ ASSERT_EQ(cbm_log_get_level(), CBM_LOG_WARN);
+
+ cbm_log_init_for_process(false, true);
+ ASSERT_EQ(cbm_log_get_level(), CBM_LOG_INFO);
+
+ cbm_setenv("CBM_LOG_LEVEL", "none", 1);
+ cbm_log_init_for_process(false, true);
+ ASSERT_EQ(cbm_log_get_level(), CBM_LOG_INFO);
+
+ cbm_setenv("CBM_LOG_LEVEL", "debug", 1);
+ cbm_log_init_for_process(true, false);
+ ASSERT_EQ(cbm_log_get_level(), CBM_LOG_DEBUG);
+
+ cbm_unsetenv("CBM_LOG_LEVEL");
+ cbm_log_set_level(CBM_LOG_WARN);
+ PASS();
+}
+
TEST(log_level_set) {
cbm_log_set_level(CBM_LOG_WARN);
ASSERT_EQ(cbm_log_get_level(), CBM_LOG_WARN);
@@ -300,6 +321,7 @@ TEST(log_level_from_env_invalid_ignored) {
SUITE(log) {
RUN_TEST(log_level_default);
RUN_TEST(log_level_env_keeps_info_and_debug_opt_in);
+ RUN_TEST(log_startup_policy_keeps_frontends_quiet_and_workers_live);
RUN_TEST(log_level_set);
RUN_TEST(log_info_output);
RUN_TEST(log_filtered_by_level);
diff --git a/tests/test_main.c b/tests/test_main.c
index 6c23050ea..72d45be10 100644
--- a/tests/test_main.c
+++ b/tests/test_main.c
@@ -16,6 +16,7 @@ int tf_skip_count = 0;
#include "foundation/constants.h" /* CBM_SZ_4K — forced stderr buffer */
#include "foundation/log.h" /* crash-durable worker log probe */
#include "foundation/mem.h" /* cbm_mem_init — worker budget */
+#include "foundation/log.h" /* worker liveness heartbeat probe */
#include "foundation/platform.h" /* cbm_file_exists — blocking-git marker */
#include "daemon/runtime.h" /* bounded worker response probe */
#include "daemon/ipc.h" /* Windows private-lock re-exec probe */
@@ -234,6 +235,17 @@ static void tf_index_worker_probe(const char *args_json, const char *response_ou
fflush(NULL);
_Exit(response ? 0 : 1);
}
+ if (strstr(args_json, "\"heartbeat\"")) {
+ FILE *response = response_out ? cbm_fopen(response_out, "wb") : NULL;
+ if (response) {
+ (void)fputs("{\"probe\":\"heartbeat\"}", response);
+ (void)fclose(response);
+ }
+ cbm_log_info("pipeline.discover", "files", "1");
+ (void)fprintf(stderr, "async worker heartbeat probe ready\n");
+ fflush(NULL);
+ _Exit(response ? 0 : 1);
+ }
if (strstr(args_json, "\"crash\"")) {
(void)fprintf(stderr, "async worker crash probe\n");
fflush(NULL);
@@ -346,6 +358,7 @@ static int tf_maybe_run_index_worker(int argc, char **argv) {
invocation.marker_file, invocation.quarantine_file,
invocation.memory_budget_bytes);
cbm_mem_init_with_cap(0.5, invocation.memory_budget_bytes);
+ cbm_log_init_for_process(false, true);
tf_index_worker_probe(invocation.args_json, invocation.response_out);
cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
if (!srv) {
diff --git a/tests/test_mcp.c b/tests/test_mcp.c
index 1c2c9ac0a..1608d297f 100644
--- a/tests/test_mcp.c
+++ b/tests/test_mcp.c
@@ -716,6 +716,21 @@ TEST(json_to_tree_keeps_multiline_source_readable) {
PASS();
}
+TEST(json_to_tree_quotes_dynamic_keys_without_line_injection) {
+ const char *json =
+ "{\"bad\\nkey\":{\"colon:key\":1,\"\":2},"
+ "\"rows\":[{\"col\\tname\":\"x\",\"close)\":\"y\"}]}";
+ char *tree = cbm_json_to_tree(json);
+ ASSERT_NOT_NULL(tree);
+ ASSERT_STR_EQ(tree, "\"bad\\nkey\":\n"
+ " \"colon:key\": 1\n"
+ " \"\": 2\n"
+ "rows: 1 (cols: \"col\\u0009name\" \"close)\")\n"
+ " x y\n");
+ free(tree);
+ PASS();
+}
+
/* Decode the intentionally tiny one-column subset used by the prefix-directory
* round-trip test. Its values need no tree quoting, so any mismatch is an
* encoder/reference bug rather than a second parser implementation. */
@@ -17828,6 +17843,7 @@ SUITE(mcp) {
RUN_TEST(tree_cell_sanitizes_control_and_invalid_utf8);
RUN_TEST(json_to_tree_uses_header_once_rows_without_losing_metadata);
RUN_TEST(json_to_tree_keeps_multiline_source_readable);
+ RUN_TEST(json_to_tree_quotes_dynamic_keys_without_line_injection);
RUN_TEST(tree_table_uses_prefix_dictionary_only_when_it_materially_wins);
RUN_TEST(jsonrpc_parse_tools_call);
RUN_TEST(jsonrpc_parse_string_id_issue253);