Skip to content

fix(cron): delete successful on-exit deleteAfterRun jobs - #104550

Merged
steipete merged 3 commits into
openclaw:mainfrom
ObliviateRickLin:fix/cron-onexit-delete-after-run-104518
Jul 11, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
ObliviateRickLin:fix/cron-onexit-delete-after-run-104518

Conversation

@ObliviateRickLin

Copy link
Copy Markdown
Contributor

What Problem This Solves

#104518: an --on-exit cron job created with --delete-after-run runs its payload successfully but is retained as a disabled job instead of being deleted — the reporter needed a manual cron rm. Root cause is a two-part interaction, exactly as the triage identified: the gateway exit watcher durably disables an on-exit job before firing it (persistCompletion → enabled: false, the fail-closed replay protection so a gateway restart cannot re-arm and re-run the watched command), and the successful delete-after-run finalization in applyJobResult was restricted to schedule.kind === "at" — so no transition ever removed the fired job.

Why This Change Was Made

Per the triage's best solution ("generalize successful delete-after-run finalization to supported one-shot schedules … preserving durable pre-fire replay protection"):

  • shouldDelete in src/cron/service/timer.ts now covers every one-shot schedule kind ("at" and "on-exit"), still gated on deleteAfterRun === true && status === "ok".
  • The pre-fire disable ordering is untouched — replay protection stays durable and fail-closed; deletion is the service-owned terminal transition after a successful run, flowing through the same applyJobResult consumer used by both the timer path and the force path the exit watcher actually fires (cron.run(jobId, "force") → ops.ts delete branch).
  • Failed runs keep the existing contract: retained (disabled) for inspection, deletion only on ok — same as at jobs.

User Impact

openclaw cron add --on-exit ... --delete-after-run now behaves like the documented one-shot cleanup for --at jobs: success removes the job; no more zombie disabled entries needing manual cron rm.

Evidence

Regression (ops.regression.test.ts, drives the same disabled-job force path the exit watcher fires, per the triage's coverage list):

  • successful deleteAfterRun on-exit job → removed from the store;
  • deleteAfterRun: false → retained, durably disabled with lastStatus: "ok" (persistence-order contract unchanged);
  • failed run with deleteAfterRun: true → retained disabled with the error state preserved.

Fails on prior head for the reported reason: expected { id: 'onexit-delete-ok', …(11) } to be undefined — the job was retained disabled, byte-for-byte the reported behavior.

Validation: ops.regression.test.ts 12/12; timer.regression.test.ts 72/72 (includes the existing at-schedule deleteAfterRun retry/delete coverage, unchanged); tsgo:core 0; oxlint/oxfmt clean. Prod diff is the one guarded condition plus its ownership comment.

Fixes #104518

🤖 Generated with Claude Code

https://claude.ai/code/session_01AJogTw4aGDiacwqju1uod6

deleteAfterRun finalization was restricted to at schedules, so a successful
on-exit job with deleteAfterRun=true was retained as a disabled job instead
of being removed (the gateway exit watcher durably disables on-exit jobs
BEFORE firing as replay protection, and no later transition deleted them).
Successful delete-after-run now covers every one-shot schedule kind; the
pre-fire disable ordering is unchanged. Regression covers deletion on ok,
retention without the flag, and retention on failure through the same force
path the exit watcher fires.

Fixes openclaw#104518
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 11, 2026
@clawsweeper

clawsweeper Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 11, 2026, 7:20 PM ET / 23:20 UTC.

Summary
The PR extends successful deleteAfterRun removal to on-exit schedules and adds durable regression coverage for watcher-pre-disabled success, retention without deletion, and retention after failure.

PR surface: Source +2, Tests +70. Total +72 across 2 files.

Reproducibility: yes. The exact CLI workflow reproduces a retained disabled job on current main, and the contributor's real patched gateway run shows the persisted job removed.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #104518
Summary: The issue is canonical, and this PR plus one alternative open PR are viable candidate fixes for the same lifecycle defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] Two proof-positive PRs currently compete for the same canonical issue; maintainers should land one implementation and close the other to avoid duplicate fixes and divergent regression suites.

Maintainer options:

  1. Decide the mitigation before merge
    Land one narrow shared-finalizer fix that preserves the watcher's fail-closed pre-fire persistence, deletes successful deleteAfterRun on-exit jobs, and retains failed or explicitly kept jobs with durable regression coverage.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair remains; the maintainer next action is to choose and land one of the two viable candidate PRs for the canonical issue.

Maintainer decision needed

  • Question: Should this narrow, maintainer-refined PR be the canonical fix for the on-exit deleteAfterRun bug instead of the broader competing PR?
  • Rationale: Both open PRs are mergeable and proof-positive for the same canonical issue, so only a maintainer should select which branch and test shape to land.
  • Likely owner: steipete — The current assignee also authored the latest durable regression refinement on this branch.
  • Options:

Security
Cleared: The diff changes cron finalization and regression tests only, with no dependency, workflow, permission, secret, downloaded-code, or supply-chain changes.

Review details

Best possible solution:

Land one narrow shared-finalizer fix that preserves the watcher's fail-closed pre-fire persistence, deletes successful deleteAfterRun on-exit jobs, and retains failed or explicitly kept jobs with durable regression coverage.

Do we have a high-confidence way to reproduce the issue?

Yes. The exact CLI workflow reproduces a retained disabled job on current main, and the contributor's real patched gateway run shows the persisted job removed.

Is this the best way to solve the issue?

Yes. Extending the existing service-owned successful one-shot finalizer is the narrowest maintainable fix because it preserves durable pre-fire replay protection and avoids a second cleanup owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 453c049ac89d.

Label changes

Label justifications:

  • P2: This fixes a bounded user-visible cron lifecycle defect that otherwise leaves successful one-shot jobs requiring manual cleanup.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): A redacted real isolated-gateway before/after run demonstrates the exact current-main failure and durable persisted-job removal on the PR build.
  • proof: sufficient: Contributor real behavior proof is sufficient. A redacted real isolated-gateway before/after run demonstrates the exact current-main failure and durable persisted-job removal on the PR build.
Evidence reviewed

PR surface:

Source +2, Tests +70. Total +72 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 2 +2
Tests 1 71 1 +70
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 75 3 +72

What I checked:

  • Current-main defect remains: Current main deletes successful deleteAfterRun jobs only when schedule.kind is at, so a watcher-pre-disabled successful on-exit job is retained. (src/cron/service/timer.ts:806, 453c049ac89d)
  • Correct owner boundary: The gateway watcher durably disables an on-exit job before firing it through the normal cron run pipeline; post-success removal therefore belongs in the shared service finalizer rather than a second watcher cleanup path. (src/gateway/cron-exit-watchers.ts:201, 453c049ac89d)
  • Force-run finalization path: Forced cron runs call applyJobResult with schedule preservation and then use its boolean result for persisted removal, matching the path used after the watcher has terminal-disabled the job. (src/cron/service/ops.ts:1213, 453c049ac89d)
  • Durable regression coverage: The PR head verifies in-memory and on-disk deletion after success, disabled retention without deleteAfterRun, disabled retention after failure, and the expected started/finished/removed event sequence. (src/cron/service/ops.regression.test.ts:798, cce5e6499add)
  • Feature provenance: The relevant watcher lifecycle was introduced by the merged on-exit feature PR; its implementation intentionally persists terminal state before firing to prevent replay after restart. (src/gateway/cron-exit-watchers.ts:201, 68bfa42b9bfc)
  • Live proof: The contributor supplied the issue's exact CLI flow against a real isolated gateway: current main retained one disabled successful job, while the PR build left the persisted cron list empty. (cce5e6499add)

Likely related people:

  • steipete: Added the current head's durable-state and event-order regression commit, refreshed the branch from main, and is assigned to the PR. (role: recent area contributor and current assignee; confidence: high; commits: cce5e6499add, b79929d1e827; files: src/cron/service/ops.regression.test.ts, src/cron/service/timer.ts)
  • anagnorisis2peripeteia: Authored the merged on-exit watcher feature and its durable pre-fire state transition, which is the lifecycle this patch completes. (role: on-exit feature introducer; confidence: high; commits: 61b3c745a865, 68bfa42b9bfc; files: src/gateway/cron-exit-watchers.ts, src/cron/service/ops.ts, src/cron/types.ts)
  • tyler6204: Earlier merged cron scheduler reliability work shaped the shared one-shot finalization path touched by this patch. (role: earlier cron finalization contributor; confidence: medium; commits: d90cac990c8f, 8fae55e8e057; files: src/cron/service/timer.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (4 earlier review cycles)
  • reviewed 2026-07-11T16:10:28.986Z sha 2d0e96a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-11T16:17:03.402Z sha 2d0e96a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-11T17:17:41.338Z sha 2d0e96a :: needs maintainer review before merge. :: none
  • reviewed 2026-07-11T23:04:44.253Z sha b79929d :: needs maintainer review before merge. :: none

@ObliviateRickLin

Copy link
Copy Markdown
Contributor Author

Live before/after — the issue's exact repro on a real gateway

Real openclaw gateway (fresh OPENCLAW_STATE_DIR, loopback token auth), the issue's exact command sequence on both dists:

openclaw cron add \
  --name beta5-on-exit-command-nodeliver-smoke \
  --on-exit 'sh -c "exit 0"' \
  --command 'printf BETA5_ON_EXIT_NODELIVER_OK' \
  --no-deliver \
  --delete-after-run
# watched command exits, payload fires…
openclaw cron list --all --json

BEFORE — pristine current main dist:

job count: 1
 - beta5-on-exit-command-nodeliver-smoke  enabled=False  lastStatus=ok

The payload succeeded but the job is retained as a disabled zombie — byte-for-byte the reported behavior.

AFTER — this PR's dist, identical sequence:

job count: 0

The watched command exited, the payload ran successfully, and the job is gone from the persisted cron listing — the documented one-shot cleanup, now covering on-exit schedules.

No private paths, endpoints, or credentials appear above (fresh throwaway state dir, loopback only).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 11, 2026
@steipete steipete self-assigned this Jul 11, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 11, 2026
@steipete
steipete merged commit f0676a7 into openclaw:main Jul 11, 2026
102 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor

Maintainer refresh complete at cce5e6499add2bcad77adba118f3de3b5b86225c.

  • Extended the existing successful deleteAfterRun finalization rule to on-exit one-shots while retaining failed runs and jobs configured to remain.
  • Refactored the regression into a table and verified the in-memory job, durable store, and lifecycle events for all three outcomes.
  • Sanitized AWS Crabbox cbx_3b3f9a8794f9, run run_c060f692c4e8: pnpm test src/cron/service/ops.regression.test.ts — 16/16 passed.
  • Fresh autoreview: clean, 0.96 confidence.
  • Exact-head CI run 29171766664: green.

This is the preferred small fix for #104518 and is ready for the next landing batch.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 12, 2026
…4550)

* fix(cron): delete successful on-exit deleteAfterRun jobs

deleteAfterRun finalization was restricted to at schedules, so a successful
on-exit job with deleteAfterRun=true was retained as a disabled job instead
of being removed (the gateway exit watcher durably disables on-exit jobs
BEFORE firing as replay protection, and no later transition deleted them).
Successful delete-after-run now covers every one-shot schedule kind; the
pre-fire disable ordering is unchanged. Regression covers deletion on ok,
retention without the flag, and retention on failure through the same force
path the exit watcher fires.

Fixes openclaw#104518

* test(cron): prove durable on-exit finalization

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

cron: on-exit deleteAfterRun disables successful job instead of deleting it

2 participants