Skip to content

fix(cron): protect recreated reminders from stale active runs - #114756

Merged
steipete merged 1 commit into
mainfrom
codex/cron-active-removal-replacement
Jul 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cron-active-removal-replacement

Conversation

@steipete-oai

@steipete-oai steipete-oai commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users who remove a running scheduled reminder and recreate the same explicit job ID can have the original execution overwrite or consume the newly created reminder. The stale run could incorrectly attach its completion, delivery history, or failure status to the replacement across direct manual runs, queued runs, scheduled timer runs, and startup catch-up.

Why This Change Was Made

The cron active-run registry previously distinguished durable schedule edits but not a durable job deletion. Record deletion on the exact admitted run only after its removal commits, keep its active marker until real completion, finalize old scheduled and queued outcomes against the original job snapshot, and leave a same-ID replacement completely independent. Apply the same ownership invariant to ordinary removals and transactional agent-job deletions, including uncertain commits; rollbacks and idle jobs remain unchanged. No public config, plugin API, Gateway protocol, dependency, SQLite schema, migration, or compatibility surface changes.

User Impact

Operators can safely remove and recreate a reminder while its previous run is finishing. The replacement stays enabled, keeps its own schedule and untouched run/delivery history, and fires normally; the old execution still receives its correct terminal result without duplicate delivery.

Evidence

  • Frozen clean main: 62baf451c14c98dc8ab70e5050083a8efb18823b.
  • Archived and live GitHub searches found no duplicate open issue or PR.
  • Red-first trusted Linux proof: all 8 direct, queued, scheduled, startup, and deleteAfterRun replacement cases failed on unmodified production.
  • Post-fix focused ownership and real durable-store regression suite: 46/46; independently repeated 3 times.
  • Complete cron suite: 1,780/1,780 across 154 test files.
  • Complete cron-related Gateway, stream, caller-scope, validation, and CLI regression suites passed.
  • pnpm check:changed passed production and test typechecking, targeted lint, formatting, plugin/dependency guards, native state schema, database-first, runtime imports, webhook, and pairing checks.
  • Dedicated Blacksmith Testbox tbx_01kyjq52wf8c3hc9bw4ynnxy97; exact reviewed patch; user command exit 0.
  • Fresh independent Codex autoreview: no accepted or actionable findings.
  • Provenance: the durable removal path was carried forward by refactor(cron): split service operations #113830; no schema or security-owned source changed.

Refreshed latest-main proof

  • Preserved red-first baseline: 62baf451c14c98dc8ab70e5050083a8efb18823b.
  • Rebased baseline, including the new cron/Workboard lifecycle-race fix fix: prevent cron and Workboard lifecycle races #114744: 5e8555a7c9b7ceefc2e1be2df57c6251f4411af8.
  • Exact independently reviewed pull-request head: 93fe321608c2d62f6f47e8f36dadf2428063e5e9.
  • Three fresh exact-head ownership stress runs: 138/138 across all direct, queued, timer, startup, and deletion-policy cases.
  • Complete rebased cron suite and cron CLI regressions pass; all Gateway cron, stream, validation, and caller-scope tests pass: 370/370.
  • Fresh exact-head branch autoreview: no accepted or actionable findings.
  • Refreshed trusted Linux Testbox: tbx_01kyjsdndw4k04t7a6nxpwsw5n.
  • ClawSweeper rank-up completed: rebased against current main, incorporated fix: prevent cron and Workboard lifecycle races #114744, and reran exact-head ownership stress, the complete cron/Gateway/CLI regression surfaces, and independent review.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 27, 2026
@steipete
steipete marked this pull request as ready for review July 27, 2026 21:43
@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. P2 Normal backlog priority with limited blast radius. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 6:14 PM ET / 22:14 UTC.

ClawSweeper review

What this changes

The PR records deletion of an in-flight cron job so its later completion cannot write outcome or delivery state into a newly created reminder that reuses the same ID.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for maintainer review. The focused patch appears correct and its supplied durable-store proof covers the direct, queued, scheduled, and startup paths; however, the branch is behind current main and the protected maintainer label requires an explicit final merge-result refresh before landing.

Priority: P2
Reviewed head: 93fe321608c2d62f6f47e8f36dadf2428063e5e9
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, backed by broad trigger-family regression coverage and real durable-store proof; only final merge-result validation and protected-label review remain.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body supplies red-first and post-fix durable-store evidence for the changed behavior, including repeated exact-head stress runs and focused cron, Gateway, and CLI regressions.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies red-first and post-fix durable-store evidence for the changed behavior, including repeated exact-head stress runs and focused cron, Gateway, and CLI regressions.
Evidence reviewed 5 items Deletion identity is carried on the admitted run: The PR adds jobRemoved to the active marker and records it only after ordinary or transactional job removal has committed, preserving duplicate-run suppression while distinguishing a later same-ID job.
Manual and timer completion paths reject a replacement: Manual completion uses the admitted execution snapshot when the marker reports deletion, and timer outcome finalization refuses to update a stored same-ID job for a removed active marker.
Trigger-family regression coverage: The branch adds removal-and-recreation coverage for direct and queued one-shot runs plus scheduled and startup batch outcomes, with both delete-after-run settings.
Findings None None.
Security None None.

How this fits together

OpenClaw cron persists reminder definitions, admits executions in process, then applies terminal results back to stored jobs. The changed active-run marker separates a deleted original job from a same-ID replacement so the old completion cannot mutate the replacement.

flowchart LR
  A[Persisted reminder] --> B[Admitted cron run]
  B --> C[Active-run marker]
  A --> D[Remove original job]
  D --> E[Durable removal marker]
  D --> F[Same-ID replacement]
  C --> G[Run completes]
  E --> G
  G --> H[Apply outcome only to original run]
  F --> I[Replacement remains independent]
Loading

Decision needed

Question Recommendation
Should this protected cron-state repair be accepted after rebasing onto current main and proving the replacement-ID invariant on the exact merge result? Refresh and land: Rebase onto current main, rerun the focused direct, queued, scheduled, and startup replacement-ID regressions plus required checks, then merge if the final result remains clean.

Why: The patch has no discrete code defect from this review, but it changes in-flight-to-persisted-job ownership and carries the protected maintainer label, so a maintainer must own the final upgrade-safe landing decision.

Before merge

  • Resolve merge risk (P1) - The PR is mergeable but behind current main; the replacement-ID ownership tests and required checks need to run against the final merge result before this session-state change lands.
  • Complete next step (P2) - No mechanical repair is indicated; a maintainer must refresh the exact merge result and accept the protected cron-state change before landing.
Agent review details

Security

None.

PR surface

Source +29, Tests +212. Total +241 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 33 4 +29
Tests 3 212 0 +212
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 245 4 +241

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Prove the exact merge result (recommended)
    Rebase or use the merge queue, then rerun the focused removal-and-same-ID-recreation cron regressions and required checks on the final merge result.
  2. Pause for owner review
    Do not merge until a cron owner accepts the active-marker deletion contract if the final refresh exposes a lifecycle interaction not covered by the focused cases.

Technical review

Best possible solution:

Refresh the branch onto current main, preserve the durable deletion-marker invariant across every completion path, and land only after the exact merge result passes the focused replacement-ID regressions and required checks.

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

Yes. Start a cron run, remove its job after admission, recreate a job with the same explicit ID before the original completes, then release the original run and verify that the replacement keeps its own history and schedule.

Is this the best way to solve the issue?

Yes. Recording durable deletion on the already-admitted active marker is the narrowest owner-boundary fix: it avoids changing persisted job shape or adding a compatibility path while protecting both manual and timer completion boundaries.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded reminder state-integrity race that can affect a delete-and-recreate workflow but is not an outage or security bypass.
  • merge-risk: 🚨 session-state: Merging changes how a finishing in-flight run associates its terminal state with a persisted cron job after deletion and ID reuse.
  • 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 (terminal): The PR body supplies red-first and post-fix durable-store evidence for the changed behavior, including repeated exact-head stress runs and focused cron, Gateway, and CLI regressions.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies red-first and post-fix durable-store evidence for the changed behavior, including repeated exact-head stress runs and focused cron, Gateway, and CLI regressions.

Evidence

What I checked:

  • Deletion identity is carried on the admitted run: The PR adds jobRemoved to the active marker and records it only after ordinary or transactional job removal has committed, preserving duplicate-run suppression while distinguishing a later same-ID job. (src/cron/active-jobs.ts:134, 93fe321608c2)
  • Manual and timer completion paths reject a replacement: Manual completion uses the admitted execution snapshot when the marker reports deletion, and timer outcome finalization refuses to update a stored same-ID job for a removed active marker. (src/cron/service/ops-run.ts:83, 93fe321608c2)
  • Trigger-family regression coverage: The branch adds removal-and-recreation coverage for direct and queued one-shot runs plus scheduled and startup batch outcomes, with both delete-after-run settings. (src/cron/service.one-shot-schedule-ownership.test.ts:85, 93fe321608c2)
  • Current ownership boundary provenance: The related merged cron operation split established the mutation, run, and timer-outcome modules this patch changes; the patch follows that split rather than introducing a new service-level path. (src/cron/service/ops-mutations.ts:411, 731a5d1e4545)
  • Exact-head behavior proof: The PR body reports a red-first durable-store reproduction followed by repeated exact-head ownership stress runs and focused cron, Gateway, and CLI regressions on head 93fe321. (src/cron/service/timer.batch-finalization.test.ts:70, 93fe321608c2)

Likely related people:

  • steipete: Authored the merged cron operation split that created the current mutation, execution, and timer-finalization ownership boundaries, and appears in the related merged lifecycle-race work. (role: recent cron-service refactor contributor; confidence: high; commits: 731a5d1e4545, d0948c33b533; files: src/cron/service/ops-mutations.ts, src/cron/service/ops-run.ts, src/cron/service/timer-outcomes.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase or merge-queue the branch and rerun the focused replacement-ID regressions on the exact merge result.
  • Wait for the remaining in-progress required checks before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

History

Review history (2 earlier review cycles)
  • reviewed 2026-07-27T21:47:59.740Z sha 8482ed953ca6e1eda07ccd42528389b93d90a503 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-27T22:07:41.844Z sha 93fe321 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/cron-active-removal-replacement branch from 8482ed9 to 93fe321 Compare July 27, 2026 22:02
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Jul 27, 2026
@steipete
steipete merged commit 0073862 into main Jul 27, 2026
127 checks passed
@steipete
steipete deleted the codex/cron-active-removal-replacement branch July 27, 2026 22:22
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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.

2 participants