Repository navigation
fix(cron): stop warning forever for deleted agents - #124566
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: found issues before merge. Reviewed August 16, 2026, 8:36 AM ET / 12:36 UTC. ClawSweeper reviewWhat this changesThe PR skips unavailable agents before cron session-store cleanup and renames the cron logger’s store field to Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessKeep open: the generic availability check also rejects unfenced retired owners, contradicting the existing reaper contract to prune their expired sessions. Likely related people: @steipete (high confidence). Priority: P1 Review scores
Verification
How this fits togetherThe cron service periodically gathers persisted and scheduled agent owners, resolves each session store, and removes expired cron-run sessions. Gateway construction supplies both the owner list and lifecycle availability checks. flowchart LR
A[Persisted session owners] --> C[Cron reaper target set]
B[Cron jobs and default owner] --> C
C --> D{Deletion fence?}
D -->|no| E[Resolve session store]
E --> F[Prune expired cron sessions]
D -->|yes| G[Log one skip]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +12, Tests +66. Total +78 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Inject a reaper-specific deletion-fence predicate from Gateway, preserve cleanup for unfenced persisted owners, and prove both cases through the real Gateway composition. Do we have a high-confidence way to reproduce the issue? Yes, from source: a persisted owner absent from the roster is discovered for cleanup, but Gateway’s availability callback returns false and the proposed line skips it before session-store resolution. Is this the best way to solve the issue? No. The best fix is to gate only the deletion-journal fence, because generic roster availability intentionally has a broader meaning for cron mutations and run authority. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c1622d08f50f. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…8920) ## 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/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]>
…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]>
What Problem This Solves
Fixes an issue where operators who deleted agents accumulated a permanent cron warning loop. The observed gateway emitted 715
cron-reaper: failed to sweep session storewarnings in one day: 13 deleted agents multiplied by 55 sweep attempts each. Every attempt tried to open a database that the deletion journal correctly fences, so no expired session was pruned and the warning could not resolve without code changes.The target set was seeded from every persisted session-store owner in
timer-scheduler.ts, but unlike cron mutations and run receipts, the reaper never consulted the existingisAgentAvailableowner before resolving and opening the store.Why This Change Was Made
The reaper now applies
isAgentAvailableto the complete, normalized target set after persisted owners, cron-job owners, and the default owner have been combined. This is the owning boundary: filteringlistKnownSessionStoreAgentIdswould break its other caller, the combined Gateway session view, and filtering only the discovery callback would let stale job/default owners re-add the unavailable agent.Unavailable targets are re-evaluated on every tick and recorded once per unavailable transition at debug level. The diagnostic Set only bounds emission; it is not an agent-existence or deletion cache. The database fence and five-minute reaper throttle are unchanged.
Agent deletion remains the cleanup owner. Shared-store session rows are purged during deletion; per-agent rows disappear with the deleted database. An interrupted cleanup retains its journal and database fence for an explicit delete retry. Completed
deleteFiles:falsetombstones intentionally retain the database behind the fence until identity recreation, so the cron reaper must not access it.The JSON-looking cron path still selects a logical SQLite partition, but it is not a file. Cron logger bindings now call it
storeKeyinstead of the misleadingstorePath.AI-assisted change; the implementation, ownership boundaries, and evidence below were reviewed before publication.
User Impact
Deleted and blocked-delete agents no longer cause a failed database open and WARN every five minutes. Live agents—including agents with no cron jobs—continue to have expired cron-run sessions pruned. Operators debugging cron logs see the logical SQLite partition labeled as
storeKey, not as a nonexistent JSON file.Evidence
Before / regression
After
node scripts/run-vitest.mjs src/cron/service.session-reaper-in-finally.test.ts src/cron/service/state.test.ts src/config/sessions/targets-known-owners.test.ts src/gateway/server-cron.test.ts src/gateway/local-request-context.test.tstbx_01m056bs44sm009704ppmmknf3, Actions run https://github.com/openclaw/openclaw/actions/runs/31945286828pnpm buildpassed.OPENCLAW_STATE_DIRandOPENCLAW_SKIP_CHANNELS=1:victimand an expired cron-run session.deleteFiles:false, leavingcleanupCompleted:trueand the database intentionally retained behind its tombstone.reaper_warning_count=0,reaper_skip_debug_count=1.storePathbindings for the cron partition; 39storeKeybindings. The one skip record carriedagentId=victimandstoreKey=/tmp/openclaw-cron-reaper-r18/cron/jobs.json.node scripts/check-changed.mjstbx_01m057nbdds0tz18mq2m6pwjr8, Actions run https://github.com/openclaw/openclaw/actions/runs/31946320495..agents/skills/autoreview/scripts/autoreview --mode uncommitted --stream-engine-outputProduction LOC: +13/-2 (net +11) | Tests/test support: +67/-0
Sweep result:
listKnownSessionStoreAgentIdsremains intentionally broad for combined session views. Gateway startup temp cleanup may encounter a tombstone once per startup, and explicit task/plugin maintenance may report one visible failure, but no other recurring maintenance loop derives a forever-retried target set from persisted owners. Transcript-index startup and memory/index maintenance are configured/active-agent scoped.