Skip to content

fix(cron): start forced automations after the requesting turn ends - #188513

Merged
steipete merged 1 commit into
mainfrom
codex/forced-run-after-turn
Oct 30, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/forced-run-after-turn

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes a same-session automation's “run it now” request being silently skipped as soon as the requesting agent turn ends.

User Impact

An authorized run-now request starts after the requesting turn finishes. If the job is disabled, removed, or otherwise cannot start, the owning conversation receives a short notice with the reason and a next step. Request-time cron.* permissions and the scheduled job's live owner/grant checks remain enforced.

Why This Change Was Made

Enqueueing is the manual request's authorization boundary. The queue previously retained and rechecked the requesting tool turn's authority after waiting for that same turn to end, making the handoff fail by construction. Accepted runs now use the existing scheduled execution authority. Event-ingress transfer and on-exit source custody retain their separate checks.

Non-start outcomes use the existing cron conversation-result commit, including its idempotency and transcript-generation checks. No new queue, recovery owner, persisted shape, configuration, or dependency is introduced. Force-running a job that was already disabled remains supported; disabling it after enqueue prevents launch.

Evidence

Incident timeline, 2026-10-30 UTC: a daily job targeting the caller's session used 0 16 * * * and wakeMode: now. At 15:41:58.899 the agent requested runMode: force with timeoutMs: 1000 and received an enqueued receipt with the “starts after this turn” note. The turn ended at 15:42:01.874. At 15:42:02.034 the receipt finished skipped, with agent tool caller authority is no longer active and delivery not-started. No follow-up turn or conversation notice appeared.

The new regression runs a real agent turn and automations tool through an isolated Gateway against a synthetic HTTP Responses provider. On base 1d6f75fd745062cb4bf0ca94bc53b256d3659af5, it reproduced that exact skipped receipt and stopped after three provider calls. With the fix it completes a fourth call in a new turn in the same session. A second scenario disables the job before the caller ends: no agent turn starts, history records the skip, and the transcript contains exactly one notice.

  • Node and pinned Bun: OPENCLAW_VITEST_RUNTIME=<node|bun> OPENCLAW_E2E_USE_PREBUILT_DIST=1 node scripts/run-vitest.mjs src/gateway/cron-forced-after-turn.e2e.test.ts --maxWorkers=1 — passed. The prebuilt runtime was prepared by the initial normal E2E invocation; changed source workers were rebuilt and verified by the wrapper.
  • Focused cron admission, operator lifetime, stored command schedules, receipt finalization, manual tool authority, Gateway cron/notifications, and Gateway policy suites — passed after updating one assertion that pinned callback arity. Foreign-job runs and requests revoked before commit remain refused at request time.
  • pnpm tsgo:core; touched test projects test/tsconfig/tsconfig.core.test.services-cron.json and test/tsconfig/tsconfig.core.test.gateway-root.json; targeted Oxlint and formatting; one-file MDX check; git diff --check — passed.
  • Line-cap, max-lines, and test-line ratchets — passed without budget or baseline changes. An initial two-line growth in the oversized Gateway callback was removed by reusing its existing job snapshot instead of looking the job up twice more.
  • Independent local review: no actionable P0–P2 findings.

The diff adds 79 production lines, 7 net test lines, and one documentation line. The test increase replaces a mocked lifecycle test and the superseded caller-retention contract with the real Gateway handoff and notice proof. Most production growth is the previously missing conversation notice.

Notices are best effort through the existing result writer: a missing owning transcript or a generation change during commit is logged, while durable cron history remains authoritative. This does not add notice replay after a Gateway crash. No live Gateway or real user state was accessed; no deployment, release, or migration was performed.

@clawsweeper

clawsweeper Bot commented Oct 30, 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 gateway Gateway runtime size: M labels Oct 30, 2026
@steipete
steipete marked this pull request as ready for review October 30, 2026 16:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-30T16:24:13.800429Z 736e6a2 Draft marked ready
ℹ️ 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.

@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: 736e6a236c

ℹ️ 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".

if (
params.job &&
params.resolveCronAgent &&
(params.evt.status === "skipped" || (params.evt.status === "error" && params.runNotStarted))

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 Keep intentional scratch-empty skips silent

For a recurring job with payload.skipIfScratchEmpty: true, this condition turns every intentionally suppressed check into a conversation warning telling the user to resolve a cause and run it again. executeJobCore returns status: "skipped" with the summary Automation scratch is explicitly empty, and finalization publishes that outcome for scheduled runs too. The default proactive job enables this policy and runs every 30 minutes, so leaving its scratch empty now repeatedly appends notices despite there being nothing requiring attention. Exclude intentional policy skips from these failure notices, or scope the notices to explicitly requested runs.

Useful? React with 👍 / 👎.

Comment on lines +138 to +140
outcome.executionStarted === false
? { ...eventContext, runNotStarted: true }
: eventContext,

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 Propagate non-start metadata from preparation failures

When an accepted run fails during model selection or hits the setup watchdog before execution, the new conversation notice is still omitted. For example, resolveCronRunPreparation returns an error result when resolveCronModelSelection fails without setting executionStarted: false; runCronIsolatedAgentTurn and executeDetachedCronJob preserve that undefined value. The setup-timeout outcome in timer-job-runner.ts also omits the field. Consequently, this strict comparison never sets runNotStarted, and the notification dispatcher rejects these pre-execution errors. Propagate an authoritative non-start flag from those preparation and timeout paths so the newly promised failure notice covers them.

Useful? React with 👍 / 👎.

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR hands accepted manual automation runs to scheduled execution authority and adds conversation notices when runs cannot start.

Example: A daily automation scheduled at 16:00 is force-run from its owning conversation at 15:41.

  • Before: After the requesting turn ends, the accepted run is skipped because its tool caller authority has expired.
  • After: The automation starts in a new turn after the requesting turn finishes.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The central repair has meaningful Gateway coverage, but two notification defects and an authority-boundary proof gap prevent a pass.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An acknowledged run-now request silently disappears when its requesting conversation turn ends.
Reason: The reported failure is concrete, and the supplied maintainer-authored status establishes direction for handing accepted requests to scheduled authority.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep open: this PR addresses a current automation failure, but two notification defects need repair.

Priority: P2
Reviewed head: 736e6a236c2e5255b5582a29b2150aab1fc46cd9

Before merge

  • Add real behavior proof - Authority-chain proof required: the isolated Gateway harness demonstrates after-turn execution and a disabled-job refusal, but does not demonstrate rejection before privileged I/O when the job's stored operator authority is revoked during the accepted queue wait. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Keep intentional scratch-empty skips silent (P2) - This condition sends a warning for every skipped outcome, including scheduled jobs with payload.skipIfScratchEmpty. executeJobCore returns a normal skipped result when scratch is empty, and the default proactive job enables that policy with a default 30-minute cadence. An idle checklist therefore repeatedly appends a notice telling the user to resolve a cause and retry, although no action is needed. Exclude intentional policy skips using producer-owned classification, or restrict this notice to explicit run requests.
  • Propagate non-start metadata from preparation failures (P2) - The new notice requires executionStarted to be explicitly false, but resolveCronRunPreparation returns model-selection errors without that field and runCronIsolatedAgentTurn preserves the omission. The setup watchdog also creates error outcomes without it. An accepted run that fails before execution consequently records an error without the promised conversation notice. Mark these outcomes authoritatively at their producers rather than treating every undefined value as an unstarted run.
  • Resolve security concern: Verify scheduled authority after removing the queued caller guard - The manual commit guard is discarded at acceptance. Existing scheduled authority checks remain, but the supplied negative scenarios cover pre-commit refusal or withdrawal after preparation, rather than revocation of stored authority while this newly detached request waits.
  • Resolve merge risk - Before merge, the PR owner should verify that withdrawing the job's stored authority during the queue wait prevents privileged I/O after the requesting turn ends.

Findings

  • [P2] Keep intentional scratch-empty skips silent — src/gateway/server-cron-notifications.ts:581-584
  • [P2] Propagate non-start metadata from preparation failures — src/cron/service/timer-outcome-finalization.ts:138-140
  • [medium] Verify scheduled authority after removing the queued caller guard — src/cron/service/run-queue.ts:119

Tests

  • Missing end-to-end proof: The supplied evidence does not demonstrate stored-authority revocation during the accepted queue wait being rejected before privileged I/O.
Agent review details

How this fits together

The Gateway admits automation requests, the durable cron queue selects work, and the launcher executes under scheduled authority before recording history and publishing conversation results.

flowchart LR
  A[Requesting agent turn] --> B[Cron request admission]
  B --> C[Durable run queue]
  C --> D[Scheduled run launcher]
  D --> E[Agent execution]
  E --> F[Outcome finalization]
  F --> G[History and conversation result]
Loading

Technical review

Best possible solution:

Keep the scheduler handoff, classify non-start outcomes at their producers, and send actionable notices through the existing conversation-result writer.

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

The incident records an accepted request followed by an expired-caller skip, and current-main source shows the corresponding guard after the idle wait; the PR reports red-on-base and green-on-head Gateway coverage, which was inspected but not executed during this read-only review.

Is this the best way to solve the issue?

Moving the accepted request to the existing scheduler owner addresses the lifecycle mismatch without another queue or configuration option, but notice eligibility and producer metadata need correction.

Full review comments:

  • [P2] Keep intentional scratch-empty skips silent — src/gateway/server-cron-notifications.ts:581-584
    This condition sends a warning for every skipped outcome, including scheduled jobs with payload.skipIfScratchEmpty. executeJobCore returns a normal skipped result when scratch is empty, and the default proactive job enables that policy with a default 30-minute cadence. An idle checklist therefore repeatedly appends a notice telling the user to resolve a cause and retry, although no action is needed. Exclude intentional policy skips using producer-owned classification, or restrict this notice to explicit run requests.
    Confidence: 0.99
  • [P2] Propagate non-start metadata from preparation failures — src/cron/service/timer-outcome-finalization.ts:138-140
    The new notice requires executionStarted to be explicitly false, but resolveCronRunPreparation returns model-selection errors without that field and runCronIsolatedAgentTurn preserves the omission. The setup watchdog also creates error outcomes without it. An accepted run that fails before execution consequently records an error without the promised conversation notice. Mark these outcomes authoritatively at their producers rather than treating every undefined value as an unstarted run.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Verify stored authority across the queue handoff (recommended)
    Exercise an accepted same-session request whose stored operator authority is revoked while it waits, and demonstrate rejection before the final privileged effect.

Provenance checked

  • Manual request authority lifetime changes intended behavior with a stated reason (1125da0: Retain queued caller device authority through settlement so disconnect and actual revocation remain distinct; this PR explicitly changes acceptance to the handoff boundary.)
  • Worker queue and host launcher ownership keeps the original intent (0973bef: The worker owns durable queue order, capacity and activation; the host launcher consumes committed activations and invokes existing execution owners.)
  • Detached transcript-write lifecycle keeps the original intent (510beb8: Accepted runs must write results independently of the initiating turn's disposed transcript lifecycle; the production detachment remains and stronger Gateway coverage replaces its mocked regression.)

Testing

Proof path: in-process harness.

Security

Needs attention: The changed authority handoff needs queued-revocation proof; inspection established no concrete bypass.

Evidence

Security concerns:

  • [medium] Verify scheduled authority after removing the queued caller guard — src/cron/service/run-queue.ts:119
    The manual commit guard is discarded at acceptance. Existing scheduled authority checks remain, but the supplied negative scenarios cover pre-commit refusal or withdrawal after preparation, rather than revocation of stored authority while this newly detached request waits.
    Confidence: 0.87

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 718bd3d adds src/cron/service/run-queue-execution.ts:53 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 718bd3d69d29; files: src/cron/service/run-queue-execution.ts)
  • Ayaan Zaidi: Raw commit 8100c60 adds src/gateway/server-cron-notifications.ts:82 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8100c6008860; files: src/gateway/server-cron-notifications.ts)

PR surface

Source +79, Tests +7, Docs +1. Total +87 across 12 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 7 104 25 +79
Tests 4 134 127 +7
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 239 152 +87

Review metrics

Metric Value Why it matters
Production versus test growth Production +104/-25; tests +134/-127 Net production growth is 79 lines, mainly conversation notices; net test growth is 7 lines after replacing weaker lifecycle coverage with Gateway handoff scenarios.

Labels

Label changes:

  • add P2: The change repairs a specific manual-automation workflow with limited blast radius.
  • add merge-risk: 🚨 message-delivery: The new notice path repeatedly warns on intentional skips and suppresses notices for some genuine preparation failures.
  • add merge-risk: 🚨 security-boundary: Manual requests stop carrying their caller guard after enqueue, changing the authority boundary for delayed execution.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: The change repairs a specific manual-automation workflow with limited blast radius.
  • merge-risk: 🚨 message-delivery: The new notice path repeatedly warns on intentional skips and suppresses notices for some genuine preparation failures.
  • merge-risk: 🚨 security-boundary: Manual requests stop carrying their caller guard after enqueue, changing the authority boundary for delayed execution.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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.

Reviewed October 30, 2026, 12:38 PM ET / 16:38 UTC.

@steipete
steipete merged commit 32bff6b into main Oct 30, 2026
214 of 217 checks passed
@steipete
steipete deleted the codex/forced-run-after-turn branch October 30, 2026 16:56
shakkernerd added a commit that referenced this pull request Oct 30, 2026
Align manual cron fixtures and documentation with durable enqueue authority while retaining cleanup and eligibility controls.

Refs #188513.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…penclaw#188513)

A forced automation run requested from inside an agent turn, for a job that targets that same conversation, is deferred until the turn ends. Launch re-checked the requesting tool caller's authority, which had ended by construction, so every such run was skipped with "agent tool caller authority is no longer active" and the conversation got no notice (Team, 2026-10-30, Dependency Updater "do it now").

Request authority is now checked once at enqueue; launch uses the job's scheduled authority with the existing final eligibility check (job present, owner/source current, not disabled after enqueue). Skipped or unstarted runs post a notice in the owning conversation through the existing cron result writer. Unauthorized force requests and requests revoked before commit remain refused.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…law#188704)

Align manual cron fixtures and documentation with durable enqueue authority while retaining cleanup and eligibility controls.

Refs openclaw#188513.
RomneyDa added a commit that referenced this pull request Oct 31, 2026
Align manual cron fixtures and documentation with durable enqueue authority while retaining cleanup and eligibility controls.

Refs #188513.

(cherry picked from commit 4fba134)
Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 31, 2026
Backport main PR #188513 so a manual automation accepted by the scheduler no longer depends on the requesting tool generation after enqueue. Preserve event-ingress custody and the final live job eligibility checks.

Co-authored-by: RomneyDa <[email protected]>
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 gateway Gateway runtime merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant