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: address QA round 3

Shane McCarron086422020f5f
diff --git a/src/watcher/watcher.h b/src/watcher/watcher.h
index f6a4df2dc..013e1356a 100644
--- a/src/watcher/watcher.h
+++ b/src/watcher/watcher.h
@@ -98,10 +98,13 @@ int cbm_watcher_watch_count(cbm_watcher_t *w);
*
* Memory visibility: this reads under projects_lock, but poll_project WRITES
* the counter outside that lock — it runs against a state snapshot taken
- * while the lock was held, which is the same discipline every other
- * per-project field in this struct already follows. Reading concurrently with
- * a live poll is therefore formally a data race and may observe a stale
- * value; it is a diagnostic and test accessor, not a synchronisation point.
+ * while the lock was held, which is the same discipline the other
+ * poll-mutated fields here already follow (last_head, last_dirty_sig,
+ * interval_ms, next_poll_ns, missing_root_count). It is NOT the discipline of
+ * every field: active_git is serialized by projects_lock and registered is an
+ * atomic_bool. Reading concurrently with a live poll is therefore formally a
+ * data race and may observe a stale value; it is a diagnostic and test
+ * accessor, not a synchronisation point.
* Single-threaded callers (the tests, and any caller between poll cycles)
* always see the current value. Do not build scheduling decisions on it
* without first giving the counter atomic accessors. */
@@ -112,9 +115,17 @@ int cbm_watcher_poll_interval_ms(int file_count);
/* Return the delay (ms) before the next index attempt for a project with
* `consecutive_failures` consecutive hard index failures. Zero failures
- * yields `interval_ms` unchanged; each further failure doubles the delay up
- * to a fixed ceiling, so a permanently failing project stops re-forking a
- * worker at the poll cadence without ever being abandoned.
+ * yields `interval_ms` unchanged; each further failure doubles the delay, so
+ * a permanently failing project stops re-forking a worker at the poll cadence
+ * without ever being abandoned.
+ *
+ * Doubling stops at a fixed shift cap, so the delay plateaus at
+ * `interval_ms << INDEX_FAIL_SHIFT_MAX` — which is the ceiling only when
+ * `interval_ms` is large enough to reach it (>= 4688 ms for the current cap
+ * and ceiling). Below that the plateau sits strictly under the ceiling. Every
+ * interval this watcher generates is >= POLL_BASE_MS, so in practice the
+ * ceiling is always reached; the distinction is stated because this is an
+ * exported function and a caller may pass a smaller interval.
*
* The result is clamped at BOTH ends: never above the ceiling, and never
* below `interval_ms`, so backing off can only ever delay the next attempt,
diff --git a/tests/test_watcher.c b/tests/test_watcher.c
index d405e3005..4b6e874b0 100644
--- a/tests/test_watcher.c
+++ b/tests/test_watcher.c
@@ -1874,13 +1874,27 @@ TEST(watcher_index_failure_streak_increments_and_resets_issue2015) {
PASS();
}
-/* The delay WIRE-UP (#2015): a hard failure must actually push the project's
- * next poll out, so a permanently failing project stops re-forking a worker
- * on every cycle. That is this PR's headline behaviour and it is observable
- * without a clock, by simply NOT calling cbm_watcher_touch between polls:
- * touch zeroes next_poll_ns, so a wire-up that never sets a deadline leaves
- * it at 0 and the callback fires on every poll. What still needs a clock is
- * only the delay's MAGNITUDE, not whether gating happens at all. */
+/* The delay WIRE-UP (#2015): a hard failure must leave SOME deadline behind,
+ * so the failing project is not re-polled on the very next cycle. Observable
+ * without a clock by simply not calling cbm_watcher_touch between polls —
+ * touch zeroes next_poll_ns, so a wire-up that never assigns one leaves it at
+ * 0 and the callback fires on every poll.
+ *
+ * Be precise about what this does NOT prove, because it is less than it looks.
+ * The code before this change also assigned a deadline here (the plain
+ * adaptive interval), so this test passes against the unfixed tree: it is a
+ * regression guard on the assignment existing, NOT a demonstration of the
+ * backoff.
+ *
+ * Measured, not assumed: replacing the backoff call with the pre-change
+ * `ctx->now + interval_ms * US_PER_MS` leaves this whole suite green at 82/82.
+ * No test in this file fails when the behavioural change is removed — the
+ * index_backoff_* tests still pass because they exercise the pure function
+ * directly, and the streak tests still pass because the counter is unaffected.
+ * What distinguishes backed-off from plain cadence is the delay's MAGNITUDE,
+ * and observing that needs a controllable clock the watcher does not have, or
+ * a further accessor exposing next_poll_ns. Both were judged out of scope; the
+ * gap is recorded here rather than papered over. */
TEST(watcher_index_failure_backoff_gates_repolling_issue2015) {
char tmpdir[256];
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cbm_watcher_gate_XXXXXX");