Skip to content

fix(cron): maintenance fails every minute while an agent deletion is pending - #167907

Merged
steipete merged 1 commit into
mainfrom
codex/stab-agent-delete-active-run
Oct 9, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/stab-agent-delete-active-run

Conversation

@steipete

@steipete steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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:

[cron/maintenance] Cron maintenance failed error="OpenClaw agent database is unavailable while agent <id> is deleted."

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.ts carried 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.delete is retried); that needs a separate design.

Evidence

  • Live A/B: create an agent, start a long turn, delete the agent mid-turn (cleanup stays pending on both builds). Main: Cron maintenance failed … is deleted every 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.ts 61 passed. Types, lint, import cycles (0), docs links pass. Autoreview clean.

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.
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Cron’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.

  • Before: Maintenance throws “OpenClaw agent database is unavailable while agent retired is deleted.” and aborts the remaining sweep.
  • After: Maintenance records agent-deletion-pending for retired and continues pruning eligible sessions for healthy agents.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow, useful repair with reported live Gateway A/B evidence, meaningful regression coverage, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The complete PR body reports exercising the actual Gateway maintenance scheduler after deleting an agent mid-turn: recurring main-build deletion errors disappear on the branch while cleanup remains pending. SQLite-backed regression results additionally cover healthy-store retention; no stored-data format or migration changes are introduced.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Deleting one agent during active work can make periodic session cleanup fail repeatedly for the Gateway’s other agents.
Reason: The change repairs the stated maintenance failure with less production code. The author’s prior merged maintenance ownership supports the explained change from terminal pending deletion to an isolated skip.

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
Reviewed head: 0d864ea352e53520467f8470a4d5e5bed9957589

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

  • src/cron/session-registry-maintenance.ts deletion handling changes intended behavior with a stated reason (fix(tasks): skip completed deleted-agent stores #130554: Completed deletion tombstones intentionally fence retained databases; the original repair skipped only completed deletions and preserved terminal behavior for incomplete deletions.)
  • src/cron/session-registry-maintenance.test.ts pending-deletion expectation changes intended behavior with a stated reason (fix(tasks): skip completed deleted-agent stores #130554: Regression coverage enforced the original distinction between completed deletion skips and terminal incomplete deletions.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b5a942c adds src/cron/session-registry-maintenance.ts:126 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b5a942c31f59; files: src/cron/session-registry-maintenance.ts)

PR surface

Source -3, Tests -5, Docs +2. Total -6 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 8 11 -3
Tests 1 19 24 -5
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 29 35 -6

Labels

Label changes:

  • add P2: Pending agent deletion interrupts periodic session retention, but this report does not establish broken scheduling or Gateway availability.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Pending agent deletion interrupts periodic session retention, but this report does not establish broken scheduling or Gateway availability.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 2:20 PM ET / 18:20 UTC.

@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete merged commit 9ef071e into main Oct 9, 2026
119 checks passed
@steipete
steipete deleted the codex/stab-agent-delete-active-run branch October 9, 2026 18:37
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant