fix: address codex review — use clock for cutoff + early-exit harvest

- 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 <noreply@anthropic.com>
This commit is contained in:
carpedkm
2026-06-20 14:11:58 +00:00
parent 889238b234
commit 6cc1cd2e95
2 changed files with 5 additions and 2 deletions
+2 -1
View File
@@ -150,7 +150,8 @@ def run_sleep_cycle(
lookback_hours = cfg.get("lookback_hours", 72) lookback_hours = cfg.get("lookback_hours", 72)
if lookback_hours and lookback_hours > 0: if lookback_hours and lookback_hours > 0:
import time 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) since = _now_iso(cutoff)
max_tasks = cfg.get("max_tasks_per_night", 40) max_tasks = cfg.get("max_tasks_per_night", 40)
max_sessions = cfg.get("max_sessions_per_night", 0) or max_tasks * 3 max_sessions = cfg.get("max_sessions_per_night", 0) or max_tasks * 3
+3 -1
View File
@@ -294,7 +294,9 @@ def harvest(
if not _project_matches(d.project or "", scope, invoked_project): if not _project_matches(d.project or "", scope, invoked_project):
continue continue
if since_iso and d.ended_at and d.ended_at < since_iso: 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) digests.append(d)
if limit and len(digests) >= limit: if limit and len(digests) >= limit:
break break