Skip to content

Commit a54ea95

Browse files
committed
fix(windows): ship one binary — remove the launcher stub flagged as a dropper
Windows shipped a PAIR: a small permanent launcher (codebase-memory-mcp.exe) plus the real product binary (codebase-memory-mcp.payload.exe). The launcher existed for exactly one reason — a running .exe cannot replace its own image on Windows, so an in-process self-update needs a second resident binary to do the swap. That stub is statically indistinguishable from a dropper: a small, unsigned, zero-prevalence PE whose whole job is verify-and-execute another binary. Defender's ML scored it Trojan:Win32/Wacatac.B!ml and blocked the v0.9.1-rc.1 release at the VirusTotal gate. It is not fixable in our code on x64 — bcrypt-free, stripped, VERSIONINFO'd, minimal-resource and even resource-FREE builds on CI's own MSYS2 CLANG64 toolchain were all flagged, while the product binary scans clean on every platform. So remove the stub and move self-update OUT of the process into install.ps1, which runs while cbm is NOT running: Windows' image lock only blocks a process from replacing ITSELF. now prints the exact PowerShell command (with the Unblock-File hint for Mark-of-the-Web); install.ps1 is idempotent, so re-running it IS the update — it stops the daemon, renames the running binary aside (the one mutation Windows permits on a running image), publishes the new one, and sweeps retired copies. Windows now matches Linux and macOS: ONE binary per platform. * packaging, install.ps1, npm and PyPI wrappers all carry a single binary * the launcher/payload ABI contract and ~2500 lines of stub state machinery are deleted * every daemon start, CLI call and hook fire loses a process spawn, a named pipe handshake and an stdio relay * test_windows_bundle_contract.sh is rewritten as an INVERTED contract: it now asserts no shipped surface can reintroduce a launcher/payload pair, and that install.ps1 retires the running binary before publishing Verified: VirusTotal 0/67 on the packaged binary and 0/58 on install.ps1 (no certificate involved); macOS and Linux full suites green; Windows guards all green including the new update-handoff contract; npm 10/10; PyPI 3/3. Signed-off-by: Martin Vogel <[email protected]>
1 parent d90986b commit a54ea95

33 files changed

Lines changed: 968 additions & 10975 deletions

‎.github/workflows/_smoke.yml‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,18 @@ jobs:
206206
mkdir -p "$ARTIFACT_DIR"
207207
unzip -o "codebase-memory-mcp${SUFFIX}-windows-${ARCH}.zip" -d "$ARTIFACT_DIR"
208208
test -s "$ARTIFACT_DIR/codebase-memory-mcp.exe"
209-
test -s "$ARTIFACT_DIR/codebase-memory-mcp.payload.exe"
210-
# Pre-flight both images from a profile-rooted directory: the shared
211-
# runner workspace is deliberately not a valid launcher bundle root.
209+
# ONE binary per platform: a payload sibling would mean the
210+
# AV-flagged launcher stub came back.
211+
test ! -e "$ARTIFACT_DIR/codebase-memory-mcp.payload.exe"
212+
# Pre-flight the image from a profile-rooted directory: the shared
213+
# runner workspace is deliberately not a valid install root.
212214
PROFILE_ROOT="$(cygpath -u "$USERPROFILE")"
213215
LAUNCH_DIR="$(mktemp -d "$PROFILE_ROOT/cbm-release-version.XXXXXX")"
214216
# Best-effort cleanup with one retry: Windows holds the just-exited
215217
# image's file busy for ~100ms (section teardown / first-touch AV),
216218
# and a temp dir on an ephemeral runner must never fail the job.
217219
trap 'rm -rf "$LAUNCH_DIR" 2>/dev/null || { sleep 2; rm -rf "$LAUNCH_DIR" 2>/dev/null || true; }' EXIT
218-
cp "$ARTIFACT_DIR/codebase-memory-mcp.exe" \
219-
"$ARTIFACT_DIR/codebase-memory-mcp.payload.exe" "$LAUNCH_DIR/"
220-
"$LAUNCH_DIR/codebase-memory-mcp.payload.exe" --version
220+
cp "$ARTIFACT_DIR/codebase-memory-mcp.exe" "$LAUNCH_DIR/"
221221
"$LAUNCH_DIR/codebase-memory-mcp.exe" --version
222222
223223
# ONE harness for every venue: the same script win.sh smoke-install and
@@ -241,13 +241,11 @@ jobs:
241241
run: |
242242
ARTIFACT_DIR="$(cygpath -u "$RUNNER_TEMP")/cbm-artifact"
243243
scripts/security-strings.sh "$ARTIFACT_DIR/codebase-memory-mcp.exe"
244-
scripts/security-strings.sh "$ARTIFACT_DIR/codebase-memory-mcp.payload.exe"
245244
PROFILE_ROOT="$(cygpath -u "$USERPROFILE")"
246245
SECURITY_DIR="$(mktemp -d "$PROFILE_ROOT/cbm-release-security.XXXXXX")"
247246
# Best-effort cleanup with one retry (see the version preflight).
248247
trap 'rm -rf "$SECURITY_DIR" 2>/dev/null || { sleep 2; rm -rf "$SECURITY_DIR" 2>/dev/null || true; }' EXIT
249-
cp "$ARTIFACT_DIR/codebase-memory-mcp.exe" \
250-
"$ARTIFACT_DIR/codebase-memory-mcp.payload.exe" "$SECURITY_DIR/"
248+
cp "$ARTIFACT_DIR/codebase-memory-mcp.exe" "$SECURITY_DIR/"
251249
TMPDIR="$SECURITY_DIR" \
252250
scripts/security-install.sh "$SECURITY_DIR/codebase-memory-mcp.exe"
253251
@@ -256,7 +254,7 @@ jobs:
256254
run: |
257255
& "C:\Program Files\Windows Defender\MpCmdRun.exe" -SignatureUpdate 2>$null
258256
$artifactDir = Join-Path $env:RUNNER_TEMP "cbm-artifact"
259-
foreach ($binary in @("codebase-memory-mcp.exe", "codebase-memory-mcp.payload.exe")) {
257+
foreach ($binary in @("codebase-memory-mcp.exe")) {
260258
$result = & "C:\Program Files\Windows Defender\MpCmdRun.exe" -Scan -ScanType 3 -File (Join-Path $artifactDir $binary) -DisableRemediation
261259
$code = $LASTEXITCODE
262260
Write-Host $result

‎Makefile.cbm‎

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,7 @@ GIT_SRCS = src/git/git_context.c
311311
CLI_SRCS = src/cli/cli.c src/cli/progress_sink.c src/cli/hook_augment.c \
312312
src/cli/agent_clients.c src/cli/agent_profiles.c \
313313
src/cli/config_json_like.c src/cli/config_toml_edit.c src/cli/config_yaml_edit.c \
314-
src/cli/config_text_edit.c src/cli/activation_transaction.c \
315-
src/cli/windows_launcher_state.c
316-
317-
# Tiny permanent Windows launcher. It deliberately links only the stable
318-
# launcher-state module and Windows SDK libraries, never the parser/indexer.
319-
WINDOWS_LAUNCHER_SRC = src/launcher/windows_launcher.c
314+
src/cli/config_text_edit.c src/cli/activation_transaction.c
320315

321316
# UI module (graph visualization)
322317
UI_SRCS = \
@@ -490,8 +485,7 @@ TEST_TRACES_SRCS = tests/test_traces.c
490485
TEST_CLI_SRCS = tests/test_cli.c tests/test_agent_clients.c tests/test_agent_profiles.c \
491486
tests/test_config_json_like.c \
492487
tests/test_config_toml_edit.c tests/test_config_yaml_edit.c tests/test_config_text_edit.c \
493-
tests/test_activation_transaction.c \
494-
tests/test_windows_launcher_state.c
488+
tests/test_activation_transaction.c
495489

496490
TEST_MEM_SRCS = tests/test_mem.c
497491

@@ -601,7 +595,7 @@ PP_OBJ_TSAN = $(BUILD_DIR)/tsan_preprocessor.o
601595

602596
# ── Targets ──────────────────────────────────────────────────────
603597

604-
.PHONY: test test-par test-repro test-foundation test-tsan test-daemon-smoke cbm cbm-launcher cbm-with-ui frontend embed clean-c lint lint-tidy lint-cppcheck lint-format security
598+
.PHONY: test test-par test-repro test-foundation test-tsan test-daemon-smoke cbm cbm-with-ui frontend embed clean-c lint lint-tidy lint-cppcheck lint-format security
605599

606600
$(BUILD_DIR):
607601
mkdir -p $(BUILD_DIR)
@@ -841,39 +835,16 @@ OBJS_VENDORED_PROD = $(MIMALLOC_OBJ_PROD) $(SQLITE3_OBJ_PROD) $(TRE_OBJ_PROD) $(
841835

842836
MAIN_SRC = src/main.c
843837

844-
WINDOWS_LAUNCHER_TARGET :=
845-
ifeq ($(IS_MINGW),yes)
846-
WINDOWS_LAUNCHER_TARGET := $(BUILD_DIR)/codebase-memory-mcp-launcher.exe
847-
endif
848-
849-
# Keep the explicit .exe target even on non-Windows hosts: packaging contracts
850-
# and native-Windows invocations share this single artifact name. A non-Windows
851-
# direct invocation builds a diagnostic stub and is not part of `cbm`.
852-
$(BUILD_DIR)/codebase-memory-mcp-launcher.exe: $(WINDOWS_LAUNCHER_SRC) src/cli/windows_launcher_state.c src/cli/windows_launcher_state.h | $(BUILD_DIR)
853-
$(CC) $(CFLAGS_PROD) -o $@ \
854-
$(WINDOWS_LAUNCHER_SRC) src/cli/windows_launcher_state.c \
855-
$(if $(filter yes,$(IS_MINGW)),-municode -lbcrypt $(WIN32_LIBS),)
856-
857-
# Native-Windows compatibility fixture: its launcher ABI intentionally does
858-
# not fit the production payload's default [1,1] range. It is never packaged.
859-
$(BUILD_DIR)/codebase-memory-mcp-launcher-abi2.exe: $(WINDOWS_LAUNCHER_SRC) src/cli/windows_launcher_state.c src/cli/windows_launcher_state.h | $(BUILD_DIR)
860-
$(CC) $(CFLAGS_PROD) -DCBM_WINDOWS_LAUNCHER_ABI_CURRENT=2 -o $@ \
861-
$(WINDOWS_LAUNCHER_SRC) src/cli/windows_launcher_state.c \
862-
$(if $(filter yes,$(IS_MINGW)),-municode -lbcrypt $(WIN32_LIBS),)
863-
864838
$(BUILD_DIR)/codebase-memory-mcp: $(MAIN_SRC) $(PROD_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) $(OBJS_VENDORED_PROD) | $(BUILD_DIR)
865839
$(CC) $(CFLAGS_PROD) -o $@ \
866840
$(MAIN_SRC) $(PROD_SRCS) \
867841
$(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) \
868842
$(OBJS_VENDORED_PROD) \
869843
$(LDFLAGS)
870844

871-
cbm: $(BUILD_DIR)/codebase-memory-mcp $(WINDOWS_LAUNCHER_TARGET)
845+
cbm: $(BUILD_DIR)/codebase-memory-mcp
872846
@echo "Built: $(BUILD_DIR)/codebase-memory-mcp"
873847

874-
cbm-launcher: $(BUILD_DIR)/codebase-memory-mcp-launcher.exe
875-
@echo "Built: $(BUILD_DIR)/codebase-memory-mcp-launcher.exe"
876-
877848
# ── Build with embedded UI (requires Node.js) ───────────────────
878849

879850
# Swap embedded_stub.c for the generated embedded_assets.c
@@ -889,7 +860,7 @@ frontend:
889860
embed: frontend
890861
scripts/embed-frontend.sh graph-ui/dist $(BUILD_DIR)/embedded
891862

892-
cbm-with-ui: embed $(OBJS_VENDORED_PROD) $(WINDOWS_LAUNCHER_TARGET)
863+
cbm-with-ui: embed $(OBJS_VENDORED_PROD)
893864
$(CC) $(CFLAGS_PROD) -o $(BUILD_DIR)/codebase-memory-mcp \
894865
$(MAIN_SRC) $(PROD_SRCS_WITH_ASSETS) \
895866
$(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) \
@@ -919,7 +890,7 @@ SYSROOT_FLAG = $(if $(SYSROOT),-isysroot $(SYSROOT),)
919890
LINT_SRCS = $(FOUNDATION_SRCS) $(STORE_SRCS) $(CYPHER_SRCS) $(MCP_SRCS) $(DAEMON_SRCS) \
920891
$(DISCOVER_SRCS) $(GRAPH_BUFFER_SRCS) $(PIPELINE_SRCS) $(SIMHASH_SRCS) $(SEMANTIC_SRCS) \
921892
$(TRACES_SRCS) $(WATCHER_SRCS) $(CLI_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) \
922-
$(ZSTD_SRCS) $(SQLITE_WRITER_SRC) $(MAIN_SRC) $(WINDOWS_LAUNCHER_SRC)
893+
$(ZSTD_SRCS) $(SQLITE_WRITER_SRC) $(MAIN_SRC)
923894
LINT_HDRS = $(wildcard src/**/*.h src/*.h $(CBM_DIR)/*.h)
924895
LINT_TEST_SRCS = $(ALL_TEST_SRCS)
925896

‎install.ps1‎

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ Add-Type -AssemblyName System.Net.Http
1414
$Repo = "DeusData/codebase-memory-mcp"
1515
$InstallDir = "$env:LOCALAPPDATA\Programs\codebase-memory-mcp"
1616
$BinName = "codebase-memory-mcp.exe"
17-
$PayloadName = "codebase-memory-mcp.payload.exe"
1817
$WindowsArchiveNames = @(
1918
$BinName,
20-
$PayloadName,
2119
"LICENSE",
2220
"install.ps1",
2321
"THIRD_PARTY_NOTICES.md"
@@ -237,32 +235,28 @@ try {
237235
exit 1
238236
}
239237

240-
# Extract the complete, validated bundle. The portable launcher owns the
241-
# managed install transaction and contains its adjacent payload.
238+
# Extract the validated bundle. Windows ships ONE binary, exactly like Linux
239+
# and macOS; this script is what replaces it, because a running executable
240+
# cannot replace itself on Windows. Re-running this script IS the update.
242241
Write-Host "Extracting..."
243242
Expand-Archive -Path "$TmpDir\$Archive" -DestinationPath $TmpDir -Force
244243

245-
$DownloadedLauncher = Join-Path $TmpDir $BinName
246-
$DownloadedPayload = Join-Path $TmpDir $PayloadName
247-
if (-not (Test-Path -LiteralPath $DownloadedLauncher -PathType Leaf) -or
248-
-not (Test-Path -LiteralPath $DownloadedPayload -PathType Leaf)) {
249-
Write-Host "error: launcher or payload not found after extraction" -ForegroundColor Red
244+
$DownloadedBinary = Join-Path $TmpDir $BinName
245+
if (-not (Test-Path -LiteralPath $DownloadedBinary -PathType Leaf)) {
246+
Write-Host "error: $BinName not found after extraction" -ForegroundColor Red
250247
Remove-Item -Recurse -Force $TmpDir
251248
exit 1
252249
}
253-
$launcherItem = Get-Item -LiteralPath $DownloadedLauncher
254-
$payloadItem = Get-Item -LiteralPath $DownloadedPayload
255-
if (($launcherItem.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -or
256-
($payloadItem.Attributes -band [System.IO.FileAttributes]::ReparsePoint)) {
250+
$binaryItem = Get-Item -LiteralPath $DownloadedBinary
251+
if ($binaryItem.Attributes -band [System.IO.FileAttributes]::ReparsePoint) {
257252
Write-Host "error: refusing reparse-point executable in release archive" -ForegroundColor Red
258253
Remove-Item -Recurse -Force $TmpDir
259254
exit 1
260255
}
261256

262-
# Verify the complete launcher/payload path before it asks all coordinated CBM
263-
# processes to stop.
257+
# Prove the downloaded binary runs before touching an existing installation.
264258
try {
265-
$candidateVersion = & $DownloadedLauncher --version 2>&1
259+
$candidateVersion = & $DownloadedBinary --version 2>&1
266260
if ($LASTEXITCODE -ne 0) { throw "candidate exited with $LASTEXITCODE" }
267261
Write-Host "Verified candidate: $candidateVersion"
268262
} catch {
@@ -272,13 +266,36 @@ try {
272266
}
273267

274268
$Dest = Join-Path $InstallDir $BinName
269+
270+
# Retire the running installation before replacing it. Windows keeps an image
271+
# lock on a running .exe: the file cannot be overwritten, but it CAN be renamed
272+
# out of the way, which is what makes an in-place update possible from here.
273+
if (Test-Path -LiteralPath $Dest -PathType Leaf) {
274+
try { & $Dest daemon stop 2>&1 | Out-Null } catch { }
275+
$retired = "$Dest.retired-$(Get-Date -Format yyyyMMddHHmmss)"
276+
$renamed = $false
277+
foreach ($attempt in 1..10) {
278+
try { Move-Item -LiteralPath $Dest -Destination $retired -Force -ErrorAction Stop; $renamed = $true; break }
279+
catch { Start-Sleep -Milliseconds 500 }
280+
}
281+
if (-not $renamed) {
282+
Write-Host "error: could not retire the existing $BinName — close all running" -ForegroundColor Red
283+
Write-Host " codebase-memory-mcp sessions and coding agents, then re-run." -ForegroundColor Red
284+
Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue
285+
exit 1
286+
}
287+
# A retired image stays locked until its last process exits; delete it when
288+
# we can, and leave it for the next run when we cannot. Never fail here.
289+
Remove-Item -LiteralPath $retired -Force -ErrorAction SilentlyContinue
290+
}
291+
Get-ChildItem -LiteralPath $InstallDir -Filter "$BinName.retired-*" -ErrorAction SilentlyContinue |
292+
ForEach-Object { Remove-Item -LiteralPath $_.FullName -Force -ErrorAction SilentlyContinue }
293+
275294
$InstallArgs = @("install", "-y", "--force", "--dir=$InstallDir")
276295
if ($SkipConfig) { $InstallArgs += "--skip-config" }
277-
# PowerShell's call operator waits for the launcher, which in turn contains the
278-
# install payload in its native job and relays the exact exit status.
279-
& $DownloadedLauncher @InstallArgs
296+
& $DownloadedBinary @InstallArgs
280297
if ($LASTEXITCODE -ne 0) {
281-
Write-Host "error: coordinated activation failed (exit code $LASTEXITCODE)" -ForegroundColor Red
298+
Write-Host "error: installation failed (exit code $LASTEXITCODE)" -ForegroundColor Red
282299
Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue
283300
exit 1
284301
}

‎pkg/npm/bin.js‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,19 @@ const fs = require('fs');
88
const { spawnSync } = require('child_process');
99

1010
const isWindows = process.platform === 'win32';
11-
const windowsLauncherName = 'codebase-memory-mcp.exe';
12-
// npm is a portable one-shot wrapper. On Windows the public .exe in the
13-
// release archive is the permanent launcher, so privately validate the
14-
// release pair, cache both files, and enter the native process through that
15-
// launcher. The adjacent payload remains the immutable cache readiness signal.
16-
const binName = isWindows ? 'codebase-memory-mcp.payload.exe' : 'codebase-memory-mcp';
11+
// npm is a portable one-shot wrapper. Every platform ships exactly ONE binary,
12+
// so the cached file is the executed file — there is no launcher pair to keep
13+
// in sync and no adjacent payload to validate.
14+
const binName = isWindows ? 'codebase-memory-mcp.exe' : 'codebase-memory-mcp';
1715
const binPath = path.join(__dirname, 'bin', binName);
18-
const launcherPath = path.join(__dirname, 'bin', windowsLauncherName);
19-
const executionPath = isWindows ? launcherPath : binPath;
16+
const executionPath = binPath;
2017
const cacheReady = () => {
21-
if (!fs.existsSync(binPath) || (isWindows && !fs.existsSync(launcherPath))) {
18+
if (!fs.existsSync(binPath)) {
2219
return false;
2320
}
2421
if (!isWindows) return true;
25-
// The launcher resolving --version through its adjacent payload validates
26-
// both halves of the immutable Windows cache pair.
27-
const probe = spawnSync(launcherPath, ['--version'], {
22+
// A cached Windows binary that cannot report its own version is not usable.
23+
const probe = spawnSync(binPath, ['--version'], {
2824
stdio: 'ignore',
2925
timeout: 15_000,
3026
windowsHide: true,
@@ -77,8 +73,8 @@ if (mutation) {
7773
process.stderr.write(
7874
`This npm Windows copy is portable. Use "${packageCommand}" for package ` +
7975
'maintenance (add -g for a global install), or run ' +
80-
'"codebase-memory-mcp install --yes" once to create ' +
81-
'a managed launcher with coordinated self-update/uninstall.\n',
76+
'"codebase-memory-mcp install --yes" once for a managed install with its ' +
77+
'own install.ps1 for updates.\n',
8278
);
8379
}
8480

0 commit comments

Comments
 (0)