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: address review feedback on artifact export error surfacing
Matt Van Horn44d517451148
diff --git a/src/pipeline/artifact.c b/src/pipeline/artifact.cindex a9ea1a72f..720c9d237 100644--- a/src/pipeline/artifact.c+++ b/src/pipeline/artifact.c@@ -36,6 +36,9 @@ enum {#include <sys/stat.h>#include <time.h>#include <unistd.h>+#ifdef _WIN32+#include <windows.h>+#endif/* ── Helpers ──────────────────────────────────────────────────────── */@@ -180,15 +183,21 @@ static int write_file_atomic(const char *path, const char *data, size_t len,}#ifdef _WIN32- /* C rename() does not reliably replace an existing destination on Windows. */- cbm_unlink(path);-#endif+ /* MoveFileEx replace approach suggested by @Ayush7Ranjan in #492. */+ if (!MoveFileExA(tmp, path, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) {+ DWORD saved_error = GetLastError();+ cbm_unlink(tmp);+ file_error_set(out_err, "rename_temp", (int)saved_error);+ return CBM_NOT_FOUND;+ }+#elseif (rename(tmp, path) != 0) {int saved_errno = errno;cbm_unlink(tmp);file_error_set(out_err, "rename_temp", saved_errno);return CBM_NOT_FOUND;}+#endifreturn 0;}diff --git a/src/pipeline/artifact.h b/src/pipeline/artifact.hindex 62d5fab55..3c1a90e28 100644--- a/src/pipeline/artifact.h+++ b/src/pipeline/artifact.h@@ -32,6 +32,10 @@ enum {int cbm_artifact_export(const char *db_path, const char *repo_path, const char *project_name,int quality);+/* Get details for the most recent export failure on this thread.+ * Returns NULL if no export error is recorded. */+const char *cbm_artifact_export_last_error(void);+/* Import artifact from .codebase-memory/graph.db.zst to cache_db_path.* Decompresses, runs integrity check, recreates indexes.* Returns 0 on success, -1 on error. */diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.cindex ef5e81c5d..a6dd8de10 100644--- a/src/pipeline/pipeline.c+++ b/src/pipeline/pipeline.c@@ -46,8 +46,6 @@ static inline void *intptr_to_ptr(intptr_t v) {return p;}-const char *cbm_artifact_export_last_error(void);-/* ── Global index lock ─────────────────────────────────────────── *//* Prevents concurrent pipeline runs on the same DB file.* Atomic spinlock: 0 = free, 1 = locked. */@@ -853,6 +851,7 @@ static int dump_and_persist_hashes(cbm_pipeline_t *p, const cbm_file_info_t *filif (arc != 0) {const char *err = cbm_artifact_export_last_error();cbm_log_error("pipeline.err", "phase", "artifact_export", "err", err ? err : "unknown");+ /* A failed persistence export intentionally fails the run; this used to be ignored. */return arc;}}diff --git a/tests/test_artifact.c b/tests/test_artifact.cindex 8d28c2507..4dcffe0de 100644--- a/tests/test_artifact.c+++ b/tests/test_artifact.c@@ -21,8 +21,6 @@ enum { ART_TEST_LOG_BUF = 32768 };static char g_log_capture[ART_TEST_LOG_BUF];static CBMLogLevel g_prev_log_level;-const char *cbm_artifact_export_last_error(void);-static void setup_artifact_test(void) {snprintf(g_tmpdir, sizeof(g_tmpdir), "%s/cbm_test_artifact_XXXXXX", cbm_tmpdir());cbm_mkdtemp(g_tmpdir);