Skip to content

fix(cron): cancellation reason survives late delivery finalization - #125397

Closed
steipete wants to merge 1 commit into
mainfrom
recovery/cron-cancellation-outcome-20260817
Closed

steipete wants to merge 1 commit into
mainfrom
recovery/cron-cancellation-outcome-20260817

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #117425

AI-assisted: Codex implemented and independently reviewed this repair.

What Problem This Solves

Fixes an issue where cancelling a cron task after its execution completed but while webhook delivery was still pending could leave the task marked cancelled while silently clearing the accepted operator cancellation reason. The same task row also could not represent that execution succeeded while delivery was interrupted.

Why This Change Was Made

Late cron finalization now preserves the generic task lifecycle's accepted cancelled status and reason, while cron-owned detail stores the underlying execution error/summary and delivery result for history projection. Current detail wins over the unchanged released-row fallback, so this adds no config, schema, protocol, or fallback reader. PR #117425 owns admission provenance and stale-delivery policy; it has no file overlap with this terminal task/history projection repair.

Production LOC: +15/-7 (net +8) to separate the two owner-native outcomes at write time; tests: +24/-10. The production growth adds the missing canonical cron detail fields and prevents cancellation finalization from overwriting generic lifecycle fields.

User Impact

Operators can trust a successful cancellation response to remain visible on the task. Cron history separately reports the completed execution and interrupted delivery, for example status: ok, the execution summary, delivered: false, and the delivery cancellation error.

Evidence

  • Pre-fix reproduction: node scripts/run-vitest.mjs src/cron/service/task-runs.test.ts -t 'keeps operator cancellation reason when webhook delivery is interrupted' failed because the persisted task had no error; expected Cancelled by operator.
  • Rebased focused suites: node scripts/run-vitest.mjs src/cron/service/task-runs.test.ts src/cron/service/timer-job-runner.interruption.test.ts src/cron/task-run-history.test.ts — 41 passed.
  • Rebased real-flow sibling coverage: node scripts/run-vitest.mjs src/cron/service.persists-delivered-status.test.ts src/cron/service/timer.regression.test.ts -t 'finalizes immediately when a command webhook is cancelled|cancels timeout-disabled cron task runs without waiting for the runner' — 2 passed, 83 skipped.
  • node scripts/check-changed.mjs — passed after the rebase, including core and core-test typechecks, lint, database-first, and import-cycle guards.
  • git diff --check origin/main...HEAD — passed.
  • Codex-backed autoreview: clean, no accepted/actionable findings.
  • Test-audit authoring gate: the regression protects the producer-owned ordering, fails pre-fix for the intended reason, is not duplicated by existing coverage, and adds no test-only production seam.

Live operator-Gateway proof was not run: reproducing the narrow post-execution/pre-webhook cancellation window requires coordinating an authenticated task cancellation with a deliberately hanging webhook. The focused owner-boundary regression captures that exact ordering, while the two existing real-flow tests independently prove accepted cancellation and hanging-webhook interruption.

@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 17, 2026 20:32
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 17, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 24, 2026, 4:49 PM ET / 20:49 UTC.

ClawSweeper review

What this changes

This PR preserves an operator’s cancellation reason on a cron task while recording the completed execution and interrupted delivery outcome in cron history.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: the prior P1 remains. This conflicted branch lacks current main’s completion-status contract, so an unsafe rebase could report a required delivery failure as success; the cancellation-reason repair should be rebased atop that contract.

Priority: P2
Reviewed head: 8ac01c3286c9b77a744e1031e7d3c82599f11f04

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The cancellation-state approach is useful, but the unresolved P1 rebase regression prevents confidence in the current patch.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its stated focused tests remain supplemental and must be rerun on the rebased head.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its stated focused tests remain supplemental and must be rerun on the rebased head.
Evidence reviewed 6 items Current completion contract: Current main derives completion only after execution and delivery settle, including a failed required delivery.
Current persistence and task mapping: Current main persists completionStatus in cron detail and maps an ok execution with failed or unknown completion to a failed generic task state.
Current regression coverage: Current main explicitly tests the ok-plus-failed/unknown-completion mapping.
Findings 1 actionable finding [P1] Preserve completion status during the rebase
Security None None.

Live Verification

Command: pnpm openclaw cron --help

Result: FAIL (failed) — execution before step 1 run: live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

Assertions:

  • FAIL expect_output: docs.openclaw.ai/cli/cron

How this fits together

Cron finalization writes both a generic task lifecycle record and cron-specific history detail after execution and delivery settle. A late cancellation must preserve the generic cancellation outcome while retaining the cron completion and delivery facts for history.

flowchart LR
A[Cron execution] --> B[Delivery settlement]
B --> C[Completion outcome]
C --> D[Finished cron event]
D --> E[Late task finalization]
E --> F{Task already cancelled?}
F --> G[Generic task reason]
F --> H[Cron history detail]
Loading

Before merge

  • Preserve completion status during the rebase (P1) - Current main persists completionStatus and maps an ok execution with failed or unknown completion to a failed task. This head has no such field and maps every ok result to succeeded; because the PR is conflicted, resolving with this codec would regress required-delivery failures. Retain the current pipeline and extend this regression to assert cancelled task state alongside completionStatus: "failed" history.
  • Resolve merge risk (P1) - A conflict resolution that retains the branch’s pre-completion codec would mark an ok execution with required delivery failure as succeeded.
  • Resolve merge risk (P1) - Production code grows by 8 lines; the added cron-owned execution error and summary fields are justified only if the rebase keeps one canonical detail representation rather than adding parallel state.
  • Complete next step (P2) - This maintainer-owned conflicted branch needs a deliberate rebase that preserves current main’s completion contract before normal review can continue.

Findings

  • [P1] Preserve completion status during the rebase — src/cron/task-run-detail.ts:201-202
Agent review details

Security

None.

PR surface

Source +8, Tests +14. Total +22 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 15 7 +8
Tests 3 24 10 +14
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 39 17 +22

Review metrics

Metric Value Why it matters
Production versus tests production +8 (15 added, 7 removed); tests +14 (24 added, 10 removed) The production growth separates generic cancellation state from cron-owned history detail and needs to survive the required-delivery rebase.

Merge-risk options

Maintainer options:

  1. Rebase on the completion contract (recommended)
    Retain current main’s completionStatus flow and add the combined cancellation-plus-failed-delivery regression before merging.
  2. Pause the stale branch
    Leave this PR unmerged if the cancellation repair cannot be rebased without preserving the current delivery-completion semantics.

Technical review

Best possible solution:

Rebase the cancellation-only change onto current main, retain completionStatus authoring, persistence, and mapping, then add one combined regression for cancelled task state plus failed delivery completion in history.

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

Yes, source-reproducible: current main shows the completion path that the branch lacks, although no test was run in this read-only review.

Is this the best way to solve the issue?

No: preserving cancellation ownership is the right direction, but this stale branch is not the best complete fix until it retains current main’s completion-status pipeline and proves both outcomes together.

Full review comments:

  • [P1] Preserve completion status during the rebase — src/cron/task-run-detail.ts:201-202
    Current main persists completionStatus and maps an ok execution with failed or unknown completion to a failed task. This head has no such field and maps every ok result to succeeded; because the PR is conflicted, resolving with this codec would regress required-delivery failures. Retain the current pipeline and extend this regression to assert cancelled task state alongside completionStatus: "failed" history.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded cron task-history correctness repair with an operator-visible outcome, but not an emergency runtime failure.
  • merge-risk: 🚨 compatibility: Task terminal-state and persisted cron-history semantics can regress for existing required-delivery jobs if the stale branch codec wins the conflict.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its stated focused tests remain supplemental and must be rerun on the rebased head.

Evidence

What I checked:

  • Current completion contract: Current main derives completion only after execution and delivery settle, including a failed required delivery. (src/cron/service/timer-job-runner.ts:464, 5775cd3dfaf4)
  • Current persistence and task mapping: Current main persists completionStatus in cron detail and maps an ok execution with failed or unknown completion to a failed generic task state. (src/cron/task-run-detail.ts:211, 5775cd3dfaf4)
  • Current regression coverage: Current main explicitly tests the ok-plus-failed/unknown-completion mapping. (src/cron/task-run-history.test.ts:102, 5775cd3dfaf4)
  • Branch omits completion status: The PR head maps every ok cron event to succeeded and has no completionStatus occurrence under src/cron, so it predates the current contract. (src/cron/task-run-detail.ts:299, 8ac01c3286c9)
  • Current-area provenance: Available shallow-history blame attributes the current completion, detail, and terminal-finalization surface to the current-area author; deeper history is unavailable locally. (src/cron/task-run-detail.ts:211, c7f70f338ac1)
  • Merge state: The supplied GitHub state reports this head as conflicted/dirty, so the completion contract must be deliberately retained during rebase.

Likely related people:

  • steipete: Current-main blame attributes the completion/detail/finalization surface to this author, who also authored the proposed repair. (role: current-area contributor; confidence: high; commits: c7f70f338ac1, 8ac01c3286c9; files: src/cron/service/timer-job-runner.ts, src/cron/service/task-runs.ts, src/cron/task-run-detail.ts)

Rank-up moves

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

  • Rebase while retaining current main’s completionStatus authoring, detail persistence, and task-state mapping.
  • Add a combined regression proving the cancelled task reason remains visible while history records required delivery as failed, then rerun it on the exact head.

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 (6 earlier review cycles)
  • reviewed 2026-08-17T20:41:08.890Z sha 8ac01c3 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T04:14:53.946Z sha 8ac01c3 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T04:57:41.552Z sha 8ac01c3 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T04:05:07.382Z sha 8ac01c3 :: found issues before merge. :: [P1] Preserve the completion-status contract during the rebase
  • reviewed 2026-08-23T04:46:12.868Z sha 8ac01c3 :: found issues before merge. :: [P1] Preserve completion status during the rebase
  • reviewed 2026-08-24T06:23:09.608Z sha 8ac01c3 :: found issues before merge. :: [P1] Retain the completion-status contract during rebase

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed 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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 22, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Superseded by #129331.

The replacement preserves this PR's original author attribution, rebases the cancellation-reason repair onto current completionStatus semantics, and adds the combined cancelled-task plus failed-required-delivery regression requested by ClawSweeper. The original shared ordering now fails before the production fix and passes on the replacement head; the broader cron owner/sibling suite passes 140/140.

Closing this stale, conflicting source PR in favor of the takeover-ready replacement.

@RomneyDa
RomneyDa deleted the recovery/cron-cancellation-outcome-20260817 branch October 22, 2026 00:24
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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants