From 6cc1cd2e95e0a3a6abb0f3572dfe7b919a40cb43 Mon Sep 17 00:00:00 2001 From: carpedkm Date: Sat, 20 Jun 2026 14:11:58 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20address=20codex=20review=20=E2=80=94=20u?= =?UTF-8?q?se=20clock=20for=20cutoff=20+=20early-exit=20harvest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - cycle.py: use supplied `clock` parameter (not wall time) for the lookback cutoff, so deterministic tests/experiments get reproducible harvest windows - harvest.py: break (not continue) when a file is older than since_iso, since files are sorted newest-first by mtime — avoids scanning the entire transcript directory for quiet projects with large histories Co-Authored-By: Claude Fable 5 --- skillopt_sleep/cycle.py | 3 ++- skillopt_sleep/harvest.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/skillopt_sleep/cycle.py b/skillopt_sleep/cycle.py index e66f436..9375784 100644 --- a/skillopt_sleep/cycle.py +++ b/skillopt_sleep/cycle.py @@ -150,7 +150,8 @@ def run_sleep_cycle( lookback_hours = cfg.get("lookback_hours", 72) if lookback_hours and lookback_hours > 0: import time - cutoff = time.time() - lookback_hours * 3600 + ref_time = clock if clock is not None else time.time() + cutoff = ref_time - lookback_hours * 3600 since = _now_iso(cutoff) max_tasks = cfg.get("max_tasks_per_night", 40) max_sessions = cfg.get("max_sessions_per_night", 0) or max_tasks * 3 diff --git a/skillopt_sleep/harvest.py b/skillopt_sleep/harvest.py index 3645d3f..84446f8 100644 --- a/skillopt_sleep/harvest.py +++ b/skillopt_sleep/harvest.py @@ -294,7 +294,9 @@ def harvest( if not _project_matches(d.project or "", scope, invoked_project): continue if since_iso and d.ended_at and d.ended_at < since_iso: - continue + # Files are sorted newest-first by mtime; once we see one that + # is older than the cutoff, all remaining files are older too. + break digests.append(d) if limit and len(digests) >= limit: break