Repository navigation
fix(cron): maintenance fails every minute while an agent deletion is pending - #167907
Conversation
Keep pending deletion stores under their deletion owner while continuing session retention for healthy agents. Preserve completed-deletion skips and corrupt or held-store handling.
|
🦞👀 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. What this changesCron’s session retention sweep skips agents whose deletion is pending or complete, allowing cleanup of old sessions for healthy agents to continue. Example: An agent named retired has a pending deletion when session retention runs.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains useful: current main still aborts maintenance for pending deletions, and the proposed repair has no actionable correctness finding. The broader deletion cleanup problem remains separate. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway periodically removes expired automation session records while preserving running work. This sweep reads agent deletion facts before visiting each session database and returns maintenance results or intentional skips. flowchart TD
A[Gateway maintenance tick] --> B[Read running jobs and deletion facts]
B --> C{Agent deletion pending or complete?}
C -->|Yes| D[Record store skip]
C -->|No| E[Maintain eligible session store]
D --> F[Continue with other agents]
E --> F
Technical reviewBest possible solution: Keep deletion fences intact and isolate pending-deletion skips in the existing retention owner. Do we have a high-confidence way to reproduce the issue? Yes: leave an agent deletion pending and let Gateway maintenance run; current main explicitly throws on that status. The PR’s live A/B report and the related report independently describe this path, although this review did not execute it. Is this the best way to solve the issue? Yes: removing the aggregate sweep’s pending-deletion exception fixes maintenance isolation in its existing owner while preserving database fences and ordinary storage failures. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f4cb17e84085. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -3, Tests -5, Docs +2. Total -6 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 9, 2026, 2:20 PM ET / 18:20 UTC. |
|
@clawsweeper approve Maintainer decision (coordinator for Peter, 2026-10-09): bug fix - cron maintenance skips agents in deletion instead of failing each tick; no retention or fence change. |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Merged via squash.
|
…7907) Keep pending deletion stores under their deletion owner while continuing session retention for healthy agents. Preserve completed-deletion skips and corrupt or held-store handling.
What Problem This Solves
Fixes: while an agent deletion is pending (for example after deleting an agent that had a running turn), cron maintenance fails every minute:
Seen on a dev Gateway on main: one failure per maintenance tick for the deleted agent, continuing across a Gateway restart until the deletion was retried manually. Session-registry retention for the healthy agents was skipped on each failed tick.
User Impact
Cron session-registry maintenance skips agents whose deletion is pending or complete, records why, and keeps running retention for every other agent. Database fences, corrupt-store failures, held-store warnings and retention periods are unchanged.
Why This Change Was Made
src/cron/session-registry-maintenance.tscarried an explicit exception that let pending deletions through to the store visit, which then hit the deletion fence. The maintenance owner now treats pending and completed deletions like other unavailable stores (skip with a recorded reason). Sibling sweeps were checked: the isolated-cron reaper already uses deletion-aware availability and startup already skips pending stores. Production +8/−11.This does not fix the underlying deletion lifecycle (deleting an agent with an active turn leaves cleanup pending until
agents.deleteis retried); that needs a separate design.Evidence
Cron maintenance failed … is deletedevery minute. This branch: no deletion failures over 2.5 minutes of maintenance ticks.pnpm test src/cron/session-registry-maintenance.test.ts --maxWorkers=1: with the new cases and unchanged production 2 failed / 9 passed (OpenClaw agent database is unavailable while agent retired is deleted.); with the fix 11 passed (80 s, mostly the existing SQLite worker fixture).agents-mutate.test.ts61 passed. Types, lint, import cycles (0), docs links pass. Autoreview clean.