Skip to content

fix(cron): continue scheduled turns interrupted by restart - #177127

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-restart-recovery-cron-delegated-authority-20260919
Oct 19, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-restart-recovery-cron-delegated-authority-20260919

Conversation

@steipete

@steipete steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes scheduled agent turns that never continue after a Gateway restart, including one-shot jobs whose interrupted run was disabled while session recovery reported delegated_authority_unavailable.

User Impact

An enabled, unchanged time-scheduled agent job interrupted before delivery gets one fresh retry through cron. The session records a visible handoff notice. Possible prior delivery, operator cancellation, edited or disabled jobs, and command/script/event/process-exit work retain their existing non-replay behavior. No configuration or schema migration is required.

Why This Change Was Made

Cron already persists the job's delegation, but its occurrence grant is process-scoped. Generic session recovery cannot borrow an earlier operator turn's authority. Preserve the typed restart outcome, finish the old receipt as interrupted, and schedule a fresh occurrence through cron's existing worker-owned receipt admission and current authorization checks. Release the single interrupted cron session claim so that admission can proceed.

The retry asks the agent to reconcile retained history and prior tool effects. Receipt uniqueness prevents duplicate retry admission; this does not promise exactly-once arbitrary external tool effects. Jobs already disabled by an older build require operator recovery.

Evidence

  • Three graceful-restart regression scenarios pass, including an earlier operator source and steering: one interrupted attempt, one authorized retry, no third attempt after another startup.

  • Crash recovery before delivery retries once; delivery already accepted is not replayed.

  • Core typecheck passed using tsrs. Export-name collision guard passed. Import-closure guards: 22 tests passed.

  • Focused startup recovery: 10 passed; delivery recovery: 7 passed; one-shot ownership and batch finalization: 29 passed. Changed-file lint, format, and diff checks passed. Independent autoreview found no actionable P0/P1 findings.

  • Live isolated Linux sandbox with a real openai/gpt-4.1 scheduled job: SIGTERM while its tool was running; shutdown recorded OPENCLAW_RESTART_ABORT. Boot recovery settled with reason=cron_interrupted, nextOwner=cron; cron retried after the standard 120-second startup delay. Result: 2 attempts, 1 completion, 1 interrupted receipt, 1 successful receipt. A third boot plus 130 seconds of observation produced no duplicate. The completed one-shot had no next run. All test Gateways exited cleanly.

  • Live proof used 077fcccbdfde plus the reviewed patch; the conflict-free rebase is covered by PR CI on c50e0d58b9d618024c2a3c620c27543e088c4592. No production state or service was modified.

  • Initial CI 39220863837 found two stale disabled-job expectations; both reproduced locally and were updated to the new scheduled retry contract. Manual non-replay checks remain green. Review also identified migrated receipts with unknown delivery state: new announce/webhook cases reproduced duplicate delivery, then passed after requiring an explicit not-started fact. The complete follow-up received a clean independent review.

Production LOC delta: +115. This growth carries the typed restart fact through existing adapters and checks the existing receipt's delivery/configuration facts in both graceful and crash recovery. There is no new recovery owner, sidecar, or durable state format. This is a correctness fix; no performance comparison is claimed.

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review ended

ClawSweeper stopped reviewing this revision because the pull request closed.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 19, 2026 08:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T08:40:32.684822Z c50e0d5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c3bee88f72

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cron/store/run-receipt-read.ts Resolved
@steipete
steipete force-pushed the steipete/perf-micro-restart-recovery-cron-delegated-authority-20260919 branch from c3bee88 to c50e0d5 Compare October 19, 2026 08:24
@steipete
steipete merged commit 2d3cb1c into main Oct 19, 2026
124 checks passed
@steipete
steipete deleted the steipete/perf-micro-restart-recovery-cron-delegated-authority-20260919 branch October 19, 2026 08:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c50e0d58b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +218 to +221
receipt.deliveryNotStarted === true &&
receipt.configRevision === resolveCronJobConfigRevision(job) &&
!job.state.runningScheduleChangeId
? resolveCronRestartRetryAtMs(job, runningAtMs, nowMs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Persist that the restart retry has already been spent

When the fresh retry is itself interrupted before delivery, its new scheduled receipt satisfies these same predicates again because no durable fact records that the one allowed retry was consumed; markInterruptedStartupRun simply replaces startupCatchupAtMs with another deadline. Consecutive restarts can therefore rerun a tool-bearing turn indefinitely and amplify duplicate external effects, rather than allowing only one fresh retry. Persist and consume a retry budget when scheduling the first replacement, and exclude that replacement's receipt from further automatic retries.

AGENTS.md reference: AGENTS.md:L95-L95

Useful? React with 👍 / 👎.

Comment on lines +234 to +237
if (job.state?.lastError === STARTUP_INTERRUPTED_ERROR) {
commandBody +=
"\n\nThe previous attempt was interrupted by a Gateway restart. Continue the unfinished task. " +
"Inspect the retained conversation and any tool effects before acting; do not repeat work or deliveries that already completed.";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Add continuation guidance only to the actual retry

When startup recovery sees a recurring agent turn whose delivery state is started/unknown or whose definition changed, it intentionally declines to schedule a retry but still records STARTUP_INTERRUPTED_ERROR as lastError. The next ordinary recurring occurrence then enters this branch and is instructed to continue the previous task, which can make it skip its new occurrence or duplicate prior effects even though replay was deliberately disallowed. Gate this guidance on a durable pending-restart-retry marker rather than historical lastError alone.

Useful? React with 👍 / 👎.

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 size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant