Repository navigation
refactor(cleanup): per-sweep strategies for _run_cleanup_inner (#1026) - #1035
Conversation
…gies (#1026) The cleanup cycle was a single 290-line method running ~11 sequential sweeps, each in its own try/except. Extract each sweep into a focused `_sweep_*` method; the orchestrator is now a 33-line sequence. No behavior change — per-sweep error isolation, the rate-limit cycle gate, the watchdog→slot-sweep `confirmed_running_ids` handoff, and the WAL-checkpoint retention gate are all preserved. Adds tests/unit/test_cleanup_inner_sweeps.py characterizing the cycle (sweep set, report population, error isolation, cycle-gating, WAL gate); green before and after the extraction. Related to #1026 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
dbf52f8 to
653aeb0
Compare
✅
|
|
Resolve by running |
vybe
left a comment
There was a problem hiding this comment.
Validated via /validate-pr: faithful extract-method decomposition (290-line method → 33-line orchestrator). Sweep order, per-sweep error isolation, the #226 watchdog→slot handoff, the _cycle_count%12 gate (read before increment), and the WAL-checkpoint retention gate all preserved. Characterization tests green pre+post. Approving.
Summary
First (lowest-difficulty) refactor from #1026 — decompose the cleanup-service hotspot.
CleanupService._run_cleanup_innerwas a single 290-line method running ~11 sequential sweeps, each wrapped in its own try/except. This extracts each sweep into a focused_sweep_*method; the orchestrator is now a 33-line sequence that reads top-to-bottom.No behavior change. Preserved exactly:
_cycle_count % 12, read before the orchestrator's end-of-cycle increment)confirmed_running_idshandoff (bug: Stale slot cleanup uses fixed 20-min TTL regardless of agent timeout #226)Sweeps extracted
_sweep_watchdog(#129) ·_sweep_stale_executions·_sweep_no_session_executions(#106) ·_sweep_orphaned_skipped(#106) ·_sweep_stale_activities·_sweep_stale_slots(#219/#226/#378) ·_sweep_rate_limit_events(#476) ·_sweep_shared_files(FILES-001) ·_sweep_retention_772(#772) ·_sweep_soft_deleted_agents(#834 1a) ·_sweep_soft_deleted_schedules(#834 1b) ·_maybe_wal_checkpointTests
Adds
tests/unit/test_cleanup_inner_sweeps.py— characterization tests pinning the cycle's contract (sweep set, report-field population, error isolation, cycle-gating, WAL gate). Green before and after the extraction — the proof of behavior preservation.-m "not slow"); the only failures are 5 pre-existing/environmentaltest_git_pull_branch.pycases (need a realorigin/mainrepo) — unrelated to this diffScope
Single function per the issue's "small incremental PRs" guidance. Next in #1026:
adapters/message_router._handle_message_inner.execute_task(25 params) saved for last, after the #1027 request-object pattern.Related to #1026