Repository navigation
fix(cron): keep automations running when their chat's id changes - #200396
Merged
Merged
Conversation
- 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.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Contributor
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
- 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).
- 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.
Collaborator
Author
|
Landed as 346d231.
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Automations created from a chat stop, and recurring watchers are disabled, when that chat changes while the automation runs.
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 fix: keep automations running when you open another chat #200314, creating any unrelated chat for the same agent also matched (undefined === undefined, [Bug]: Unrelated same-agent session creation aborts cron conditions and can disable watchers #200307).aborted.classifyCronScriptFailuremappedabortedtopermanent, andapplyJobResultdisables anoperatorSourcejob on its firstpermanenterror. One interrupted check therefore turned a recurring watcher off for good. fix(cron): preserve operator continuations across edits and restarts #180891 intended the opposite: "Aborts (restarts, cancellation) are rethrown unchanged and stay retryable."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
restoreGatewayOperatorSourcerevokes 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 dropssessionId; the cron callers stop passing it.classifyCronScriptFailuremapsabortedto{ 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 staypermanent. If the creator's authority was genuinely revoked, the next occurrence's source restore refuses it and that refusal still retires the job.captureCronJobTurnTargetdrops 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
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 endsabortedstays enabled and scheduled;internal_errorstill disables it (base:aborteddisabled 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.tsnow cleans up the sender's run session with the real delete (run-continuation-cleanup.tsdeletes it) instead of a transcript-id replacement.config/session-identity-allowlist.txtshrinks 6584 → 6580 pins:cron-job-turn-target.tsno longer compares an identity, andoperator-run-recovery.tsdrops 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 20in the condition) from its own chat; the harness waits until a condition isrunning, then mutates the owner chat:b4fc0534sessions.rewind+ resend)aborted; watcher disabled after 1 evaluationsessions.reset)enabled=0,cron trigger evaluation failed (aborted)enabled=1, 0 errors, 6 evaluationsA 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).