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: stabilize Windows coordination startup

Martin Vogel410c8d70c8f3
diff --git a/.github/workflows/_smoke.yml b/.github/workflows/_smoke.yml
index b4059e9b7..c635ebd4a 100644
--- a/.github/workflows/_smoke.yml
+++ b/.github/workflows/_smoke.yml
@@ -248,7 +248,8 @@ jobs:
SMOKE_DIR="$(mktemp -d "$PROFILE_ROOT/cbm-release-smoke.XXXXXX")"
trap 'rm -rf "$SMOKE_DIR"' EXIT
cp codebase-memory-mcp.exe codebase-memory-mcp.payload.exe "$SMOKE_DIR/"
- SMOKE_TEMP_ROOT="$SMOKE_DIR" \
+ CBM_CACHE_DIR="$(cygpath -m "$SMOKE_DIR/cache")" \
+ SMOKE_TEMP_ROOT="$SMOKE_DIR" \
scripts/smoke-test.sh "$SMOKE_DIR/codebase-memory-mcp.exe"
env:
SMOKE_DOWNLOAD_URL: http://127.0.0.1:18080
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index a98a1d62b..797a335bd 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -124,7 +124,8 @@ jobs:
"$SMOKE_DIR/codebase-memory-mcp.exe"
cp build/c/codebase-memory-mcp.exe \
"$SMOKE_DIR/codebase-memory-mcp.payload.exe"
- SMOKE_TEMP_ROOT="$SMOKE_DIR" \
+ CBM_CACHE_DIR="$(cygpath -m "$SMOKE_DIR/cache")" \
+ SMOKE_TEMP_ROOT="$SMOKE_DIR" \
scripts/smoke-test.sh "$SMOKE_DIR/codebase-memory-mcp.exe"
ci-ok:
diff --git a/src/main.c b/src/main.c
index d269957a0..4f3599adf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1018,19 +1018,52 @@ static bool main_resolve_executable(const char *argv0, char out[MAIN_PATH_CAP])
cbm_canonical_path(resolved, out, MAIN_PATH_CAP);
}
-static bool main_build_identity(cbm_daemon_build_identity_t *identity) {
- if (!identity || !cbm_index_supervisor_capture_build_fingerprint()) {
- return false;
+typedef enum {
+ MAIN_BUILD_IDENTITY_OK = 0,
+ MAIN_BUILD_IDENTITY_INVALID_OUTPUT,
+ MAIN_BUILD_IDENTITY_PROCESS_FINGERPRINT,
+ MAIN_BUILD_IDENTITY_CACHE_RESOLVE,
+ MAIN_BUILD_IDENTITY_CACHE_CANONICALIZE,
+ MAIN_BUILD_IDENTITY_CACHE_PRIVATE,
+ MAIN_BUILD_IDENTITY_CACHE_ENVIRONMENT,
+} main_build_identity_status_t;
+
+static const char *main_build_identity_status_name(main_build_identity_status_t status) {
+ switch (status) {
+ case MAIN_BUILD_IDENTITY_OK:
+ return "ok";
+ case MAIN_BUILD_IDENTITY_INVALID_OUTPUT:
+ return "identity-output";
+ case MAIN_BUILD_IDENTITY_PROCESS_FINGERPRINT:
+ return "process-fingerprint";
+ case MAIN_BUILD_IDENTITY_CACHE_RESOLVE:
+ return "cache-resolve";
+ case MAIN_BUILD_IDENTITY_CACHE_CANONICALIZE:
+ return "cache-canonicalize";
+ case MAIN_BUILD_IDENTITY_CACHE_PRIVATE:
+ return "cache-private";
+ case MAIN_BUILD_IDENTITY_CACHE_ENVIRONMENT:
+ return "cache-environment";
+ }
+ return "identity-unknown";
+}
+
+static main_build_identity_status_t main_build_identity(cbm_daemon_build_identity_t *identity) {
+ if (!identity) {
+ return MAIN_BUILD_IDENTITY_INVALID_OUTPUT;
+ }
+ if (!cbm_index_supervisor_capture_build_fingerprint()) {
+ return MAIN_BUILD_IDENTITY_PROCESS_FINGERPRINT;
}
const char *fingerprint = cbm_index_supervisor_build_fingerprint();
if (!fingerprint) {
- return false;
+ return MAIN_BUILD_IDENTITY_PROCESS_FINGERPRINT;
}
const char *cache = cbm_resolve_cache_dir();
char canonical_cache[MAIN_PATH_CAP];
static char cache_fingerprint[CBM_SHA256_HEX_LEN + 1];
if (!cache || !cache[0]) {
- return false;
+ return MAIN_BUILD_IDENTITY_CACHE_RESOLVE;
}
/* Preserve one intentional alias spelling at the process boundary: an
* existing directory (including a symlink supplied by the user) is
@@ -1043,7 +1076,7 @@ static bool main_build_identity(cbm_daemon_build_identity_t *identity) {
cache_ready = cbm_canonical_path(cache, canonical_cache, sizeof(canonical_cache));
}
if (!cache_ready || !cbm_is_dir(canonical_cache)) {
- return false;
+ return MAIN_BUILD_IDENTITY_CACHE_CANONICALIZE;
}
cbm_normalize_path_sep(canonical_cache);
/* Admission is account-scoped, so its storage authority must be too.
@@ -1052,14 +1085,14 @@ static bool main_build_identity(cbm_daemon_build_identity_t *identity) {
* the v1 threat boundary; cross-account and unsafe filesystem states fail
* here before any daemon/cohort state is opened. */
if (!cbm_daemon_ipc_private_directory_secure(canonical_cache)) {
- return false;
+ return MAIN_BUILD_IDENTITY_CACHE_PRIVATE;
}
/* Every cache consumer in this process must use the exact path whose
* fingerprint joins the account-wide cohort. Keeping an original symlink
* spelling in the environment would let a later retarget move storage
* while the process still advertises the old canonical root. */
if (cbm_setenv("CBM_CACHE_DIR", canonical_cache, 1) != 0) {
- return false;
+ return MAIN_BUILD_IDENTITY_CACHE_ENVIRONMENT;
}
cbm_sha256_hex(canonical_cache, strlen(canonical_cache), cache_fingerprint);
*identity = (cbm_daemon_build_identity_t){
@@ -1070,7 +1103,7 @@ static bool main_build_identity(cbm_daemon_build_identity_t *identity) {
.store_abi = 1,
.feature_abi = 1,
};
- return true;
+ return MAIN_BUILD_IDENTITY_OK;
}
static uint64_t main_deadline_after(uint32_t timeout_ms) {
@@ -1378,14 +1411,27 @@ int main(int argc, char **argv) {
cbm_daemon_maintenance_monitor_t *maintenance_monitor = NULL;
cbm_daemon_conflict_t cohort_conflict;
cbm_version_cohort_status_t cohort_status = CBM_VERSION_COHORT_IO;
+ main_build_identity_status_t local_identity_status = MAIN_BUILD_IDENTITY_OK;
int result = CBM_NOT_FOUND;
int exit_code = EXIT_FAILURE;
bool cleanup_ok = true;
- if (!local_endpoint || !project_locks || !cohort_manager ||
- !main_resolve_executable(argv[0], local_executable) ||
- !main_build_identity(&local_identity)) {
- (void)fprintf(stderr,
- "codebase-memory-mcp: secure CLI coordination could not be created\n");
+ const char *coordination_failure = NULL;
+ if (!local_endpoint) {
+ coordination_failure = "endpoint";
+ } else if (!project_locks) {
+ coordination_failure = "project-locks";
+ } else if (!cohort_manager) {
+ coordination_failure = "version-cohort";
+ } else if (!main_resolve_executable(argv[0], local_executable)) {
+ coordination_failure = "executable-path";
+ } else if ((local_identity_status = main_build_identity(&local_identity)) !=
+ MAIN_BUILD_IDENTITY_OK) {
+ coordination_failure = main_build_identity_status_name(local_identity_status);
+ }
+ if (coordination_failure) {
+ (void)fprintf(
+ stderr, "codebase-memory-mcp: secure CLI coordination could not be created (%s)\n",
+ coordination_failure);
goto local_cli_cleanup;
}
cbm_http_server_set_binary_path(local_executable);
@@ -1484,9 +1530,18 @@ int main(int argc, char **argv) {
char executable_path[MAIN_PATH_CAP];
cbm_daemon_build_identity_t identity;
- if (!main_resolve_executable(argv[0], executable_path) || !main_build_identity(&identity)) {
+ if (!main_resolve_executable(argv[0], executable_path)) {
+ (void)fprintf(stderr,
+ "codebase-memory-mcp: exact executable identity could not be verified "
+ "(executable-path)\n");
+ return role == CBM_DAEMON_PROCESS_HOOK_CLIENT ? EXIT_SUCCESS : EXIT_FAILURE;
+ }
+ main_build_identity_status_t identity_status = main_build_identity(&identity);
+ if (identity_status != MAIN_BUILD_IDENTITY_OK) {
(void)fprintf(stderr,
- "codebase-memory-mcp: exact executable identity could not be verified\n");
+ "codebase-memory-mcp: exact executable identity could not be verified "
+ "(%s)\n",
+ main_build_identity_status_name(identity_status));
return role == CBM_DAEMON_PROCESS_HOOK_CLIENT ? EXIT_SUCCESS : EXIT_FAILURE;
}
cbm_http_server_set_binary_path(executable_path);
diff --git a/tests/test_lock_registry.c b/tests/test_lock_registry.c
index 05c16d90d..c83fc6bf6 100644
--- a/tests/test_lock_registry.c
+++ b/tests/test_lock_registry.c
@@ -65,6 +65,7 @@ static cbm_private_lock_directory_t *lock_registry_test_directory_open(const cha
}
#endif
+#ifndef _WIN32
static bool lock_registry_fixture_start(lock_registry_fixture_t *fixture) {
memset(fixture, 0, sizeof(*fixture));
#ifdef _WIN32
@@ -109,6 +110,7 @@ static void lock_registry_fixture_finish(lock_registry_fixture_t *fixture) {
#endif
memset(fixture, 0, sizeof(*fixture));
}
+#endif
typedef struct {
cbm_lock_registry_t *registry;
@@ -120,6 +122,7 @@ typedef struct {
cbm_lock_lease_t *lease;
} lock_registry_waiter_t;
+#ifndef _WIN32
static void *lock_registry_waiter_run(void *opaque) {
lock_registry_waiter_t *waiter = opaque;
waiter->status = cbm_lock_registry_acquire(waiter->registry, waiter->resource_key, waiter->mode,
@@ -142,6 +145,7 @@ static void lock_registry_cancel_at_native_ready(void *opaque, cbm_private_file_
atomic_store_explicit(&fault->cancel_token, true, memory_order_release);
}
}
+#endif
TEST(lock_registry_cancelled_wait_rolls_back_and_does_not_barge) {
#ifdef _WIN32
@@ -1023,6 +1027,7 @@ typedef struct {
cbm_lock_lease_t *lease;
} lock_registry_deadline_waiter_t;
+#ifndef _WIN32
static void *lock_registry_deadline_waiter_run(void *opaque) {
lock_registry_deadline_waiter_t *waiter = opaque;
atomic_store_explicit(&waiter->ready, true, memory_order_release);
@@ -1036,6 +1041,7 @@ static void *lock_registry_deadline_waiter_run(void *opaque) {
atomic_store_explicit(&waiter->finished, true, memory_order_release);
return NULL;
}
+#endif
TEST(lock_registry_absolute_deadline_survives_repeated_wakes) {
#ifdef _WIN32
@@ -1169,6 +1175,7 @@ typedef struct {
atomic_int *violations;
} lock_registry_stress_worker_t;
+#ifndef _WIN32
static void *lock_registry_stress_run(void *opaque) {
lock_registry_stress_worker_t *worker = opaque;
(void)atomic_fetch_add_explicit(worker->ready, 1, memory_order_acq_rel);
@@ -1215,6 +1222,7 @@ static void *lock_registry_stress_run(void *opaque) {
}
return NULL;
}
+#endif
TEST(lock_registry_concurrent_shared_exclusive_stress) {
#ifdef _WIN32
diff --git a/tests/test_windows_bundle_contract.sh b/tests/test_windows_bundle_contract.sh
index caa5cfc31..823fedc75 100644
--- a/tests/test_windows_bundle_contract.sh
+++ b/tests/test_windows_bundle_contract.sh
@@ -508,6 +508,7 @@ require(
'PROFILE_ROOT="$(cygpath -u "$USERPROFILE")"',
'SMOKE_DIR="$(mktemp -d "$PROFILE_ROOT/cbm-release-smoke.XXXXXX")"',
'cp codebase-memory-mcp.exe codebase-memory-mcp.payload.exe "$SMOKE_DIR/"',
+ 'CBM_CACHE_DIR="$(cygpath -m "$SMOKE_DIR/cache")" '
'SMOKE_TEMP_ROOT="$SMOKE_DIR" '
'scripts/smoke-test.sh "$SMOKE_DIR/codebase-memory-mcp.exe"',
)
@@ -655,6 +656,7 @@ if pr_windows_blocks:
'"$SMOKE_DIR/codebase-memory-mcp.exe"',
'cp build/c/codebase-memory-mcp.exe '
'"$SMOKE_DIR/codebase-memory-mcp.payload.exe"',
+ 'CBM_CACHE_DIR="$(cygpath -m "$SMOKE_DIR/cache")" '
'SMOKE_TEMP_ROOT="$SMOKE_DIR" '
'scripts/smoke-test.sh "$SMOKE_DIR/codebase-memory-mcp.exe"',
)
diff --git a/tests/windows/mcp_stdio.py b/tests/windows/mcp_stdio.py
index 251cff8dd..055f8e069 100644
--- a/tests/windows/mcp_stdio.py
+++ b/tests/windows/mcp_stdio.py
@@ -45,7 +45,8 @@ class McpServer:
[self.binary],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=self.env, cwd=self.cwd, bufsize=0)
- threading.Thread(target=self._drain_stderr, daemon=True).start()
+ self._stderr_thread = threading.Thread(target=self._drain_stderr, daemon=True)
+ self._stderr_thread.start()
def _drain_stderr(self):
try:
@@ -80,7 +81,10 @@ class McpServer:
raise McpError("read error: %r" % result["exc"])
line = result.get("line", b"")
if not line:
- raise McpError("EOF / server closed stdout")
+ self._stderr_thread.join(timeout=1)
+ stderr = self.stderr_text().strip()
+ detail = ": %s" % stderr[-1200:] if stderr else ""
+ raise McpError("EOF / server closed stdout%s" % detail)
# strict: an invalid-UTF-8 JSON-RPC response is itself a failure.
return json.loads(line.decode("utf-8", "strict"))