Repository navigation
fix(cron): skip availability checks when session pruning is idle - #148920
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 6:31 AM ET / 10:31 UTC (Revision 3). ClawSweeper reviewWhat this changesCron session cleanup now skips agent availability checks when pruning is disabled or cooling down, removes redundant diagnostic state, and adds scheduler regression coverage. Merge readiness✅ Ready for maintainer review The fix remains useful: current main still performs availability checks before pruning admission. No actionable defect was found, and the recorded Gateway measurements support the narrow performance claim. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway cron scheduler runs jobs and periodically removes expired run sessions. The session reaper decides whether maintenance is due, checks agent availability, and passes eligible removals to the existing session lifecycle owner. flowchart TD
A[Scheduler tick] --> B[Scheduled job execution]
A --> C[Discover session owners]
C --> D[Retention and cooldown decision]
D -->|Idle| E[Skip maintenance]
D -->|Due| F[Fresh availability check]
F -->|Available| G[Read sessions and prune expired runs]
F -->|Unavailable| E
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -5, Tests +103. Total +98 across 5 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep maintenance admission in the reaper, with fresh availability checks only for eligible sweeps and independent checks for job execution. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the path: each admitted tick checks every maintenance owner before the reaper can skip disabled or throttled work, and the journal reader uses a write transaction. This review did not execute the runtime. Is this the best way to solve the issue? Yes. Moving the check behind the existing admission decision removes unnecessary work without caching availability, changing retention settings, or weakening job execution checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2b8c9f1ad64a. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
landpr-approve-admin-merge |
holny
left a comment
There was a problem hiding this comment.
Nice cleanup — checking availability after the retention/throttle decision kills the per-tick journal writes for idle agents, and dropping reportedUnavailableReaperAgentIds in favor of the existing attempt throttle keeps the skip logs bounded.
One ordering thing worth a look: resolveSessionStorePath now runs for every reaper agent before the availability guard fires inside sweepCronRunSessions (timer-scheduler.ts:559-561). The old version of the test here deliberately had the resolver throw for a deleted agent, and the availability pre-check was what turned that into a quiet skip — the updated test swaps the mock to a non-throwing one, so that case is no longer covered. If a real resolver can still reject for a deleted agent, the throw now surfaces inside the scheduler loop; either keep the availability check ahead of path resolution or guard the per-agent call.
|
landpr-approve-admin-merge |
|
landpr-approve-unrelated-red |
|
Thanks @609NFT and @zachisfine! Proof: A real Gateway with 632 agents and a harmless scheduled command performed no maintenance journal transactions on disabled or throttled ticks. Eligible sweeps and scheduled commands still ran.
|
* commit 'ba441dd2d14e1d02dca72dd341cff28c360acaa2': fix(ci): remove duplicate Copilot auth metadata (#149016) test(agents): align auth fixtures with runtime store reads (#149004) improve: reduce data fetched during reminder maintenance (#148996) fix(cron): skip availability checks when session pruning is idle (#148920) fix(auth): guard GitHub Copilot device flow authority (#148999) fix(agents): prevent early recovery aborts of foreground exec (#148959) fix(github-copilot): remove retired Raptor mini (#116505) improve(feishu): reduce preparation work for documents with tables (#148997) improve: reduce database work when recording participants (#148841) test: accept Bun error labels in plugin assertions (#148955) fix(models): clarify saved account health and catalog status (#148987)
* commit '1226eecf4ff909de172a6837422cfa64723fade8': (39 commits) test: align model auth and setup fixtures with current behavior (#149023) refactor: reuse web search request context (#148949) fix(ci): remove duplicate Copilot auth metadata (#149016) test(agents): align auth fixtures with runtime store reads (#149004) improve: reduce data fetched during reminder maintenance (#148996) fix(cron): skip availability checks when session pruning is idle (#148920) fix(auth): guard GitHub Copilot device flow authority (#148999) fix(agents): prevent early recovery aborts of foreground exec (#148959) fix(github-copilot): remove retired Raptor mini (#116505) improve(feishu): reduce preparation work for documents with tables (#148997) improve: reduce database work when recording participants (#148841) test: accept Bun error labels in plugin assertions (#148955) fix(models): clarify saved account health and catalog status (#148987) test(plugins): align Copilot auth-choice registry expectations (#148981) fix(channels): reject blank integer channel add options (#145534) fix(ui): preserve archive undo after chat navigation (#148831) feat: show cited source previews in macOS and iOS chat (#148906) fix: avoid redundant tab updates while chats stream (#148865) test(qa): run Discord through Crabline (#116446) perf(crabbox): prepare project runtimes during worker download (#148952) ...
* commit '84114b5a2711764e2ca333e327e808fd88316063': (40 commits) improve(sessions): reuse compiled transcript metadata queries (#148773) fix(ci): repair Copilot contracts and config failure diagnostics (#149001) test: align model auth and setup fixtures with current behavior (#149023) refactor: reuse web search request context (#148949) fix(ci): remove duplicate Copilot auth metadata (#149016) test(agents): align auth fixtures with runtime store reads (#149004) improve: reduce data fetched during reminder maintenance (#148996) fix(cron): skip availability checks when session pruning is idle (#148920) fix(auth): guard GitHub Copilot device flow authority (#148999) fix(agents): prevent early recovery aborts of foreground exec (#148959) fix(github-copilot): remove retired Raptor mini (#116505) improve(feishu): reduce preparation work for documents with tables (#148997) improve: reduce database work when recording participants (#148841) test: accept Bun error labels in plugin assertions (#148955) fix(models): clarify saved account health and catalog status (#148987) test(plugins): align Copilot auth-choice registry expectations (#148981) fix(channels): reject blank integer channel add options (#145534) fix(ui): preserve archive undo after chat navigation (#148831) feat: show cited source previews in macOS and iOS chat (#148906) fix: avoid redundant tab updates while chats stream (#148865) ...
…nclaw#148920) ## What Problem This Solves Cron starts a journal write transaction for every agent on every admitted tick, even when session pruning is disabled or throttled. Closes openclaw#145394. Refs openclaw#124566. ## Why This Change Was Made The reaper now checks fresh availability after its retention and agent/store throttle decision, before reading sessions. This state has one writer. Its existing attempt throttle also bounds skip logs, replacing the separate diagnostic set. ## User Impact Idle pruning avoids per-agent journal writes. Unavailable agents stay excluded. Recovered agents can run scheduled jobs immediately; maintenance can wait until its existing five-minute cooldown expires. ## Evidence A real Gateway with 632 synthetic agents ran `/usr/bin/true` every 10 seconds via `cron.add`, launched with `pnpm openclaw gateway run`. Native SQLite tracing counted maintenance transaction starts separately from job execution. | Maintenance | Before | After | | --- | ---: | ---: | | Disabled, each of 3 ticks | 632 writes | 0 | | Throttled, each of 2 ticks | 632 writes | 0 | | Eligible pass | 632 checks/sweeps | 632 checks/sweeps | All command runs succeeded. Health probes still timed out around reload in both runs; this does not claim to remove all fleet stalls. On a fresh merge with main, 210 tests passed across six owner and sibling files. Both new scheduler regressions fail with the original code. Type-aware lint, production/test types, formatting, protocol checks, architecture, and ratchets passed. Thanks @609NFT for the journal stack evidence and @zachisfine for separating the session-listing cost. Other fleet health stalls remain outside this fix. ## Compatibility No schema, config, retention-rule, shared journal reader, or deletion-fence change. ## Consumers Timer maintenance uses the same reaper as before. Job execution retains its fresh availability checks. ## Invalidation The existing agent/store cooldown records attempts. Disabled retention records none; clock rollback admits a fresh attempt. ## Tests Scheduler entry tests cover disabled/re-enabled pruning, throttling, rollback, unavailable-owner exclusion, and job execution during recovery cooldown. Co-authored-by: Ayaan Zaidi <[email protected]>
* refactor(agents): centralize tool description exclusions * Merge main into refactor/tool-description-exclusions-20260915 * commit '84114b5a2711764e2ca333e327e808fd88316063': (40 commits) improve(sessions): reuse compiled transcript metadata queries (#148773) fix(ci): repair Copilot contracts and config failure diagnostics (#149001) test: align model auth and setup fixtures with current behavior (#149023) refactor: reuse web search request context (#148949) fix(ci): remove duplicate Copilot auth metadata (#149016) test(agents): align auth fixtures with runtime store reads (#149004) improve: reduce data fetched during reminder maintenance (#148996) fix(cron): skip availability checks when session pruning is idle (#148920) fix(auth): guard GitHub Copilot device flow authority (#148999) fix(agents): prevent early recovery aborts of foreground exec (#148959) fix(github-copilot): remove retired Raptor mini (#116505) improve(feishu): reduce preparation work for documents with tables (#148997) improve: reduce database work when recording participants (#148841) test: accept Bun error labels in plugin assertions (#148955) fix(models): clarify saved account health and catalog status (#148987) test(plugins): align Copilot auth-choice registry expectations (#148981) fix(channels): reject blank integer channel add options (#145534) fix(ui): preserve archive undo after chat navigation (#148831) feat: show cited source previews in macOS and iOS chat (#148906) fix: avoid redundant tab updates while chats stream (#148865) ... * refactor(agents): consolidate tool description exclusions * chore: merge main for tool summary validation * commit '926bb1e1d75c6b102bcbf93114c690312c23cf18': (1903 commits) refactor(matrix): reuse startup verification account key (#157310) perf(config): avoid repeated environment scans during publication (#156457) chore(i18n): refresh native locales (#157495) fix(update): show quiet step progress and date recorded outcomes (#153407) feat(gateway): preserve browser sign-in requirements before connecting (#157454) test(scripts): await CLI admission fixture lifetimes (#157424) fix(ci): preserve consumer selection across core type stripes (#157373) fix(wizard): preserve typed plugin enum values (#127577) (#138090) fix(qa): title mock Code Mode fixture calls refactor: simplify SQLite worker lifecycle and test fixtures (#157458) test: prebuild run-node signal fixture (#157478) refactor(exec): reuse approval policy rule keys (#157198) fix(ci): reuse prepared runtime for changed-target E2E shards (#157365) fix(config): apply Gateway writes without waiting for file events (#157372) fix: count recorded nested tool operations once (#157438) fix(telegram): stop leaking raw file:// markdown links in messages (#137810) refactor(claws): share resource capability changes (#154680) improve(channels): reduce redundant preparation for button messages (#157050) fix(build): package preparation fails on unrelated test types (#157318) refactor(claws): share bounded document reading (#157436) ... Co-authored-by: Vincent Koc <[email protected]>
…8966) * refactor(agents): centralize tool description exclusions * Merge main into refactor/tool-description-exclusions-20260915 * commit '4a994031abb1b54d51b76755a55ac8f6e918162d': (40 commits) improve(sessions): reuse compiled transcript metadata queries (openclaw#148773) fix(ci): repair Copilot contracts and config failure diagnostics (openclaw#149001) test: align model auth and setup fixtures with current behavior (openclaw#149023) refactor: reuse web search request context (openclaw#148949) fix(ci): remove duplicate Copilot auth metadata (openclaw#149016) test(agents): align auth fixtures with runtime store reads (openclaw#149004) improve: reduce data fetched during reminder maintenance (openclaw#148996) fix(cron): skip availability checks when session pruning is idle (openclaw#148920) fix(auth): guard GitHub Copilot device flow authority (openclaw#148999) fix(agents): prevent early recovery aborts of foreground exec (openclaw#148959) fix(github-copilot): remove retired Raptor mini (openclaw#116505) improve(feishu): reduce preparation work for documents with tables (openclaw#148997) improve: reduce database work when recording participants (openclaw#148841) test: accept Bun error labels in plugin assertions (openclaw#148955) fix(models): clarify saved account health and catalog status (openclaw#148987) test(plugins): align Copilot auth-choice registry expectations (openclaw#148981) fix(channels): reject blank integer channel add options (openclaw#145534) fix(ui): preserve archive undo after chat navigation (openclaw#148831) feat: show cited source previews in macOS and iOS chat (openclaw#148906) fix: avoid redundant tab updates while chats stream (openclaw#148865) ... * refactor(agents): consolidate tool description exclusions * chore: merge main for tool summary validation * commit 'e0f58a77476acbe382bff5e55cd520e9d228d478': (1903 commits) refactor(matrix): reuse startup verification account key (openclaw#157310) perf(config): avoid repeated environment scans during publication (openclaw#156457) chore(i18n): refresh native locales (openclaw#157495) fix(update): show quiet step progress and date recorded outcomes (openclaw#153407) feat(gateway): preserve browser sign-in requirements before connecting (openclaw#157454) test(scripts): await CLI admission fixture lifetimes (openclaw#157424) fix(ci): preserve consumer selection across core type stripes (openclaw#157373) fix(wizard): preserve typed plugin enum values (openclaw#127577) (openclaw#138090) fix(qa): title mock Code Mode fixture calls refactor: simplify SQLite worker lifecycle and test fixtures (openclaw#157458) test: prebuild run-node signal fixture (openclaw#157478) refactor(exec): reuse approval policy rule keys (openclaw#157198) fix(ci): reuse prepared runtime for changed-target E2E shards (openclaw#157365) fix(config): apply Gateway writes without waiting for file events (openclaw#157372) fix: count recorded nested tool operations once (openclaw#157438) fix(telegram): stop leaking raw file:// markdown links in messages (openclaw#137810) refactor(claws): share resource capability changes (openclaw#154680) improve(channels): reduce redundant preparation for button messages (openclaw#157050) fix(build): package preparation fails on unrelated test types (openclaw#157318) refactor(claws): share bounded document reading (openclaw#157436) ... Co-authored-by: Vincent Koc <[email protected]>
What Problem This Solves
Cron starts a journal write transaction for every agent on every admitted tick, even when session pruning is disabled or throttled.
Closes #145394. Refs #124566.
Why This Change Was Made
The reaper now checks fresh availability after its retention and agent/store throttle decision, before reading sessions. This state has one writer. Its existing attempt throttle also bounds skip logs, replacing the separate diagnostic set.
User Impact
Idle pruning avoids per-agent journal writes. Unavailable agents stay excluded. Recovered agents can run scheduled jobs immediately; maintenance can wait until its existing five-minute cooldown expires.
Evidence
A real Gateway with 632 synthetic agents ran
/usr/bin/trueevery 10 seconds viacron.add, launched withpnpm openclaw gateway run. Native SQLite tracing counted maintenance transaction starts separately from job execution.All command runs succeeded. Health probes still timed out around reload in both runs; this does not claim to remove all fleet stalls.
On a fresh merge with main, 210 tests passed across six owner and sibling files. Both new scheduler regressions fail with the original code. Type-aware lint, production/test types, formatting, protocol checks, architecture, and ratchets passed.
Thanks @609NFT for the journal stack evidence and @zachisfine for separating the session-listing cost. Other fleet health stalls remain outside this fix.
Compatibility
No schema, config, retention-rule, shared journal reader, or deletion-fence change.
Consumers
Timer maintenance uses the same reaper as before. Job execution retains its fresh availability checks.
Invalidation
The existing agent/store cooldown records attempts. Disabled retention records none; clock rollback admits a fresh attempt.
Tests
Scheduler entry tests cover disabled/re-enabled pruning, throttling, rollback, unavailable-owner exclusion, and job execution during recovery cooldown.