Skip to content

fix(cron): keep automations running when their chat's id changes - #200396

Merged
obviyus merged 4 commits into
mainfrom
fix/cron-stop-by-cause
Nov 17, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix/cron-stop-by-cause

Conversation

@obviyus

@obviyus obviyus commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Automations created from a chat stop, and recurring watchers are disabled, when that chat changes while the automation runs.

Observed in production: a watcher was disabled twice in one day. Each time its condition aborted ~3.4 s in, ~0.1 s after another job started an isolated run (a new session).

Fix

  • restoreGatewayOperatorSource revokes only when the target chat is deleted (kind === "delete" for the target key). Edits, branch switches, resets and compaction keep the chat's authority; device, token, role, profile and grant revocation still end it through their existing subscriptions. The target type drops sessionId; the cron callers stop passing it.
  • classifyCronScriptFailure maps aborted to { kind: "aborted" }. The scheduler already treats that as an interrupted attempt: it does not count toward the failure streak and the next occurrence runs. Real script failures stay permanent. If the creator's authority was genuinely revoked, the next occurrence's source restore refuses it and that refusal still retires the job.
  • captureCronJobTurnTarget drops the transcript-id comparison and links the repair turn to its chat by key.

Not changed here: sandboxed stream automations pin the exact transcript in cron-stream-sandbox-authority.ts (follow-up). Plugin session work (service-session-work.ts) shares the subscriber but keeps its own transcript/lifecycle check at each use.

Production code: +13 / −20.

User impact

  • Editing a message, switching branches, resetting a chat or compacting it no longer stops the automations it created.
  • A watcher whose condition is interrupted runs again at its next occurrence instead of being disabled.
  • Deleting the chat still stops its running automations.
  • Already-disabled jobs are not re-enabled; run openclaw automations enable <id>.

Evidence

  • Regression tests, red on the merge base b4fc0534, green on this head:

    • operator-run-recovery.test.ts: key-linked authority stays current across an unrelated chat, a new transcript id and a reset, and is revoked when the chat is deleted (base: revoked at the edit).
    • timer-outcomes.regression.test.ts: a key-linked watcher whose condition ends aborted stays enabled and scheduled; internal_error still disables it (base: aborted disabled it).
  • Touched and consumer suites pass on this head (ocx test): operator recovery, operator cancellation, cron operator source, repair notifications, isolated operator continuation/child/bind-parent, trigger evaluation, failure alerts, failure text, server-cron, outcome regressions. operator-run-cancellation.test.ts now cleans up the sender's run session with the real delete (run-continuation-cleanup.ts deletes it) instead of a transcript-id replacement.

  • config/session-identity-allowlist.txt shrinks 6584 → 6580 pins: cron-job-turn-target.ts no longer compares an identity, and operator-run-recovery.ts drops two comparisons.

  • Real Gateway from source (ocx src, isolated state, openai/gpt-5.6-luna), base vs head. The agent creates a 30 s condition watcher (sleep 20 in the condition) from its own chat; the harness waits until a condition is running, then mutates the owner chat:

    Event while a condition is running Base b4fc0534 Head
    Message edit (sessions.rewind + resend) condition aborted; watcher disabled after 1 evaluation condition completes (×3)
    Reset (sessions.reset) not reached (already disabled) condition completes
    Another chat created not reached condition completes
    Final job state enabled=0, cron trigger evaluation failed (aborted) enabled=1, 0 errors, 6 evaluations

    A second, unsynchronized base run reproduced the same disable at the first edit that landed during a condition (abort in the same second as the edit).

- A running automation's restored authority ended on any identity change to its chat
  (edit, branch switch, reset, compaction, key move, and before #200314 any new chat).
  It now ends only when that chat is deleted; edits, resets and compaction keep it.
- Failure-repair turns compared a transcript id that key-linked sources no longer
  record, so every repair turn was silently downgraded to non-owner. Removed.
- An aborted condition or script was classified permanent, which disabled
  operator-source jobs after one abort. An abort now ends only that attempt.
@clawsweeper

clawsweeper Bot commented Nov 17, 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 size: S labels Nov 17, 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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head b9445a45ace8dd53d0625e2fb52a89ed35877264, but the PR head is now 812c5fa4494bfffaecbaa33e1715081c9953bc9b. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-17T04:02:51.203Z sha b9445a4 :: needs changes before merge. :: [P2] Migrate the remaining caller of the narrowed target type | [P2] Update the detached-turn consumer to exercise actual deletion | [P2] Regenerate the identity baseline after removing comparisons

- Drop the retired sessionId from the remaining target literals (perf script, test).
- Clean up the sender's run session with the real delete in the cancellation test;
  the file moves to the database-worker lane that lifecycle deletes need.
- Shrink the session-identity allowlist (6584 -> 6580 pins).
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 17, 2026
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 17, 2026
- Deleting the chat revoking key-linked authority is covered in operator-run-recovery.test.ts;
  the remaining rows prove accepted turns keep their authority when the occurrence retires.
- The file stays in its original test lane.
@obviyus
obviyus merged commit 346d231 into main Nov 17, 2026
120 checks passed
@obviyus
obviyus deleted the fix/cron-stop-by-cause branch November 17, 2026 05:11
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 346d231.

  • Bug: a running automation's authority was revoked when its own chat was edited, reset or compacted while a condition or script ran. The aborted check was then classified permanent, so a recurring watcher was turned off after one interrupted run. Failure-repair turns also ran as non-owner.
  • Fix: authority ends only when the chat is deleted; an aborted attempt no longer retires the job; repair turns follow the chat by key.
  • Proof: regression tests red on the merge base; on an isolated real Gateway, an edit during a running condition disabled the watcher on base, while on head three edits, a reset and a new chat during running conditions left it enabled with zero errors.

Thanks @hannesrudolph for #200307 and #200314, which found the unrelated-chat case.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…nclaw#200396)

## Problem

Automations created from a chat stop, and recurring watchers are disabled, when that chat changes while the automation runs.

- A running automation restores its creator's authority through `restoreGatewayOperatorSource`. Its session-identity subscriber revoked that authority on any identity mutation that named the chat's key: a message edit (`sessions.rewind`), a reset, a compaction successor or a key move. Before openclaw#200314, creating any unrelated chat for the same agent also matched (`undefined === undefined`, openclaw#200307).
- A revoked condition or script ends as code `aborted`. `classifyCronScriptFailure` mapped `aborted` to `permanent`, and `applyJobResult` disables an `operatorSource` job on its first `permanent` error. One interrupted check therefore turned a recurring watcher off for good. openclaw#180891 intended the opposite: "Aborts (restarts, cancellation) are rethrown unchanged and stay retryable."
- Failure-repair turns compared the restored target's transcript id with the source's. Since openclaw#199512, key-linked sources no longer record that id, so the comparison was always unequal and every repair turn was silently downgraded to a non-owner.

Observed in production: a watcher was disabled twice in one day. Each time its condition aborted ~3.4 s in, ~0.1 s after another job started an isolated run (a new session).

## Fix

- `restoreGatewayOperatorSource` revokes only when the target chat is deleted (`kind === "delete"` for the target key). Edits, branch switches, resets and compaction keep the chat's authority; device, token, role, profile and grant revocation still end it through their existing subscriptions. The target type drops `sessionId`; the cron callers stop passing it.
- `classifyCronScriptFailure` maps `aborted` to `{ kind: "aborted" }`. The scheduler already treats that as an interrupted attempt: it does not count toward the failure streak and the next occurrence runs. Real script failures stay `permanent`. If the creator's authority was genuinely revoked, the next occurrence's source restore refuses it and that refusal still retires the job.
- `captureCronJobTurnTarget` drops the transcript-id comparison and links the repair turn to its chat by key.

Not changed here: sandboxed stream automations pin the exact transcript in `cron-stream-sandbox-authority.ts` (follow-up). Plugin session work (`service-session-work.ts`) shares the subscriber but keeps its own transcript/lifecycle check at each use.

Production code: +13 / −20.

## User impact

- Editing a message, switching branches, resetting a chat or compacting it no longer stops the automations it created.
- A watcher whose condition is interrupted runs again at its next occurrence instead of being disabled.
- Deleting the chat still stops its running automations.
- Already-disabled jobs are not re-enabled; run `openclaw automations enable <id>`.

## Evidence

- Regression tests, red on the merge base `a0d35bd4`, green on this head:
  - `operator-run-recovery.test.ts`: key-linked authority stays current across an unrelated chat, a new transcript id and a reset, and is revoked when the chat is deleted (base: revoked at the edit).
  - `timer-outcomes.regression.test.ts`: a key-linked watcher whose condition ends `aborted` stays enabled and scheduled; `internal_error` still disables it (base: `aborted` disabled it).
- Touched and consumer suites pass on this head (`ocx test`): operator recovery, operator cancellation, cron operator source, repair notifications, isolated operator continuation/child/bind-parent, trigger evaluation, failure alerts, failure text, server-cron, outcome regressions. `operator-run-cancellation.test.ts` now cleans up the sender's run session with the real delete (`run-continuation-cleanup.ts` deletes it) instead of a transcript-id replacement.
- `config/session-identity-allowlist.txt` shrinks 6584 → 6580 pins: `cron-job-turn-target.ts` no longer compares an identity, and `operator-run-recovery.ts` drops two comparisons.
- Real Gateway from source (`ocx src`, isolated state, `openai/gpt-5.6-luna`), base vs head. The agent creates a 30 s condition watcher (`sleep 20` in the condition) from its own chat; the harness waits until a condition is `running`, then mutates the owner chat:

  | Event while a condition is running | Base `a0d35bd4` | Head |
  |---|---|---|
  | Message edit (`sessions.rewind` + resend) | condition `aborted`; watcher disabled after 1 evaluation | condition completes (×3) |
  | Reset (`sessions.reset`) | not reached (already disabled) | condition completes |
  | Another chat created | not reached | condition completes |
  | Final job state | `enabled=0`, `cron trigger evaluation failed (aborted)` | `enabled=1`, 0 errors, 6 evaluations |

  A second, unsynchronized base run reproduced the same disable at the first edit that landed during a condition (abort in the same second as the edit).

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa pushed a commit that referenced this pull request Nov 19, 2026
…0396)

Automations created from a chat stop, and recurring watchers are disabled, when that chat changes while the automation runs.

- A running automation restores its creator's authority through `restoreGatewayOperatorSource`. Its session-identity subscriber revoked that authority on any identity mutation that named the chat's key: a message edit (`sessions.rewind`), a reset, a compaction successor or a key move. Before #200314, creating any unrelated chat for the same agent also matched (`undefined === undefined`, #200307).
- A revoked condition or script ends as code `aborted`. `classifyCronScriptFailure` mapped `aborted` to `permanent`, and `applyJobResult` disables an `operatorSource` job on its first `permanent` error. One interrupted check therefore turned a recurring watcher off for good. #180891 intended the opposite: "Aborts (restarts, cancellation) are rethrown unchanged and stay retryable."
- Failure-repair turns compared the restored target's transcript id with the source's. Since #199512, key-linked sources no longer record that id, so the comparison was always unequal and every repair turn was silently downgraded to a non-owner.

Observed in production: a watcher was disabled twice in one day. Each time its condition aborted ~3.4 s in, ~0.1 s after another job started an isolated run (a new session).

- `restoreGatewayOperatorSource` revokes only when the target chat is deleted (`kind === "delete"` for the target key). Edits, branch switches, resets and compaction keep the chat's authority; device, token, role, profile and grant revocation still end it through their existing subscriptions. The target type drops `sessionId`; the cron callers stop passing it.
- `classifyCronScriptFailure` maps `aborted` to `{ kind: "aborted" }`. The scheduler already treats that as an interrupted attempt: it does not count toward the failure streak and the next occurrence runs. Real script failures stay `permanent`. If the creator's authority was genuinely revoked, the next occurrence's source restore refuses it and that refusal still retires the job.
- `captureCronJobTurnTarget` drops the transcript-id comparison and links the repair turn to its chat by key.

Not changed here: sandboxed stream automations pin the exact transcript in `cron-stream-sandbox-authority.ts` (follow-up). Plugin session work (`service-session-work.ts`) shares the subscriber but keeps its own transcript/lifecycle check at each use.

Production code: +13 / −20.

- Editing a message, switching branches, resetting a chat or compacting it no longer stops the automations it created.
- A watcher whose condition is interrupted runs again at its next occurrence instead of being disabled.
- Deleting the chat still stops its running automations.
- Already-disabled jobs are not re-enabled; run `openclaw automations enable <id>`.

- Regression tests, red on the merge base `b4fc0534`, green on this head:
  - `operator-run-recovery.test.ts`: key-linked authority stays current across an unrelated chat, a new transcript id and a reset, and is revoked when the chat is deleted (base: revoked at the edit).
  - `timer-outcomes.regression.test.ts`: a key-linked watcher whose condition ends `aborted` stays enabled and scheduled; `internal_error` still disables it (base: `aborted` disabled it).
- Touched and consumer suites pass on this head (`ocx test`): operator recovery, operator cancellation, cron operator source, repair notifications, isolated operator continuation/child/bind-parent, trigger evaluation, failure alerts, failure text, server-cron, outcome regressions. `operator-run-cancellation.test.ts` now cleans up the sender's run session with the real delete (`run-continuation-cleanup.ts` deletes it) instead of a transcript-id replacement.
- `config/session-identity-allowlist.txt` shrinks 6584 → 6580 pins: `cron-job-turn-target.ts` no longer compares an identity, and `operator-run-recovery.ts` drops two comparisons.
- Real Gateway from source (`ocx src`, isolated state, `openai/gpt-5.6-luna`), base vs head. The agent creates a 30 s condition watcher (`sleep 20` in the condition) from its own chat; the harness waits until a condition is `running`, then mutates the owner chat:

  | Event while a condition is running | Base `b4fc0534` | Head |
  |---|---|---|
  | Message edit (`sessions.rewind` + resend) | condition `aborted`; watcher disabled after 1 evaluation | condition completes (×3) |
  | Reset (`sessions.reset`) | not reached (already disabled) | condition completes |
  | Another chat created | not reached | condition completes |
  | Final job state | `enabled=0`, `cron trigger evaluation failed (aborted)` | `enabled=1`, 0 errors, 6 evaluations |

  A second, unsynchronized base run reproduced the same disable at the first edit that landed during a condition (abort in the same second as the edit).

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 346d231)

Release adaptation: preserve retired session identity allowlist; apply deletion-only key guard to baseline subscriber and retain new regression.

Co-authored-by: RomneyDa <[email protected]>

Follow-up disposition: bounded pinned-main same-path audit recorded in the lane report; cross-lane changes remain parent-owned.

(cherry picked from commit 75f490aee889734669c4d8d718e4cbec0934491f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant