Skip to content

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

Closed
wuqxuan wants to merge 2 commits into
openclaw:mainfrom
wuqxuan:fix/104518-on-exit-delete-after-run
Closed

wuqxuan wants to merge 2 commits into
openclaw:mainfrom
wuqxuan:fix/104518-on-exit-delete-after-run

Conversation

@wuqxuan

@wuqxuan wuqxuan commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #104518

What Problem This Solves

Fixes an issue where users who create an on-exit cron job with --delete-after-run would still find the job retained as disabled after a successful payload run, instead of being removed from the store. Manual cron rm was required for cleanup even though deletion was requested.

Why This Change Was Made

Successful deleteAfterRun finalization previously applied only to one-shot at schedules. The Gateway exit watcher still disables an on-exit job before the payload runs (replay-safe if the Gateway restarts mid-fire). This change generalizes the post-success delete path to on-exit as well, while keeping non-success / keep-after-run jobs disabled rather than deleted.

User Impact

Operators using openclaw cron add --on-exit … --delete-after-run get the documented cleanup contract: a successful fire removes the job. Failed fires remain disabled for inspection. Pre-fire disable for restart safety is unchanged.

Evidence

Verification host: local macOS (isolated Gateway + focused Vitest)

Commands:

node scripts/run-vitest.mjs src/cron/service.removal-postcommit.test.ts -t "on-exit"
# 5 passed | 9 skipped (includes armed keep/failure controls)
node scripts/run-vitest.mjs \
  src/cron/service.removal-postcommit.test.ts \
  src/gateway/cron-exit-watchers.test.ts \
  src/cron/service.runs-one-shot-main-job-disables-it.test.ts \
  src/cron/service.issue-regressions.test.ts
# all passed (cron 35 + gateway exit-watchers 15×4 shards)

Focused on-exit suite (post CS code fix):

✓ deletes a successful on-exit job after force run when deleteAfterRun is true
✓ keeps a successful on-exit job disabled when deleteAfterRun is false
✓ keeps a failed on-exit job disabled when deleteAfterRun is true
✓ keeps an armed on-exit job enabled after manual keep-after-run success
✓ keeps an armed on-exit job enabled after manual force-run failure

Commit: 4c4e37cfa9c042c473ed465edebe85cc220b528f on fix/104518-on-exit-delete-after-run

Real behavior proof

  • Behavior addressed: (1) Successful watcher-terminal on-exit + deleteAfterRun removes the job. (2) Non-delete / failed operator force runs no longer terminalize an armed on-exit job (CS P1 on timer.ts).
  • Environment: local macOS; isolated Gateway via OPENCLAW_STATE_DIR + loopback port 61922; rebuilt runtime with node scripts/run-node.mjs gateway so the working-tree finalizer was live.
  • Current-main contrast: On main, shouldDelete only covered at, so successful on-exit jobs stayed disabled in the store. An earlier stale-dist isolated run on this branch reproduced that retention; after rebuild with the PR finalizer, the same path removed the job.
  • Exact steps after this patch:
    1. Start isolated Gateway (auth token, OPENCLAW_SKIP_CHANNELS=1, cron.enabled=true).
    2. cron list --all --json → jobs: [].
    3. cron add --name pr104559-on-exit-delete-proof --on-exit "sh -c 'echo watched-exit; sleep 1; exit 0'" --system-event "pr104559 on-exit proof wake" --session main --delete-after-run --json.
    4. Watched command exits; Gateway fires payload; finalizer applies successful deleteAfterRun.
    5. cron list --all --json → jobs: [], total: 0 (durable store empty).
  • Evidence after fix (redacted):
    • add returned job id 2e583284-f0f6-4a10-930f-70f35ed45c8e, deleteAfterRun: true, schedule.kind: on-exit.
    • Immediate post-fire cron list --all --json: {"jobs":[],"total":0,...} (JOB REMOVED).
    • Focused regression tests cover armed keep-after-run success and armed force-run failure remaining enabled: true.
  • Control / negative: watcher-pre-disabled keep-after-run and failed deleteAfterRun jobs stay in store as disabled (unit controls); armed non-delete paths no longer set enabled=false in the shared finalizer.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Jul 11, 2026
@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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, 2:05 PM ET / 18:05 UTC.

Summary
The PR extends successful deleteAfterRun removal to on-exit schedules, preserves armed on-exit jobs after non-delete manual runs, adds lifecycle regression coverage, and documents the behavior.

PR surface: Source +10, Tests +206, Docs +2. Total +218 across 3 files.

Reproducibility: yes. The linked issue supplies a concrete beta reproduction, current main's finalizer explains the retained disabled row, and the PR provides a real isolated Gateway before/after path with durable CLI state.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #104518
Summary: The linked issue is canonical; this PR and #104550 are competing candidate fixes, while manual-run deletion policy is a distinct partial overlap.

Members:

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

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

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

Rank-up moves:

  • none.

Risk before merge

Maintainer options:

  1. Land this proven candidate (recommended)
    Select this branch for its live Gateway proof and armed non-delete controls, then close the competing PR after merge.
  2. Prefer the smaller candidate
    Land fix(cron): delete successful on-exit deleteAfterRun jobs #104550 only after carrying over equivalent armed-job controls and accepting its proof as sufficient.

Next step before merge

  • No automated repair is needed; the branch is ready for ordinary maintainer comparison and selection against the competing open fix.

Security
Cleared: The diff changes cron lifecycle logic, tests, and documentation without adding dependency, permission, secret, artifact-download, or supply-chain surfaces.

Review details

Best possible solution:

Land one canonical narrow fix that preserves watcher pre-disable replay safety, removes successful watcher-fired on-exit jobs, retains failed or keep-after-run jobs, and leaves broader manual-run policy to its existing dedicated work.

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

Yes. The linked issue supplies a concrete beta reproduction, current main's finalizer explains the retained disabled row, and the PR provides a real isolated Gateway before/after path with durable CLI state.

Is this the best way to solve the issue?

Yes. Post-success removal belongs in the shared service finalizer, while the watcher continues to own durable pre-fire disabling; the updated branch also avoids terminalizing armed non-delete force runs.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body shows a real isolated Gateway watched-command flow and immediate durable CLI output with the successful delete-after-run job removed.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated PR body shows a real isolated Gateway watched-command flow and immediate durable CLI output with the successful delete-after-run job removed.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The PR fixes a bounded, reproducible cron cleanup-contract bug that causes stale disabled jobs but not an urgent runtime outage.
  • merge-risk: 🚨 compatibility: The shared finalizer change extends successful deleteAfterRun semantics to the recently added on-exit schedule and overlaps an unresolved manual-run policy discussion.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated PR body shows a real isolated Gateway watched-command flow and immediate durable CLI output with the successful delete-after-run job removed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body shows a real isolated Gateway watched-command flow and immediate durable CLI output with the successful delete-after-run job removed.
Evidence reviewed

PR surface:

Source +10, Tests +206, Docs +2. Total +218 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 1 +10
Tests 1 206 0 +206
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 219 1 +218

What I checked:

  • Current-main defect: Current main deletes successful deleteAfterRun jobs only for at schedules, so the Gateway's pre-disabled successful on-exit job remains stored instead of being removed. (src/cron/service/timer.ts:803, d4adddbe9c7a)
  • Watcher lifecycle: The Gateway watcher durably records command completion before invoking the cron service force-run path, preserving replay safety while leaving post-success deletion to the shared finalizer. (src/gateway/cron-exit-watchers.ts:1, d4adddbe9c7a)
  • Prior finding resolved: The second PR commit removes unconditional on-exit terminalization and documents that generic non-delete force runs must not cancel an armed watch. (src/cron/service/timer.ts:891, 4c4e37cfa9c0)
  • Regression coverage: The updated tests cover watcher-disabled success deletion, retained keep/failure outcomes, and enabled armed keep/failure force-run controls. (src/cron/service.removal-postcommit.test.ts:268, 4c4e37cfa9c0)
  • Real behavior proof: The PR body provides an isolated Gateway run where a real watched process exits, the payload succeeds, and immediate durable cron list --all --json output reports zero jobs. (4c4e37cfa9c0)
  • Feature provenance: The on-exit watcher lifecycle entered main through the merged feature commit on July 1, 2026; the cleanup gap is therefore in current main but not in the listed June stable release. (src/gateway/cron-exit-watchers.ts:1, 68bfa42b9bfc)

Likely related people:

  • anagnorisis2peripeteia: Authored the merged on-exit schedule feature and established the watcher pre-disable and force-run lifecycle affected by this fix. (role: feature introducer; confidence: high; commits: 68bfa42b9bfc; files: src/gateway/cron-exit-watchers.ts, src/cron/service/timer.ts, docs/automation/cron-jobs.md)
  • Ayaan Zaidi: Committed the merged on-exit feature to main and is directly connected to the lifecycle now being corrected. (role: merger; confidence: medium; commits: 68bfa42b9bfc; files: src/gateway/cron-exit-watchers.ts)
  • steipete: Git history shows the largest volume of work across the central cron service files, making this the strongest general routing candidate for finalizer behavior. (role: recent area contributor; confidence: medium; files: src/cron/service/timer.ts, src/cron/service/ops.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 (2 earlier review cycles)
  • reviewed 2026-07-11T16:43:39.227Z sha 2357a0f :: needs real behavior proof before merge. :: [P1] Do not disable an armed on-exit job after a manual run
  • reviewed 2026-07-11T16:50:55.831Z sha 2357a0f :: needs real behavior proof before merge. :: [P1] Do not disable an armed on-exit job after a manual run

@wuqxuan

wuqxuan commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Removed unconditional on-exit terminalization for non-delete runs (armed keep/fail stay enabled); kept successful deleteAfterRun removal; added regression tests + isolated live Gateway proof (watched exit → job removed from durable store).

@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

Copy link
Copy Markdown
Contributor

Superseded by #104550, now landed as f0676a7. The canonical fix keeps finalization in the shared cron service owner and adds durable SQLite plus post-commit removal-event coverage.

Thank you @wuqxuan. The duplicate's live Gateway proof and durability assertions helped strengthen the landed branch.

@steipete steipete closed this Jul 11, 2026
@steipete

Copy link
Copy Markdown
Contributor

#104550 is the preferred fix for #104518. It has the same correct runtime change with a smaller, refactored regression that verifies in-memory state, durable persistence, and lifecycle events across successful deletion, configured retention, and failure retention. The refreshed exact head is green and passed the isolated focused test, so I am closing this duplicate in favor of #104550. Thank you for the contribution.

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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: M 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