Skip to content

fix(cron): stop waiting for run completion when interrupted - #186750

Merged
obviyus merged 3 commits into
openclaw:mainfrom
Alix-007:alix/fix-cron-wait-cancel-20261028
Oct 28, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
Alix-007:alix/fix-cron-wait-cancel-20261028

Conversation

@Alix-007

@Alix-007 Alix-007 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

After cron run --wait queues a job, Ctrl-C or SIGTERM leaves local history polling alive until the deadline and blocks root cleanup.

User Impact

Interrupting stops the local wait, without sending a cancellation request for the queued Gateway job. Completion, wait deadlines and output flushing retain their contracts. Both cron and automations aliases share the fix.

Why This Change Was Made

The waiter consumes the existing root command's cancellation signal for history RPCs, native interval delays and the final result check. Canceled waits return through normal root cleanup, preserving its 130/143 exit status. Like policy watch #186562 and voicecall tail #186691, waits and readback respect signal custody; this core command already has a root work-scope owner, so no competing listener or shared-supervisor change is added.

Evidence

#186750 (comment)

Normal built node openclaw.mjs CLI, secretless Linux Docker, Node 24.22.1, pinned main 89dd4bdf57e7fbed417762f786a75b4110eb3845 versus contributor product head f865181fc1aa78420a6987c82c5c33a8f43224f5. Main twice and candidate twice, both command aliases, with SIGINT/SIGTERM and completed/deadline/zero-duration/no-wait controls: 48 actual CLI processes. The owned loopback WebSocket fixture replaces only the remote service; parser, root cleanup, work scope, RPC client and waiter remain real. Requests are recorded to disk and independently reopened.

  • All 8 interrupted main processes stay alive >5s and keep polling (201 later requests aggregate). All 8 candidate processes naturally exit 130/143 in 20–32ms, exactly one history request, no later polls or final-result stdout. No job-cancel RPC is sent.
  • Completed controls exit 0 and flush succeeded/completed JSON; 250ms deadline controls exit 1 after two history requests; no-wait controls exit 0 with enqueue JSON and no polling, on both versions.
  • Zero-duration controls both exit 1: the existing 1ms RPC budget expires before history reaches the fixture. No new zero-timeout policy or successful first remote read is claimed.
  • Focused owner suite 62/62, final 1.87s; scoped lint and repository formatter parity pass. Sleep cancellation regression fails on pinned main because it remains unsettled (1 failed, 61 unselected, 3.69s).
  • Final head f8208cc2d0c70f9416533c065da753aab0e176af retains both contributor commits and only simplifies test fixtures; measured product code is unchanged. Removed over-configurable fixture/derived metadata, retained all 62 cases and owned drain. Actual signal exit-code ownership is proved in real processes instead of mutating a synthetic global code in unit tests. Production +14, tests −2, docs +2, no baseline change.

No real scheduler/model/provider executes; queued-job continuation is a product contract, not a live-job observation from this protocol fixture. Native Windows/macOS, interruption during enqueue, remote production Gateway and released upgrades are not claimed.

Merge Danger

Two-way door: revert restores prior local wait behavior without changing stored jobs, scheduling, RPC schemas or configuration. Blast radius is interrupted CLI completion waits; the queued Gateway job is not canceled, and existing completion/deadline/output behavior remains with its current owners.

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: S labels Oct 28, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Interrupting a cron completion wait stops local polling and returns through the CLI’s existing cleanup owner.

Example: Send SIGINT after openclaw cron run fixture-job --wait --poll-interval 100ms begins reading history.

  • Before: The CLI remains alive and continues polling after interruption.
  • After: The CLI exits with status 130 without further polling or final-result output.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrow repair using existing owners, supported by shipped-entry-point signal proof and distinct cancellation regressions.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied built-CLI capture exercises the changed waiter through the real parser, root work scope, RPC client, and native timers against a loopback WebSocket fixture on Linux Node 24.22.1. Both aliases stop after SIGINT/SIGTERM with 130/143, no later polls, and no final-result stdout; normal completion, deadline, and no-wait controls retain their outcomes. The final head changes tests only. Actual scheduler execution and queued-job continuation are explicitly not claimed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Ctrl-C or SIGTERM leaves a queued cron job’s local completion waiter polling instead of letting the CLI finish cleanup.
Reason: Prompt interruption restores the existing command lifecycle contract while preserving enqueue, scheduling, completion, deadline, and output behavior.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main cancellation defect with a focused change and no identified correctness findings; exact-head CI remains pending.

Priority: P2
Reviewed head: f8208cc2d0c70f9416533c065da753aab0e176af

Before merge

None.

Findings

None.

Agent review details

How this fits together

The cron CLI enqueues a Gateway job, polls history for its runId, and prints completion JSON; the root command owns interruption, cleanup, and exit status.

flowchart TD
 A[CLI cron or automations run] --> B[Gateway enqueue]
 B --> C[Completion waiter]
 C --> D[Gateway run history]
 E[Root cancellation signal] --> C
 C --> F[Output and root cleanup]
Loading

Technical review

Best possible solution:

Merge the focused waiter repair after the existing exact-head CI gates pass.

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

Current-main source shows the uncancelable polling path, and the supplied built-CLI comparison reproduces continued polling after SIGINT/SIGTERM on pinned main; no target code was executed during this review.

Is this the best way to solve the issue?

The smallest complete fix is to make the existing waiter consume root cancellation throughout RPC, delay, and result publication while preserving the root’s exit status; this diff does that without another lifecycle owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a1859e5195f6.

Provenance checked

  • Manual run completion waiting keeps the original intent (372a8e4: Provide deterministic completion waiting for shutdown hooks while keeping Gateway enqueue detached.)
  • Polling timer implementation keeps the original intent (c7aca4f: Consolidate identical non-abortable sleep wrappers while expressly leaving abortable timing semantics with their owners.)
  • Deadline and output finalization keeps the original intent (e888f38: Preserve complete piped JSON and original exit outcomes through shared one-shot finalization; earlier deadline bounds are also retained.)
  • Cron test fixture consolidation keeps the original intent (a8e4569: Reduce repeated setup while preserving distinct lifecycle and error contracts; the revised fixtures retain those assertions and add cancellation boundaries.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Brad: Raw commit 372a8e4 adds src/cli/cron-cli/register.cron-simple.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 372a8e4d2274; files: src/cli/cron-cli/register.cron-simple.ts)
  • Peter Steinberger: Raw commit 3e0d9a6 adds src/cli/cron-cli/register.cron-simple.ts:70 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3e0d9a6fd2df; files: src/cli/cron-cli/register.cron-simple.ts)
  • Alix-007: Raw commit 994d691 adds src/cli/cron-cli/register.cron-simple.ts:212 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 994d691dbf2b; files: src/cli/cron-cli/register.cron-simple.ts)

PR surface

Source +14, Tests -2, Docs +2. Total +14 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 21 7 +14
Tests 1 77 79 -2
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 100 86 +14

Review metrics

Metric Value Why it matters
Production versus tests Production +21/-7; tests +77/-79 The net production growth supplies cancellation at existing wait boundaries while test simplification offsets the added regression coverage.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Interrupted manual cron waits keep polling and delay command cleanup, with limited impact on an operator CLI workflow.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-28T12:48:07.453Z sha 5413abc :: needs maintainer review before merge. :: none
  • reviewed 2026-10-28T13:20:05.492Z sha f865181 :: needs maintainer review before merge. :: none

Reviewed October 28, 2026, 12:33 PM ET / 16:33 UTC (Revision 3).

@Alix-007

Copy link
Copy Markdown
Contributor Author

CI fixture repair at f865181fc1aa78420a6987c82c5c33a8f43224f5: consolidated the new tests without changing production code or removing cases/assertions. All 62 focused cases and targeted static checks pass. The body preserves the original runtime-proof SHA and explains production equivalence; fresh CI is pending.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Node 24 built-CLI signal proof

Current main 89dd4bdf57e7fbed417762f786a75b4110eb3845 versus contributor product head f865181fc1aa78420a6987c82c5c33a8f43224f5, normal pnpm build outputs in secretless Linux Docker Node 24.22.1, isolated synthetic HOME/config/state. Actual entry:

node openclaw.mjs cron run fixture-job --wait --wait-timeout 30s   --poll-interval 100ms --json --url "$OWNED_LOOPBACK_WS" --token "$SYNTHETIC_TOKEN"

The same matrix also runs the automations alias. Main twice and candidate twice, both aliases, each with SIGINT, SIGTERM, completed, deadline, zero-duration wait and ordinary no-wait controls: 48 real CLI processes. The fixture is only the remote Gateway WebSocket protocol boundary; parser, root command cleanup/work scope, RPC facade/client, native timer and waiter are real. Independently reopened disk recorder logs received cron.run/cron.runs requests.

Observation Main Candidate
SIGINT after first history response (4 processes/version) Still alive >5s after signal; continues polling until harness terminates stuck child Natural 130, one history request, zero later polls, no final-result stdout
SIGTERM after first history response (4 processes/version) Same failure Natural 143, one history request, zero later polls, no final-result stdout
Completed run, no signal (4/version) Exit 0, flushed JSON completed:true, succeeded Same
250ms deadline (4/version) Exit 1 after 2 history requests Same
Zero-duration wait (4/version) Exit 1; RPC's 1ms budget expires before a history request reaches fixture Same; no new timeout policy claimed
No wait (4/version) Exit 0, enqueued JSON, zero history requests Same

No job-cancel RPC occurs; only connect, enqueue and history methods are received. This is local waiter cancellation, not cancellation of the queued job. No real scheduler/model/provider executes, and actual job continuation is not claimed from a protocol fixture. Native Windows/macOS, release upgrades and interruption during enqueue are not claimed.

Like landed policy watch #186562 and voicecall tail #186691, waits consume one cancellation signal and check again before publishing results. This core CLI already has a root signal/work-scope owner: the patch reuses it instead of adding competing process listeners or changing a shared supervisor. Production remains the contributor's original correction.

Candidate signal exits are 20–32ms after delivery across all 8 interrupted processes; main remains alive 5481–5675ms and records 201 later history requests in aggregate before harness-only SIGKILL cleanup. Candidate records zero later requests.

Focused suite: 62/62 passed, final 1.87s; scoped lint and repository formatter parity pass. Sleep-cancellation regression on pinned main: 1 intended failure, 61 unselected, 3.69s, because the waiter does not settle after abort. Its inputs/logic are unchanged by the final type/table-only cleanup.

Simplification removes the over-configurable run-and-capture fixture and its derived metadata, using a queued-history fixture plus a concrete exit capture. All 62 cases remain, including clock rollback/deadline, stored failed completion and sleep/request/late-completion cancellation. Synthetic global process.exitCode mutation/checks were removed from the unit fixture: actual 130/143 ownership is instead established by the real built-root CLI matrix. Unit assertions still require prompt normal settlement, one history read, no output/error/exit call, and owned drain. Whole-PR tests are −2 lines (previously +47), production +14, docs +2; no baseline/ceiling change.

Final head f8208cc2d0c70f9416533c065da753aab0e176af preserves both contributor commits and changes tests only. Product code is identical to the newly measured f865181 build.

@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@obviyus
obviyus merged commit 6580ecf into openclaw:main Oct 28, 2026
115 checks passed
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Landed in 6580ecf. Thanks @Alix-007. cron run --wait now stops promptly on Ctrl-C or a service stop.

@Alix-007

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for reviewing and merging this. Much appreciated!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…#186750)

fix(cron): stop cron run --wait on Ctrl-C and SIGTERM

cron run --wait (and the automations alias) ignored SIGINT and SIGTERM while it polled for the job result, so it kept polling after Ctrl-C or a service stop. It now stops on the first signal, exits with the conventional status and prints no final result. It doesn't cancel the job itself, matching policy watch (openclaw#186562) and voicecall tail (openclaw#186691).

Evidence: built CLI on Node 24.22.1 with both aliases (48 real processes). On main the waiter stayed alive more than 5 s after each signal and made 201 more polls in total (twice each); with this change it exited with 130 or 143 in 20 to 32 ms, with no later polls, no final-result output and no cancel RPC (twice each). Completed, deadline, no-wait and zero-wait controls behave the same on both refs. The Gateway side was a recorded WebSocket fixture. Details: openclaw#186750 (comment).

Thanks @Alix-007.

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

Labels

cli CLI command changes docs Improvements or additions to documentation 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.

2 participants