@@ -155,12 +155,12 @@ struct cbm_watcher {
155155#define INDEX_FAIL_SUSTAINED 10
156156
157157/* Success cooldown (#2835): after a successful re-index the next poll waits
158- * at least INDEX_COOLDOWN_FACTOR x the index's own duration (measured from the
159- * index start) , so the watcher spends at most ~1/K of wall time indexing one
160- * project — a 5-minute rebuild idles ~10 minutes before the next . Sub-second
158+ * at least INDEX_COOLDOWN_FACTOR x the index's own duration, counted from when
159+ * the index finished , so the watcher spends at most ~1/(K+1) of wall time
160+ * indexing one project — a 5-minute rebuild idles 15 minutes. Sub-second
161161 * indexes stay at the plain cadence. The ceiling bounds staleness after one
162- * pathological run; it is NOT INDEX_FAIL_CEILING_MS (5 min), which would cap a
163- * >100 s rebuild's cooldown below K x elapsed and restart it back-to-back . */
162+ * pathological run; it is NOT INDEX_FAIL_CEILING_MS (5 min), which would cut
163+ * the cooldown of any rebuild over 100 s below K x its duration . */
164164#define INDEX_COOLDOWN_FACTOR 3
165165#define INDEX_COOLDOWN_CEILING_MS 1800000 /* 30 min */
166166
@@ -1717,16 +1717,18 @@ static void poll_project(const char *key, void *val, void *ud) {
17171717 }
17181718 cbm_log_info ("watcher.changed" , "project" , s -> project_name , "strategy" ,
17191719 s -> is_git ? "git" : "tree" );
1720- int delay_ms = -1 ; /* < 0: use the failure-backoff cadence below */
1720+ int delay_ms = -1 ; /* < 0: use the failure-backoff cadence below */
1721+ int64_t anchor_ns = ctx -> now ; /* success re-anchors to when the index finished */
17211722 if (ctx -> w -> index_fn ) {
17221723 int64_t index_start = now_ns ();
17231724 int rc = ctx -> w -> index_fn (s -> project_name , s -> root_path , ctx -> w -> user_data );
17241725 if (rc == 0 ) {
17251726 ctx -> reindexed ++ ;
17261727 s -> index_failures = 0 ;
17271728 commit_baselines (ctx -> w , s );
1729+ anchor_ns = now_ns ();
17281730 delay_ms =
1729- cbm_watcher_success_delay_ms (s -> interval_ms , (now_ns () - index_start ) / US_PER_MS );
1731+ cbm_watcher_success_delay_ms (s -> interval_ms , (anchor_ns - index_start ) / US_PER_MS );
17301732 if (delay_ms > s -> interval_ms ) {
17311733 cbm_log_info ("watcher.cooldown" , "project" , s -> project_name , "delay_ms" ,
17321734 itoa_buf (delay_ms ));
@@ -1758,7 +1760,7 @@ static void poll_project(const char *key, void *val, void *ud) {
17581760 if (delay_ms < 0 ) {
17591761 delay_ms = cbm_watcher_index_backoff_ms (s -> interval_ms , s -> index_failures );
17601762 }
1761- s -> next_poll_ns = ctx -> now + ((int64_t )delay_ms * US_PER_MS );
1763+ s -> next_poll_ns = anchor_ns + ((int64_t )delay_ms * US_PER_MS );
17621764}
17631765
17641766/* Callback to snapshot project state pointers into an array. */
0 commit comments