Skip to content

feat(cron): pause automations whose creating conversation is gone - #178965

Merged
jalehman merged 1 commit into
mainfrom
automations/scheduled-parent-pause
Oct 22, 2026
Merged

jalehman merged 1 commit into
mainfrom
automations/scheduled-parent-pause

Conversation

@jalehman

@jalehman jalehman commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #178933 and #179834 (both merged).

Related: #178812
Related: #178811

What Problem This Solves

Fixes: an automation keeps running after the conversation that created it has been removed or archived, acting on resources that conversation no longer has.

User Impact

User impact: an automation linked to the exact conversation that created it now pauses instead of running when that conversation is gone. "Gone" means the conversation was removed or archived, or its bound worktree no longer exists.

  • Nothing runs for that occurrence: no trigger script, payload or session turn.
  • The job is disabled, and the owning agent gets one notice that names the conversation and the openclaw automations enable <id> command. The notice goes to the agent, not to the gone conversation.
  • Restoring the conversation does not resume the job; re-enabling it does. The next occurrence checks the parent again, so a job whose parent is still gone pauses again with a new notice.
  • This applies to every executor: isolated, current, session:<key>, main, trigger and script jobs. An archived-parent session:<key> job used to fail with an error in session admission. It now pauses with the notice.
  • Command jobs never pause (decided by Josh Lehman, 2026-10-21). They still consume the occurrence and run as before. An admin archive through sessions.patch still disables bound jobs, as it does today.
  • A reset (/new) does not pause. That occurrence runs as an unbound parent with the existing (legacy) decisions: run-session board, memory and workspace, no parent-only grants, and nothing carried into the new conversation. The replacement conversation's worktree is ignored.
  • Automations without an exact parent link are unaffected: CLI- or operator-created jobs without --session-key, and older jobs that store only a session key.

Why This Change Was Made

  • One pause point. The occurrence admission from refactor(cron): admit each scheduled occurrence once #179834 already reads the parent row once. It now also reports pause when the parent is removed or archived, or a current parent's bound worktree is gone. executeJobCore checks it right after admission, before any trigger or payload work. The separate pre-session check in run-prepare and its second parent read are gone.
  • Reset. A changed session id or lifecycle revision isn't a pause. The builder rebuilds that occurrence as unbound-parent. A failed read never pauses.
  • Outcome. A pause returns a skipped outcome with a typed parentUnavailable fact. Cron's outcome owner disables the job and queues one notice. A pause is not a failure, so it settles before generic skipped-run alerting: a failureAlert with includeSkipped doesn't add a second notification. Both happen only when the outcome still owns the job's schedule (a newer operator edit wins) and the job was enabled before this outcome (one-shot jobs still get their notice).
  • Command jobs never pause. They run host commands and use none of the parent's access. They go through the admission like every other job, but resolvePausedOccurrence lets them run. No creation-time stamp is added.
  • No protocol change. The pause is a plain disable plus a notice, and the autoDisabled enum is unchanged.

Docs

docs/automation/cron-jobs/delivery.md describes the pause next to the auto-disable backstop, and troubleshooting.md explains how to recognize a paused job.

Evidence

  • src/cron/execution-context-admission.test.ts: removed and archived parents pause; a missing worktree pauses and names its path; a reset parent runs unbound, even when the replacement session's worktree is missing; a current parent; an unlinked job reads nothing; a failed read doesn't pause; the notice text.

  • src/cron/service/timer-execution.occurrence.test.ts: across the full payload × target × trigger matrix, a paused occurrence starts no executor. Command jobs still run.

  • src/cron/service/parent-pause.service.test.ts: through the real service and store, a forced run disables a recurring job without running it, and the notice is enqueued for the owning agent rather than the archived conversation. Re-enabling it pauses it again on the next run. A command job with a gone parent runs and stays enabled.

  • src/cron/service/timer-outcomes.regression.test.ts: one notice, one notice when an alert route also reports skipped runs, the one-shot notice, and a stale outcome yielding to a newer operator edit.

  • run.session-workspace-authority.test.ts: an archived-parent session:<key> job is skipped with the notice, without reading files.

  • QA scenario qa/scenarios/scheduling/cron-archived-parent-pause.yaml, run with pnpm openclaw qa suite --scenario cron-archived-parent-pause --provider-mode mock-openai against a real Gateway child: the run with a current parent reaches the model (1 job-prompt request at the mock provider), and after archiving, the forced run is skipped with the notice, the job is disabled, and the mock provider receives no further request for the job's prompt (1 → 1). Pass, 16 s. Inverting the final-effect assertion makes the scenario fail, so the check is live.

  • test/scripts/cron-context-replay.test.ts: a changed lifecycle revision now replays as a ready unbound-parent occurrence.

  • Local, after the rebase onto main: tsgo:core, tsgo:scripts, tsgo:test:src, tsgo:test:root and tsgo:extensions are clean; type-aware oxlint, oxfmt, the mock-exports and line-cap ratchets pass. Vitest over every changed test file plus the occurrence, admission, plugin-command, server-cron and replay suites: 301 of 301 pass.

  • PR CI on 35ae687ffa2: every check passes (71 pass, 53 skipping).

@clawsweeper

clawsweeper Bot commented Oct 21, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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:feature Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR pauses parent-linked automations before execution when their creating conversation is removed, archived, or loses its worktree.

Example: Nightly ingest is linked to agent:main:dashboard:parent, which is archived before its next occurrence.

  • Before: The automation can continue executing or fail later in session admission.
  • After: The occurrence is skipped, the automation is disabled, and one recovery notice targets the owning agent.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful and supported by production-entry-point evidence, with both prior correctness findings resolved and one redundant helper test.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied real Gateway QA run exercises occurrence admission through shipped RPCs and observes one successful current-parent model request followed by an archived-parent skipped, disabled occurrence with no additional job-prompt request; service coverage supports the notice-routing repair.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: An automation can outlive its creating conversation and continue running against resources that are unavailable.
Reason: The maintainer-authored direction supplies clear lifecycle behavior and recovery using existing owners, with documented command and reset exceptions.

Merge readiness

✅ Ready for maintainer review

Keep this PR open for merge: the pause behavior is useful, both prior findings are resolved, and no introduced correctness defect remains; current-head CI is still pending.

Priority: P2
Reviewed head: b7990b0a225c89a3215cc9b4c038a3a7d16e14d4

Before merge

None.

Findings

None.

Tests

  • Low-value test src/cron/execution-context-admission.test.ts: Remove the helper-only 'names the parent and the repair in the notice' test: the Gateway scenario already checks these same user-visible notice fields through cron.run.
Agent review details

How this fits together

Cron admits stored automations using current parent-session facts, then either starts their executors or finalizes a skipped occurrence and dispatches its notification.

flowchart TD
A[Stored automation] --> B[Occurrence admission]
C[Parent session facts] --> B
B --> D[Trigger and payload execution]
B --> E[Parent unavailable outcome]
E --> F[Disable automation]
F --> G[Owning agent notification]
Loading

Technical review

Best possible solution:

Keep parent pausing in occurrence admission and disablement plus owning-agent notification in the existing outcome owner.

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

Current main admits occurrences without enforcing the parent-pause result, and the supplied Gateway run demonstrates the changed behavior; this read-only review executed no target code.

Is this the best way to solve the issue?

The change uses the existing shared admission, transactional outcome, and notification owners, providing the smallest complete pause path without another scheduler or persisted state model.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Raw commit c730759 adds src/cron/execution-context-admission.ts:195 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c73075978be8; files: src/cron/execution-context-admission.ts)
  • saftall: Raw commit 053cf12 adds src/cron/service/timer-outcomes.ts:248 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 053cf12a7a0e; files: src/cron/service/timer-outcomes.ts)

PR surface

Source +110, Tests +339, Other +186. Total +635 across 15 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 7 139 29 +110
Tests 7 349 10 +339
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 186 0 +186
Total 15 674 39 +635

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 message-delivery: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a scoped automation lifecycle improvement with explicit recovery and limited impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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 (3 earlier review cycles)
  • reviewed 2026-10-21T03:02:59.812Z sha 55fe6dc :: needs real behavior proof before merge. :: [P2] Select one notification for a parent pause
  • reviewed 2026-10-22T13:54:10.225Z sha 985c8e1 :: needs changes before merge. :: [P2] Deliver the pause notice outside the unavailable conversation
  • reviewed 2026-10-22T14:02:08.870Z sha 985c8e1 :: needs changes before merge. :: [P2] Deliver the pause notice outside the unavailable conversation

Reviewed October 22, 2026, 10:21 AM ET / 14:21 UTC (Revision 4).

@jalehman
jalehman marked this pull request as draft October 21, 2026 06:31
@jalehman
jalehman force-pushed the automations/execution-context-foundation branch from 0944c7d to 3fa98ae Compare October 21, 2026 06:59
@jalehman
jalehman force-pushed the automations/scheduled-parent-pause branch from 55fe6dc to 6f07b34 Compare October 21, 2026 07:07
@jalehman
jalehman marked this pull request as ready for review October 21, 2026 15:16
@jalehman
jalehman marked this pull request as draft October 21, 2026 15:47
@jalehman
jalehman force-pushed the automations/scheduled-parent-pause branch from 6c9f35b to cd70797 Compare October 21, 2026 15:50
@jalehman
jalehman marked this pull request as ready for review October 21, 2026 15:58
@jalehman
jalehman marked this pull request as draft October 21, 2026 17:50
@jalehman
jalehman force-pushed the automations/execution-context-foundation branch from 3fa98ae to 178526d Compare October 21, 2026 18:03
@jalehman
jalehman force-pushed the automations/scheduled-parent-pause branch from cd70797 to b965e40 Compare October 21, 2026 19:52
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: XL and removed size: M labels Oct 21, 2026
@jalehman
jalehman changed the base branch from automations/execution-context-foundation to automations/occurrence-admission October 21, 2026 19:56
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 22, 2026
@jalehman

Copy link
Copy Markdown
Contributor Author

Addressed the review of 985c8e12d3f in b7990b0a225.

  • Deliver the pause notice outside the unavailable conversation (P2): fixed. When the job's sessionKey is the gone parent, the pause notice drops that key after resolving the owning agent: the explicit agentId, otherwise the agent named by that session key. enqueueCronNotification then targets the owning agent with createIfMissing and its resolved delivery context, instead of a session that admission rejects. A notice for a job whose sessionKey names some other session is unchanged.
  • Tests: parent-pause.service.test.ts drives a real forced run through the service and asserts the session event is enqueued for agent main with no session key and createIfMissing; it fails without the fix. timer-outcomes.regression.test.ts covers a job with no agentId whose parent is agent:ops:…: the notice goes to ops.

@clawsweeper re-review

@jalehman
jalehman force-pushed the automations/scheduled-parent-pause branch from 985c8e1 to b7990b0 Compare October 22, 2026 14:15
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 22, 2026
@jalehman
jalehman force-pushed the automations/scheduled-parent-pause branch from b7990b0 to 06c3406 Compare October 22, 2026 15:19
A job linked to the exact conversation that created it (sourceConversation or
a stored operator source) is now paused by its occurrence admission when that
conversation was removed or archived, or its bound worktree no longer exists.
Nothing runs for that occurrence: no trigger script, payload or session turn.
It is skipped with a notice that names the conversation and the re-enable
command, and the job is disabled so it sends that notice once. It resumes only
when re-enabled, and the next occurrence checks the parent again.

A reset (/new) parent keeps the automation running: that occurrence is built
as an unbound parent and takes the legacy decisions, with nothing carried into
the new incarnation. Command jobs never pause: they still consume the
admitted occurrence and run as before. Jobs without an exact parent link are
unaffected, and a failed read never pauses.
@jalehman
jalehman force-pushed the automations/scheduled-parent-pause branch from 06c3406 to 35ae687 Compare October 22, 2026 15:22
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 extensions: qa-lab P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

1 participant