Skip to content

Commit 0864220

Browse files
halindromeclaude
andcommitted
fix: address QA round 3
Documentation and claim accuracy only — no behavioural change. Two of the three findings are corrections to inaccurate statements the round-2 commit (61ccd90) introduced. The gating test's framing was overstated, and this time the overstatement was measured rather than argued. Replacing the backoff call with the pre-change `ctx->now + interval_ms * US_PER_MS` leaves the watcher suite green at 82/82: the index_backoff_* tests pass because they exercise the pure function directly, which the reverted scheduler no longer calls, and the streak tests pass because the counter is untouched. So no test in this suite fails when this change's behaviour is removed. The test now records that, with the figure, instead of claiming it demonstrates the backoff. It is a regression guard on a deadline being assigned at all — real, but narrower than round 2 said. Closing that gap needs either a controllable clock or a further accessor exposing next_poll_ns. Both were judged out of scope: a third exported symbol purely for testing, on a change already carrying two, is the API widening earlier rounds flagged. The gap is recorded in the test, the PR description and the round-3 note rather than papered over. The memory-visibility comment claimed index_failures follows "the same discipline every other per-project field in this struct already follows". That is false: active_git is serialized by projects_lock and registered is an atomic_bool. Narrowed to the poll-mutated fields, which are now enumerated. The round-2 decision to document rather than lock still stands — the panel verified the underlying premise — but it was resting on an overbroad claim. watcher.h said the delay "doubles up to a fixed ceiling", which skips the shift cap: the delay plateaus at interval_ms << INDEX_FAIL_SHIFT_MAX, and that reaches the ceiling only for interval_ms >= 4688 ms. Every interval this watcher generates is >= POLL_BASE_MS so the ceiling is always reached in practice, but the function is exported and a caller may pass less. Refs DeusData#2015 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FbrM52pmB1m2SR1vRRoNnf Signed-off-by: Shane McCarron <[email protected]>
1 parent 61ccd90 commit 0864220

2 files changed

Lines changed: 39 additions & 14 deletions

File tree

‎src/watcher/watcher.h‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ int cbm_watcher_watch_count(cbm_watcher_t *w);
9898
*
9999
* Memory visibility: this reads under projects_lock, but poll_project WRITES
100100
* the counter outside that lock — it runs against a state snapshot taken
101-
* while the lock was held, which is the same discipline every other
102-
* per-project field in this struct already follows. Reading concurrently with
103-
* a live poll is therefore formally a data race and may observe a stale
104-
* value; it is a diagnostic and test accessor, not a synchronisation point.
101+
* while the lock was held, which is the same discipline the other
102+
* poll-mutated fields here already follow (last_head, last_dirty_sig,
103+
* interval_ms, next_poll_ns, missing_root_count). It is NOT the discipline of
104+
* every field: active_git is serialized by projects_lock and registered is an
105+
* atomic_bool. Reading concurrently with a live poll is therefore formally a
106+
* data race and may observe a stale value; it is a diagnostic and test
107+
* accessor, not a synchronisation point.
105108
* Single-threaded callers (the tests, and any caller between poll cycles)
106109
* always see the current value. Do not build scheduling decisions on it
107110
* without first giving the counter atomic accessors. */
@@ -112,9 +115,17 @@ int cbm_watcher_poll_interval_ms(int file_count);
112115

113116
/* Return the delay (ms) before the next index attempt for a project with
114117
* `consecutive_failures` consecutive hard index failures. Zero failures
115-
* yields `interval_ms` unchanged; each further failure doubles the delay up
116-
* to a fixed ceiling, so a permanently failing project stops re-forking a
117-
* worker at the poll cadence without ever being abandoned.
118+
* yields `interval_ms` unchanged; each further failure doubles the delay, so
119+
* a permanently failing project stops re-forking a worker at the poll cadence
120+
* without ever being abandoned.
121+
*
122+
* Doubling stops at a fixed shift cap, so the delay plateaus at
123+
* `interval_ms << INDEX_FAIL_SHIFT_MAX` — which is the ceiling only when
124+
* `interval_ms` is large enough to reach it (>= 4688 ms for the current cap
125+
* and ceiling). Below that the plateau sits strictly under the ceiling. Every
126+
* interval this watcher generates is >= POLL_BASE_MS, so in practice the
127+
* ceiling is always reached; the distinction is stated because this is an
128+
* exported function and a caller may pass a smaller interval.
118129
*
119130
* The result is clamped at BOTH ends: never above the ceiling, and never
120131
* below `interval_ms`, so backing off can only ever delay the next attempt,

‎tests/test_watcher.c‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,13 +1874,27 @@ TEST(watcher_index_failure_streak_increments_and_resets_issue2015) {
18741874
PASS();
18751875
}
18761876

1877-
/* The delay WIRE-UP (#2015): a hard failure must actually push the project's
1878-
* next poll out, so a permanently failing project stops re-forking a worker
1879-
* on every cycle. That is this PR's headline behaviour and it is observable
1880-
* without a clock, by simply NOT calling cbm_watcher_touch between polls:
1881-
* touch zeroes next_poll_ns, so a wire-up that never sets a deadline leaves
1882-
* it at 0 and the callback fires on every poll. What still needs a clock is
1883-
* only the delay's MAGNITUDE, not whether gating happens at all. */
1877+
/* The delay WIRE-UP (#2015): a hard failure must leave SOME deadline behind,
1878+
* so the failing project is not re-polled on the very next cycle. Observable
1879+
* without a clock by simply not calling cbm_watcher_touch between polls —
1880+
* touch zeroes next_poll_ns, so a wire-up that never assigns one leaves it at
1881+
* 0 and the callback fires on every poll.
1882+
*
1883+
* Be precise about what this does NOT prove, because it is less than it looks.
1884+
* The code before this change also assigned a deadline here (the plain
1885+
* adaptive interval), so this test passes against the unfixed tree: it is a
1886+
* regression guard on the assignment existing, NOT a demonstration of the
1887+
* backoff.
1888+
*
1889+
* Measured, not assumed: replacing the backoff call with the pre-change
1890+
* `ctx->now + interval_ms * US_PER_MS` leaves this whole suite green at 82/82.
1891+
* No test in this file fails when the behavioural change is removed — the
1892+
* index_backoff_* tests still pass because they exercise the pure function
1893+
* directly, and the streak tests still pass because the counter is unaffected.
1894+
* What distinguishes backed-off from plain cadence is the delay's MAGNITUDE,
1895+
* and observing that needs a controllable clock the watcher does not have, or
1896+
* a further accessor exposing next_poll_ns. Both were judged out of scope; the
1897+
* gap is recorded here rather than papered over. */
18841898
TEST(watcher_index_failure_backoff_gates_repolling_issue2015) {
18851899
char tmpdir[256];
18861900
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cbm_watcher_gate_XXXXXX");

0 commit comments

Comments
 (0)