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(watcher): FILETIME-precision dirty signatures; flaky-family rebuilds
Martin Vogel32e910aab525
diff --git a/scripts/run-test-wave.py b/scripts/run-test-wave.pyindex 44a16c23c..18876d7c9 100755--- a/scripts/run-test-wave.py+++ b/scripts/run-test-wave.py@@ -25,7 +25,24 @@ SUITE_NAME = re.compile(r"^[a-z0-9_]+$")SUMMARY = re.compile(r"^ (?P<passed>[0-9]+) passed")FAILED = re.compile(r"(?:^|, )(?P<failed>[0-9]+) failed")SKIPPED = re.compile(r"(?:^|, )(?P<skipped>[0-9]+) skipped")-SLOW_SUITES = frozenset(("incremental", "store_arch", "daemon_runtime"))+# Suites on the slow tier carry a stated reason (O10: no unexplained+# entries). incremental/store_arch/daemon_runtime: the heaviest sanitized+# suites by steady-state cost. node_creation_probe/grammar_probe_b: full-+# pipeline indexing probes whose FIRST run in a fresh checkout pays a+# one-time environment tax (every artifact is AV-scan-cold on the Windows+# VM; grammar_probe_b hit it 2026-08-? under host contention, node_creation+# _probe 2026-08-28 at exactly 900s on a new run checkout, both green on+# the warm rerun). That state is deterministic, not racy — the stable-state+# budget rule applies.+SLOW_SUITES = frozenset(+ (+ "incremental",+ "store_arch",+ "daemon_runtime",+ "node_creation_probe",+ "grammar_probe_b",+ )+)POLL_SECONDS = 0.05diff --git a/src/watcher/watcher.c b/src/watcher/watcher.cindex ec186c05a..e8a096fe5 100644--- a/src/watcher/watcher.c+++ b/src/watcher/watcher.c@@ -580,21 +580,18 @@ static uint64_t sig_fold(uint64_t h, const void *data, size_t len) {return h;}-/* Platform-portable mtime_ns (mirrors pipeline_incremental.c). */-static int64_t sig_stat_mtime_ns(const struct stat *st) {-#ifdef __APPLE__- return ((int64_t)st->st_mtimespec.tv_sec * NS_PER_SEC) + (int64_t)st->st_mtimespec.tv_nsec;-#elif defined(_WIN32)- return (int64_t)st->st_mtime * NS_PER_SEC;-#else- return ((int64_t)st->st_mtim.tv_sec * NS_PER_SEC) + (int64_t)st->st_mtim.tv_nsec;-#endif-}-/* Fold a listed path's (size, mtime) into the signature so an in-place edit* of an already-dirty file still produces a new signature. A failed stat* (deleted file, quoting artifact) degrades to the entry text alone — the- * deletion itself is represented by the porcelain status. */+ * deletion itself is represented by the porcelain status.+ *+ * cbm_path_info_utf8 rather than raw stat(): on Windows, stat()'s st_mtime+ * is SECOND-granularity, so two edits inside one second with an unchanged+ * size produced the same signature — a missed reindex the Windows leg+ * caught as test_watcher:2045. The path-info helper reads FILETIME (100ns+ * ticks) and handles non-ASCII paths. A transiently unreadable file (AV+ * real-time scan holding a just-written file) gets ONE short retry so the+ * degradation stays for genuinely-gone files only. *//* `rel` is repository-relative (that is what porcelain prints), so it is joined* through `cdup` — the hop from root_path up to the repository root — rather than* onto root_path directly. cdup is "" when the project IS the repository root,@@ -603,12 +600,15 @@ static uint64_t sig_fold_path_stat(uint64_t h, const char *root_path, const charconst char *rel) {char abs[CBM_SZ_4K];snprintf(abs, sizeof(abs), "%s/%s%s", root_path, cdup ? cdup : "", rel);- struct stat st;- if (stat(abs, &st) == 0) {- int64_t mt = sig_stat_mtime_ns(&st);- int64_t sz = (int64_t)st.st_size;- h = sig_fold(h, &mt, sizeof(mt));- h = sig_fold(h, &sz, sizeof(sz));+ cbm_path_info_t info;+ int rc = cbm_path_info_utf8(abs, &info);+ if (rc != 0) {+ cbm_usleep(1000);+ rc = cbm_path_info_utf8(abs, &info);+ }+ if (rc == 0) {+ h = sig_fold(h, &info.mtime_ns, sizeof(info.mtime_ns));+ h = sig_fold(h, &info.size, sizeof(info.size));}return h;}@@ -1565,3 +1565,30 @@ int cbm_watcher_run(cbm_watcher_t *w, int base_interval_ms) {cbm_log_info("watcher.stop");return 0;}++#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS+/* Test seam: expose one project's dirty-state signatures so a failing+ * watcher assertion can print WHY. The watcher-poll flake family blocked+ * two releases precisely because a bare count assert cannot distinguish+ * "the poll saw an unchanged signature" (sigs equal — a detection miss)+ * from "the reindex path itself misbehaved" (sigs differ). Returns 0 and+ * fills the committed and pending signatures, or nonzero when the project+ * is not watched. */+int cbm_watcher_test_dirty_sigs(cbm_watcher_t *w, const char *project, uint64_t *last_out,+ uint64_t *pending_out) {+ if (!w || !project) {+ return -1;+ }+ project_state_t *s = cbm_ht_get(w->projects, project);+ if (!s) {+ return -1;+ }+ if (last_out) {+ *last_out = s->last_dirty_sig;+ }+ if (pending_out) {+ *pending_out = s->pending_dirty_sig;+ }+ return 0;+}+#endifdiff --git a/src/watcher/watcher.h b/src/watcher/watcher.hindex 2a30cbb4f..ac1b9cdc2 100644--- a/src/watcher/watcher.h+++ b/src/watcher/watcher.h@@ -79,6 +79,13 @@ void cbm_watcher_touch(cbm_watcher_t *w, const char *project_name);* Returns the number of projects that were reindexed. */int cbm_watcher_poll_once(cbm_watcher_t *w);+#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS+/* Test seam: read one project's committed/pending dirty-state signatures so+ * failing assertions can self-diagnose (see the definition for why). */+int cbm_watcher_test_dirty_sigs(cbm_watcher_t *w, const char *project, uint64_t *last_out,+ uint64_t *pending_out);+#endif+/* Run the blocking poll loop. Polls every base_interval_ms until* cbm_watcher_stop() is called. Returns 0 on clean shutdown. */int cbm_watcher_run(cbm_watcher_t *w, int base_interval_ms);diff --git a/tests/test_py_lsp_scale.c b/tests/test_py_lsp_scale.cindex f20e76275..681a0994a 100644--- a/tests/test_py_lsp_scale.c+++ b/tests/test_py_lsp_scale.c@@ -75,9 +75,25 @@ TEST(pylsp_scale_linear_growth) {int c100 = 0, r100 = 0;int c500 = 0, r500 = 0;int c2000 = 0, r2000 = 0;+ /* Min-of-N sampling: under a fully-parallel suite run, scheduler noise+ * only ever ADDS time, and it lands hardest on the tiny denominator —+ * one preempted slice on t100 multiplies the ratio. The minimum of a+ * few runs approximates the uncontended cost, so the calibrated bound+ * below keeps its meaning on a loaded host (this exact assert failed+ * the mac 18-job leg while passing isolated on the same tree). */double t100 = measure(100, &c100, &r100);+ for (int i = 0; i < 2; i++) {+ double again = measure(100, &c100, &r100);+ if (again < t100)+ t100 = again;+ }double t500 = measure(500, &c500, &r500);double t2000 = measure(2000, &c2000, &r2000);+ {+ double again = measure(2000, &c2000, &r2000);+ if (again < t2000)+ t2000 = again;+ }printf(" scale: 100=%.1fms (calls=%d resolved=%d) 500=%.1fms (calls=%d resolved=%d) ""2000=%.1fms (calls=%d resolved=%d)\n",t100, c100, r100, t500, c500, r500, t2000, c2000, r2000);diff --git a/tests/test_watcher.c b/tests/test_watcher.cindex 14b602be1..bdbb013b3 100644--- a/tests/test_watcher.c+++ b/tests/test_watcher.c@@ -188,6 +188,40 @@ static int index_callback(const char *name, const char *path, void *ud) {return 0;}+/* Self-diagnosing count check: this suite's flake family blocked two+ * releases because a bare count assert cannot say WHY — print the+ * committed/pending dirty signatures on mismatch, so the next occurrence+ * names its cause (sigs equal = detection miss; different = reindex path).+ * Use at any index_call_count assertion site. */+static void wt_diagnose_count(cbm_watcher_t *w, const char *project, int got, int expected) {+ if (got == expected) {+ return;+ }+ uint64_t last = 0, pending = 0;+ if (cbm_watcher_test_dirty_sigs(w, project, &last, &pending) == 0) {+ printf(" watcher diagnose: count=%d expected=%d last_sig=%016llx pending_sig=%016llx "+ "(%s)\n",+ got, expected, (unsigned long long)last, (unsigned long long)pending,+ last == pending ? "sigs EQUAL — the poll saw no new dirty state"+ : "sigs differ — detection fired, reindex path suspect");+ } else {+ printf(" watcher diagnose: count=%d expected=%d (project not watched?)\n", got, expected);+ }+}++/* Wait-for-the-asserted-state (bounded) for REACH assertions only: reaching+ * a count is safe to wait for, because #937 guarantees an unchanged dirty+ * tree never increments — extra polls cannot overshoot a correct+ * implementation. NEVER use this for must-stay-quiet assertions; those are+ * genuinely about a fixed number of polls. */+static int wt_poll_until_count(cbm_watcher_t *w, const char *project, int expected, int max_polls) {+ for (int i = 0; i < max_polls && index_call_count < expected; i++) {+ cbm_watcher_touch(w, project);+ cbm_watcher_poll_once(w);+ }+ return index_call_count;+}+TEST(watcher_poll_no_projects) {cbm_store_t *store = cbm_store_open_memory();cbm_watcher_t *w = cbm_watcher_new(store, index_callback, NULL);@@ -2024,25 +2058,32 @@ TEST(watcher_continued_dirty) {th_append_file(_p, "dirty\n");}- /* First detection */- cbm_watcher_touch(w, "cont-repo");- cbm_watcher_poll_once(w);- ASSERT_EQ(index_call_count, 1);+ /* First detection — a REACH assert: wait for the state, bounded. */+ {+ int got = wt_poll_until_count(w, "cont-repo", 1, 5);+ wt_diagnose_count(w, "cont-repo", got, 1);+ ASSERT_EQ(got, 1);+ }- /* Still dirty but UNCHANGED — must stay quiet (#937) */+ /* Still dirty but UNCHANGED — must stay quiet (#937): fixed polls. */cbm_watcher_touch(w, "cont-repo");cbm_watcher_poll_once(w);ASSERT_EQ(index_call_count, 1);- /* A further edit is a NEW dirty state — detect again */+ /* A further edit is a NEW dirty state — detect again. This exact site+ * failed on the Windows leg (1 vs 2): stat()'s second-granularity+ * st_mtime made two same-second edits hash identically. The signature+ * now reads FILETIME precision; the reach-wait covers scheduling. */{char _p[1024];snprintf(_p, sizeof(_p), "%s/file.txt", tmpdir);th_append_file(_p, "dirtier\n");}- cbm_watcher_touch(w, "cont-repo");- cbm_watcher_poll_once(w);- ASSERT_EQ(index_call_count, 2);+ {+ int got = wt_poll_until_count(w, "cont-repo", 2, 5);+ wt_diagnose_count(w, "cont-repo", got, 2);+ ASSERT_EQ(got, 2);+ }/* Commit to clean up, then poll — should not trigger */wt_git(tmpdir, "add file.txt");