Skip to content

fix(cron): prevent late background turns after job timeouts - #180717

Closed
SYU8384 wants to merge 3 commits into
openclaw:mainfrom
SYU8384:codex/fix-cron-terminal-execution
Closed

SYU8384 wants to merge 3 commits into
openclaw:mainfrom
SYU8384:codex/fix-cron-terminal-execution

Conversation

@SYU8384

@SYU8384 SYU8384 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Related: #176511, #143355, #137274.

What Problem This Solves

Fixes additional model turns and repeated work when a scheduled job times out after launching background commands.

User Impact

Timeout, cancellation, and restart revoke the originating occurrence's background work and completion events. Retained process output remains inspectable. Already accepted exec follow-ups survive normal successful teardown, preserving the contract from #176511 and ordinary interactive completion behavior.

Maintainer decision still required: scheduler and native-command deadlines do not automatically replay a job after execution starts or a dispatched command's outcome remains unknown. Recurring jobs keep normal cadence; one-shots follow existing terminal-failure handling. Known pre-execution failures and provider transient retry classification retain recovery. This intentionally differs from the policy discussed in #137274; this PR remains a draft.

Why This Change Was Made

Use the existing active-job marker to capture one occurrence's cancellation lifetime beyond its first model invocation. Successful retirement transfers accepted follow-ups to the session controller without cancelling them; timeout/cancellation/generation changes still revoke the captured lifetime. A superseded occurrence cannot regain authority when its older cleanup runs.

Originating-run liveness is still checked until event acceptance. Current destination and policy checks remain active afterward. Existing occurrence admission and completion source-run attribution are preserved. #143355 covers complementary child timeout propagation.

No public API, configuration, dependency, or schema changes. Upstream integration removes its retired conversation-origin field while preserving both notification-lifetime cleanup fields. The retry documentation now distinguishes scheduled execution deadlines from provider failures and forced manual runs.

Evidence

  • Review regression reproduced red against the original PR source: a real exec completion was accepted while its source turn was held, then successful marker teardown cancelled it before model execution.
  • 95 affected tests pass on the integrated head across active-job authority, real process/session-controller follow-ups, producer cancellation/recovery, and native child effects. Cases cover normal success, timeout, operator cancellation, restart, retirement before/during acceptance, and supersession. The supersession case was also reproduced red before its repair.
  • Current-head core types, targeted lint, oxfmt/Bun parity, documentation MDX sanity, and whitespace checks pass. Independent review found no remaining P0-P2 issues in the upstream integration and retry documentation. The maintained runtime build passes. Previous-head focused test type graphs, line-cap guard, and full build also passed; broad GitHub CI subsequently passed on that head.
  • Shipped CLI trace: a separate Gateway process ran synthetic cron jobs through public CLI/RPC and a loopback Responses provider that actually requested background exec. No production profile or paid provider was used.
timeout: provider requests=2; child stopped=true;
         late child effects=0; late inference=0; cron outcome=error
success: provider requests=3 (2 source + 1 exec completion);
         child effects=1; queued follow-ups=1; cron outcome=ok

The success trace holds the source response until the child completes and notification admission has time to finish; the third provider request must contain both the exec-completion notice and the child's output. The real queue regression separately proves explicit successful marker teardown before follow-up execution. An initial delivery:none fixture intentionally disabled wakes; a second fixture released the source before asynchronous acceptance. Those failed fixtures were diagnosed and retained, not reported as passes.

Fresh-install and latest-stable state compatibility: Separate foreground Gateways exercised both a fresh candidate and published 2026.10.6 followed by the candidate's documented manual runtime replacement (doctor --fix, then restart with the same isolated state). Existing one-shot/recurring settings and full successful run history were preserved. Actual scheduled model-started timeouts disabled the one-shot and advanced the daily recurring job to its normal future occurrence. Restart preserved those terminal histories, enablement, and exact next scheduled time, with zero new provider requests. Each lane made four job requests (two successes, two timeouts) and one separately identified, expected main-session auto-disable notice. This is runtime/state compatibility proof, not a published updater-driver activation test or qualification of every historical schema.

The private compatibility fixture first used forced manual runs, which intentionally preserve future slots; it was corrected to use real scheduled firing. An extra request was traced to the exact synthetic auto-disable notice, not counted as a job replay. The final proof rejects unexpected requests and checks persisted next-run times so a delayed replay cannot pass unnoticed.

CI: The complete GitHub CI run passed on a0b68f6 (run); the review of that head reported no code findings. That is prior-head evidence. This integrated head must receive its own CI/review results; draft status is preserved, so some lanes may skip. A separate aggregate status was pending when inspected. Earlier inherited local planner/root-budget and UI-suppression failures remain recorded as historical gaps, not current-head passing claims; no baselines were weakened.

Local test cost

The current six-file affected run passed 95 tests in 100.76 seconds with one worker across three shards, including compiled-subprocess preparation, real child processes, controller custody, and scheduler/native-command deadline handling. The earlier four-file repair run passed 67 tests in 63.60 seconds.

Merge Danger

Door: two-way. Blast radius: cron-owned child processes, completion admission, and deadline retry scheduling. Keep draft until maintainers accept the retry policy and required review/CI gates are satisfied.

@clawsweeper

clawsweeper Bot commented Oct 22, 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 gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 22, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR binds background commands and completion events to their cron occurrence and prevents automatic timeout retries after execution starts.

Example: A daily automation launches background exec and reaches its execution deadline.

  • Before: The background command can continue, trigger another model turn, and be followed by a timeout retry.
  • After: The occurrence cancels its background work and completion events, and the automation waits for its next daily occurrence.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Behavior and stable-state upgrade evidence address the previous proof gap, and no code defect remains identified; unresolved retry direction caps overall readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied public CLI/RPC output exercises a separate Gateway and loopback provider requesting real background exec, showing stopped children and no late effects or inference after timeout, plus one successful completion follow-up; real-owner regressions cover queued cancellation, restart, and supersession.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: A timed-out scheduled job can leave background commands and completion turns doing additional work.
Reason: Occurrence containment has clear value, but the bundled retry-default change alters an existing recovery contract without an owner decision.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR contains useful cron lifetime repairs and no identified code findings; its deliberate change to timeout retry behavior still needs a maintainer decision.

Priority: P1
Reviewed head: 86aca18150db1b7aaff9e7bc9fc9607097fed0c7
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should started scheduler and native-command timeouts disable one-shots and skip recurring retry backoff, or should this PR preserve the existing timeout retry policy?
  • Recommendation: Preserve retries in this repair: Keep the occurrence cancellation and successful-follow-up fixes, and separate the timeout retry-policy change for an explicit product decision.
  • Why: The PR deliberately changes documented recovery behavior, explicitly requests this decision, and has no recorded maintainer approval; fix(cron): keep timeout retries behind the run-receipt settlement fence #137274 proposes preserving retries instead.

Before merge

  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Agent review details

How this fits together

The cron scheduler owns occurrence cancellation and outcomes; exec consumes that lifetime when launching processes and handing completion events to the session controller.

flowchart TD
  A[Scheduled automation] --> B[Cron occurrence owner]
  B --> C[Agent execution]
  C --> D[Background exec process]
  D --> E[Session completion queue]
  B --> F[Cancellation lifetime]
  F --> D
  F --> E
  B --> G[Outcome and retry scheduling]
Loading

Technical review

Best possible solution:

Land the occurrence-lifetime repair with existing retry behavior unless the cron owner explicitly approves the proposed timeout policy.

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

Current-main exec ownership lacks the occurrence cancellation lifetime added here; source tracing and the supplied Gateway trace establish the path, while this read-only review executed no target code.

Is this the best way to solve the issue?

Reusing the active-job marker, exec cancellation owner, and session controller is a focused solution; suppressing timeout retries is a separate policy choice rather than a necessary consequence of cancellation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit aee987f adds src/agents/bash-tools.exec-notify.ts:338 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: aee987f3b95d; files: src/agents/bash-tools.exec-notify.ts)
  • weiqinl: Raw commit 461c6b0 adds src/agents/bash-tools.exec-notify.ts:51 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 461c6b0258ed; files: src/agents/bash-tools.exec-notify.ts)
  • Shakker: Raw commit 147df8d adds src/agents/bash-tools.exec-notify.ts:333 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 147df8d9edf5; files: src/agents/bash-tools.exec-notify.ts)

PR surface

Source +134, Tests +722, Docs +2. Total +858 across 18 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 10 148 14 +134
Tests 7 851 129 +722
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 1002 144 +858

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +148/-14; tests +851/-129 Production growth carries occurrence lifetime through existing exec and scheduler owners; test growth covers distinct process, queue, restart, supersession, and scheduling boundaries.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Timed-out automations can leave background work running and initiate additional model work after the occurrence should have stopped.
  • merge-risk: 🚨 compatibility: Existing scheduled jobs change timeout recovery behavior: affected one-shots disable and recurring jobs lose timeout retry backoff.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • 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-22T15:21:14.757Z sha dde7cce :: needs real behavior proof before merge. :: [P1] Preserve accepted follow-ups when a cron occurrence succeeds
  • reviewed 2026-10-22T16:12:31.282Z sha a0b68f6 :: needs real behavior proof before merge. :: none

Reviewed October 22, 2026, 1:39 PM ET / 17:39 UTC (Revision 3).

@SYU8384

SYU8384 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Fixed successful-teardown cancellation and superseded-occurrence revival in a0b68f6. Updated evidence includes red/green real-queue regressions, 67 affected tests, targeted static checks, and a shipped-CLI model-launched exec trace: zero late work after timeout and one successful completion follow-up. Retry-policy acceptance remains an explicit maintainer decision; this PR remains a draft.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. label Oct 22, 2026
@SYU8384
SYU8384 marked this pull request as ready for review October 22, 2026 16:31
@SYU8384
SYU8384 marked this pull request as draft October 22, 2026 17:15
@SYU8384

SYU8384 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Integrated upstream to resolve the exec-settlement conflict and updated the retry documentation. Current proof: 95 affected tests, core types, targeted lint/format, documentation sanity, runtime build, and the shipped-CLI background completion trace pass. Fresh candidate and published 2026.10.6 -> candidate state-upgrade checks preserve existing job settings/history; scheduled started timeouts do not replay, and restart preserves terminal outcomes and exact next-run times. The expected one-shot auto-disable notice is attributed separately from job requests. This is manual runtime/state upgrade proof, not updater-driver qualification. Retry-policy acceptance remains an upstream maintainer decision. Kept as a draft.

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 22, 2026
@SYU8384

SYU8384 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing this draft because #189469 settled the retry behavior: timed-out jobs remain eligible for retry after the original execution settles. #138499 still tracks whether a cron timeout should terminate an explicitly backgrounded command.

For a future fix, the paired Gateway regression checked both outcomes: timeout stopped the child with no late model turn, and success delivered the accepted exec completion exactly once.

@SYU8384 SYU8384 closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant