pub async fn sync_from_kv(store: &Arc<TaskStore>)Expand description
Reconcile the in-memory cooldown map with the persisted KV state.
KV is the source of truth. This is called once per tick by
router.refresh_health so the running service notices state mutated by a
separate process (e.g. orch cooldown clear). Without this sync, the CLI
clears KV but the engine’s in-memory map keeps the stale entries until they
expire on their own, producing the “all agents cooled” + “No active
cooldowns” inconsistency.
Reconciliation rules (KV authoritative for every key it has):
- KV row missing for an in-memory key: leave memory alone — likely a
set_cooldown_asyncrace where memory was written but the KV row isn’t yet visible. The next tick will catch up. - KV row present with
cooldown_until <= now(including the “0” tombstone written byclear_cooldown): drop from memory. - KV row present with
cooldown_until > now: insert/update memory to match.