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(windows): inicializa diagnósticos y verifica el límite con control sin techo

Subgurim262ab0121731
diff --git a/src/foundation/subprocess.c b/src/foundation/subprocess.c
index 475fe6741..83f788937 100644
--- a/src/foundation/subprocess.c
+++ b/src/foundation/subprocess.c
@@ -445,6 +445,9 @@ static void cbm_subprocess_result_init(cbm_proc_result_t *result) {
result->forced = false;
result->tree_quiesced = false;
result->supervision_failed = false;
+ result->job_memory_limit_bytes = 0;
+ result->peak_job_memory_bytes = 0;
+ result->job_memory_available = false;
}
static void cbm_subprocess_free_config(cbm_subprocess_t *process) {
diff --git a/src/foundation/subprocess.h b/src/foundation/subprocess.h
index 52267272c..54940de11 100644
--- a/src/foundation/subprocess.h
+++ b/src/foundation/subprocess.h
@@ -43,8 +43,8 @@ typedef struct {
bool tree_quiesced; /* the owned process tree has no surviving processes */
bool supervision_failed; /* the bounded containment deadline expired; tree_quiesced is false */
size_t job_memory_limit_bytes; /* Windows Job Object commit cap; zero on POSIX or uncapped */
- size_t peak_job_memory_bytes; /* Windows peak commit, not RSS or proof of a limit hit */
- bool job_memory_available; /* terminal Job Object memory query succeeded */
+ size_t peak_job_memory_bytes; /* Windows peak commit, not RSS or proof of a limit hit */
+ bool job_memory_available; /* terminal Job Object memory query succeeded */
} cbm_proc_result_t;
/* Called synchronously for each newly-completed log chunk while the child runs.
diff --git a/src/mcp/index_supervisor.c b/src/mcp/index_supervisor.c
index 4f4f3ac51..9aece3b3f 100644
--- a/src/mcp/index_supervisor.c
+++ b/src/mcp/index_supervisor.c
@@ -606,8 +606,9 @@ static void worker_terminal_log(cbm_index_worker_handle_t *handle) {
handle->process_result.job_memory_limit_bytes);
(void)snprintf(peak_text, sizeof(peak_text), "%zu",
handle->process_result.peak_job_memory_bytes);
- /* A rejected allocation can leave peak commit BELOW the cap. Report
- * evidence, not an inferred OOM classification or a file to quarantine. */
+ /* Peak accounting may include a denied allocation and exceed the cap,
+ * or remain below it. Report evidence, not an inferred OOM classification
+ * or a file to quarantine. */
cbm_log_warn("index.supervisor.worker_memory", "job_limit_bytes", limit_text,
"peak_job_memory_bytes",
handle->process_result.job_memory_available ? peak_text : "unavailable");
diff --git a/tests/test_subprocess.c b/tests/test_subprocess.c
index 79d456376..308d6b584 100644
--- a/tests/test_subprocess.c
+++ b/tests/test_subprocess.c
@@ -280,10 +280,20 @@ TEST(subprocess_run_spawn_failure) {
TEST(subprocess_run_null_bin_rejected) {
cbm_proc_opts_t opts = {0};
opts.bin = NULL;
- cbm_proc_result_t r;
+ /* Reusing a previous result must not expose stale Job Object diagnostics
+ * when validation rejects the next spawn before a process exists. */
+ cbm_proc_result_t r = {
+ .job_memory_limit_bytes = 123,
+ .peak_job_memory_bytes = 456,
+ .job_memory_available = true,
+ };
int rc = cbm_subprocess_run(&opts, &r);
ASSERT_EQ(rc, -1);
ASSERT_EQ(r.outcome, CBM_PROC_SPAWN_FAILED);
+ ASSERT_EQ(r.exit_code, -1);
+ ASSERT_TRUE(r.job_memory_limit_bytes == 0);
+ ASSERT_TRUE(r.peak_job_memory_bytes == 0);
+ ASSERT_FALSE(r.job_memory_available);
PASS();
}
@@ -755,12 +765,22 @@ TEST(subprocess_windows_job_object_enforces_memory_limit) {
cbm_proc_opts_t opts = {0};
opts.bin = self_path;
opts.argv = argv;
- opts.memory_limit_bytes = (size_t)1024U * 1024U * 1024U;
opts.quiet_timeout_ms = 5000;
+ /* Without the cap the SAME allocation must succeed. A machine-wide commit
+ * shortage must fail this test, not masquerade as Job Object enforcement. */
+ cbm_proc_result_t uncapped = {0};
+ int uncapped_rc = cbm_subprocess_run(&opts, &uncapped);
+ opts.memory_limit_bytes = (size_t)1024U * 1024U * 1024U;
cbm_proc_result_t result = {0};
int run_rc = cbm_subprocess_run(&opts, &result);
free(self_path);
+ ASSERT_EQ(uncapped_rc, 0);
+ ASSERT_EQ(uncapped.outcome, CBM_PROC_CLEAN);
+ ASSERT_EQ(uncapped.exit_code, 0);
+ ASSERT_TRUE(uncapped.tree_quiesced);
+ ASSERT_FALSE(uncapped.supervision_failed);
+ ASSERT_TRUE(uncapped.job_memory_limit_bytes == 0);
ASSERT_EQ(run_rc, 0);
ASSERT_EQ(result.outcome, CBM_PROC_EXIT_NONZERO);
ASSERT_EQ(result.exit_code, 73);
@@ -769,7 +789,8 @@ TEST(subprocess_windows_job_object_enforces_memory_limit) {
ASSERT_TRUE(result.job_memory_available);
ASSERT_TRUE(result.job_memory_limit_bytes == opts.memory_limit_bytes);
ASSERT_TRUE(result.peak_job_memory_bytes > 0);
- ASSERT_TRUE(result.peak_job_memory_bytes <= result.job_memory_limit_bytes);
+ /* Windows may include the denied reservation in its peak counter, so peak
+ * can exceed the cap. The uncapped/capped exit codes prove enforcement. */
PASS();
#endif
}