Skip to content

fix(cron): cancel removed conditions before main-session handoff - #138313

Merged
steipete merged 1 commit into
mainfrom
codex/qa-condition-cancellation-20260904
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-condition-cancellation-20260904

Conversation

@steipete

@steipete steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor
Additional instructions

Maintainers can update this branch through normal repository access.

What Problem This Solves

Fixes an issue where removing or disabling an automation during a main-session condition left its command running. Disabling could also enqueue the system event and record success after the operator had stopped the automation.

Why This Change Was Made

The scheduler previously chose cancellation lifetime from the eventual payload, leaving main-session conditions without a callback. The existing active marker and controller now own cancellation through condition evaluation, then release it synchronously before the main-session payload takes over. Shared heartbeat and detached payload lifecycles retain their existing ownership.

The duplicate heartbeat retry timer/listener and its single-use parameter are removed in favor of the existing abortable-sleep helper. Production: 25 added / 35 removed, net −10. Tests: net +135, including moved table indentation; documentation: +2. Configuration, stored formats, schema, migrations and delegated authority are unchanged.

User Impact

Removing or disabling a condition stops its pending command and prevents the canceled condition from starting the payload. Once a main-session heartbeat has already taken over, its request completes under the existing heartbeat lifecycle.

Evidence

  • Three actual regressions failed on the unchanged base: main-condition removal, disable, and cancellation requested before controller binding. Isolated-condition controls passed.
  • 130 focused tests across six suites pass, covering condition evaluation, timer ordering, active cancellation, heartbeat watchdogs and script wake behavior.
  • Seven normal Gateway scenarios with real foreground commands pass. Canceled commands do not perform delayed writes, canceled conditions do not enqueue payloads, and a healthy subsequent script still runs. Task-owned Gateways and listeners were closed.
  • Three additional normal Gateway controls hold real HTTP heartbeat requests at a synthetic local provider. Removing plain/condition jobs or disabling a condition job after handoff leaves the request active, produces no premature terminal record, and completes successfully after the provider responds. These controls also pass before the change. No external model-service claim.
  • Independent managed P2 review is clean (confidence 0.93). All 29 canonical changed checks passed in 517.88 seconds, with source hashes unchanged.
  • Mechanical refresh onto main 4a4b39734084529d59584fe9e7f184db3b1c3d09, after fix(cron): preserve the final reply after automation self-removal #138231 landed, preserves all six final files byte-for-byte. The published head is 091385547e0628503f555e0e1e70d9731d8958db. Required exact-head CI must pass before landing.

The first pre-bind fixture used an invalid schedule/condition combination and was corrected before production edits; the corrected regression then failed for the intended cancellation defect. Two rejected timer implementations did not cooperate with the existing fake clock. The final code uses the canonical helper and retains the original timing assertions, without a new mock or longer timeout.

Release-note context: stop removed or disabled automation conditions before they can execute delayed commands or start a main-session payload; preserve heartbeat completion after handoff.

@steipete steipete self-assigned this Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 14:15

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lifecycle boundary looks well chosen. Registering cancellation while the condition trigger owns the run, then releasing it only at onPayloadExecutionStarted, closes the gap where removal/disable could race the evaluator and still publish a late fire. The regression where the evaluator ignores abort but cannot publish is especially important. Reusing the shared abortable sleep also removes a bespoke cancellation path. I don’t see a blocking issue here.

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

The initial completed review is still missing. Exact-head CI for 091385547e0628503f555e0e1e70d9731d8958db passed in run33882682299 and native preparation passed. The body includes three before regressions,130 focused tests, seven normal Gateway command scenarios, three before/after HTTP heartbeat handoff controls, full changed checks and a clean independent review. Production is net−10. Native merge correctly stopped at the missing completed-review gate; no gate was bypassed.

@clawsweeper

clawsweeper Bot commented Sep 4, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 10:39 AM ET / 14:39 UTC.

ClawSweeper review

What this changes

The PR keeps cron cancellation active while a trigger condition runs, releases it before a main-session payload hands off to heartbeat, and adds regression coverage and documentation.

Merge readiness

✅ Ready for maintainer review

No blocking correctness or security finding. Current main still lacks cancellation binding for main-session trigger conditions; this PR adds it at the cron-run owner boundary and preserves the independent heartbeat lifecycle after handoff.

Priority: P1
Reviewed head: 091385547e0628503f555e0e1e70d9731d8958db

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, net-negative owner-boundary repair with direct regression coverage and no actionable review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This repository-member PR is exempt from the external-contributor proof gate; the captured PR body nevertheless reports real Gateway command and local-provider handoff scenarios aligned with the changed cron boundary.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This repository-member PR is exempt from the external-contributor proof gate; the captured PR body nevertheless reports real Gateway command and local-provider handoff scenarios aligned with the changed cron boundary.
Evidence reviewed 7 items Current-main gap: Current main registers an active cancellation handle only for payloads detached from the main session, leaving a main-session condition without a controller to abort.
Cancellation owner boundary: The introduced branch registers a controller for trigger conditions and passes its release callback only to non-detached payloads, so main-session conditions remain cancellable until payload entry.
Payload handoff: After trigger evaluation, the execution path checks for abort before synchronously releasing the condition handle and entering the payload path; main-session work then queues and invokes the heartbeat runner.
Findings None None.
Security None None.

How this fits together

Cron jobs can run a condition before dispatching a payload. Conditions need cancellation while they run; main-session payloads then queue work to the shared heartbeat lifecycle.

flowchart LR
  A[Cron schedule] --> B[Trigger condition]
  B --> C[Cancellation handle]
  C --> D{Condition fires?}
  D -->|No| E[Reschedule]
  D -->|Yes| F[Main-session payload]
  F --> G[Shared heartbeat]
  H[Operator remove or disable] --> C
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -10, Tests +135, Docs +2. Total +127 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 25 35 -10
Tests 2 232 97 +135
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 259 132 +127

Review metrics

Metric Value Why it matters
Production versus regression coverage production +25/-35 (net -10); tests +232/-97 (net +135); docs +2 The bug fix is net-negative in production while adding boundary regressions for cancellation, pre-bind, and handoff behavior.

Technical review

Best possible solution:

Land the owner-boundary cancellation lifetime: abort pending conditions on operator removal or disable, but leave already handed-off heartbeat work under its existing lifecycle.

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

Yes—source-reproducible: current main only creates a cancellable handle for detached payloads, while main-session conditions receive the abort signal only through that missing handle.

Is this the best way to solve the issue?

Yes—the fix attaches cancellation to the condition’s actual lifecycle owner and releases it synchronously at the existing main-session handoff, rather than adding a downstream suppression.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: Without this fix, removing or disabling an automation can still allow its pending condition to dispatch unattended work.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This repository-member PR is exempt from the external-contributor proof gate; the captured PR body nevertheless reports real Gateway command and local-provider handoff scenarios aligned with the changed cron boundary.

Label justifications:

  • P1: Without this fix, removing or disabling an automation can still allow its pending condition to dispatch unattended work.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This repository-member PR is exempt from the external-contributor proof gate; the captured PR body nevertheless reports real Gateway command and local-provider handoff scenarios aligned with the changed cron boundary.

Evidence

What I checked:

  • Current-main gap: Current main registers an active cancellation handle only for payloads detached from the main session, leaving a main-session condition without a controller to abort. (src/cron/service/timer-job-runner.ts:211, 523221e3767f)
  • Cancellation owner boundary: The introduced branch registers a controller for trigger conditions and passes its release callback only to non-detached payloads, so main-session conditions remain cancellable until payload entry. (src/cron/service/timer-job-runner.ts:211, 091385547e06)
  • Payload handoff: After trigger evaluation, the execution path checks for abort before synchronously releasing the condition handle and entering the payload path; main-session work then queues and invokes the heartbeat runner. (src/cron/service/timer-execution.ts:121, 091385547e06)
  • Regression coverage: The new service-boundary table covers remove and disable for main and isolated conditions, suppressing late evaluator results and payload effects; adjacent tests cover pre-bind cancellation and post-handoff heartbeat continuity. (src/cron/service.trigger-eval.test.ts:98, 091385547e06)
  • Abortable wait contract: The changed heartbeat retry path uses the local retry package's abortable sleep, which rejects with AbortError and clears its timer; the caller catches only that expected cancellation before its next abort check. (packages/retry/src/index.ts:21, 091385547e06)
  • Parentage and current-main status: The exact PR head has verified parent 4a4b397; current main contains that parent but not this head, and no later main change overlaps these cron paths. (src/cron/service/timer-job-runner.ts:211, 091385547e06)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Lee: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit 4b732d7 into main Sep 4, 2026
249 checks passed
@steipete
steipete deleted the codex/qa-condition-cancellation-20260904 branch September 4, 2026 14:44
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged in 4b732d72e65 from reviewed head 091385547e06.

Pending cron conditions now stop when the operator removes or disables their job. Cancellation ends at the main-session handoff, preserving the existing heartbeat lifecycle. The fix removes 10 production lines.

Validation includes 130 focused tests, seven normal Gateway command scenarios, three before/after HTTP heartbeat handoff controls, full changed checks, independent review and green exact-head CI. The completed ClawSweeper review has no findings. Main contains the landed commit and is clean.

The original completion-comment request received HTTP 403 after the confirmed merge. Read-only native reconciliation verified the landed tree and the absence of a completion marker; this records the administrative closeout.

vincentkoc added a commit that referenced this pull request Sep 4, 2026
…9-prep

* commit '407a8f453c0f0306af1ddc0aafa8697c1d49a9e7': (312 commits)
  perf(ui): coalesce automation event refreshes (#138065)
  fix: reject incomplete Skill Workshop directory reads (#138082)
  test(ui): decouple rendering checks from generated wording (#138283)
  perf: avoid temporary entries in bounded JSON traversal (#138017)
  fix(irc): render complete messages before splitting (#138328)
  perf: prepare worker trajectory payloads only for recorded events (#138086)
  fix(mcp): paginated listings no longer time out after a forward clock step (#137206)
  fix(codex): page native transcripts and bound UI previews (#136282)
  feat(gateway): apply more settings without restarting (#138112)
  fix(docs): preserve mirrored ClawHub maturity links (#138241)
  fix(test): own UI animation and legacy database setup (#138296)
  fix(tts): preserve literal directives in Markdown code (#138319)
  fix: load chat widgets behind authenticated gateways (#138074)
  chore(ui): cover native approval finalization (#137259)
  fix(cron): cancel conditions before main-session handoff (#138313)
  fix(backup): preserve text after embedded NUL characters (#138327)
  fix(android): align composer control sheets (#137442)
  fix(ci): wait for replacement PR runs instead of stale failures (#138307)
  fix(sessions): keep Gateway responsive with long transcripts (#138094)
  fix(computer): map window inputs to delivered image coordinates (#138271)
  ...

# Conflicts:
#	scripts/release-check.ts
#	test/release-check.test.ts
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
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 maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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