Skip to content

fix: keep automations running when you open another chat - #200314

Merged
hannesrudolph merged 3 commits into
mainfrom
openclaw/glow-lobster
Nov 17, 2026
Merged

hannesrudolph merged 3 commits into
mainfrom
openclaw/glow-lobster

Conversation

@hannesrudolph

@hannesrudolph hannesrudolph commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Closes #200307

What Problem This Solves

Opening another chat while an automation is checking for updates can interrupt that check and turn the automation off. The CI checker also rejected the missing-ID safety check needed to repair this bug.

User Impact

Opening a separate chat no longer stops affected automations in this way. No settings changes are needed. Automations already switched off still need to be re-enabled.

The CI correction allows direct null/undefined presence checks while continuing to reject growth in real identity comparisons and explicit identity pins. No authorization rules, retry policy, or intended cancellation behavior are changed.

Why This Change Was Made

Two missing IDs were treated as a match, so creating an unrelated chat could cancel the automation. The existing guard prevents that false match. This PR now also corrects the CI checker: asking whether an ID exists is not the same as comparing it with another identity.

The allowlist is regenerated downward only, removing 318 false-positive counts across 205 entries. No allowance is increased, and the earlier session-continuity improvements are not reverted.

Evidence

  • 41 automation/operator-source tests passed, including real authority restoration and persisted SQLite session mutations: unrelated chat creation preserves authority; replacement of the relevant target still cancels it.
  • 6 checker/CI-orchestration tests passed. Both new checker regressions fail against the previous checker and pass with the correction. The boundary test also proves that adding a real identity comparison still fails.
  • The previously failing check:session-identity-ratchet passes locally against the PR base: 1,674 files, 6,587 grandfathered counts. All 205 changed allowlist entries strictly shrink.
  • Script and tooling-test typechecks, touched-file lint, formatting, and git diff --check passed.
  • Independent AutoReview of the complete expanded candidate, P0–P2: scoped-clean, no actionable findings.

Exact-head GitHub CI is pending. No full scheduled, model-driven Gateway run or production deployment is claimed.

Scope, provenance, and validation details
  • fix(cron): keep automations bound across message edits #199512 made the target ID optional while retaining the unguarded equality. refactor(sessions): follow the chat by key for stored delivery references #200099 added the initial CI checker; refactor(sessions): address chats by ChatRef, fence writers by lease, and stop refusing on captured ids #200191 broadened it to the comparison pattern that rejected this repair.
  • The checker remains its existing line-based lexical scanner; this change is not a parser rewrite. It retains adjacent real comparisons, explicit pin-name checks, and inference-refusal checks.
  • Six changed files overall: runtime guard, runtime regression, checker, checker regressions, shrink-only generated allowlist, and CI documentation. Runtime delta remains +2/-1 lines; checker delta +9/-2; test additions total 87 lines. No new owner or runtime abstraction.
  • Automation validation: node scripts/run-vitest.mjs src/gateway/operator-run-recovery.test.ts src/gateway/cron-operator-source.test.ts --maxWorkers=1 — 41 passed; runner wall time 107.38 seconds; new runtime regression 956 ms.
  • Checker validation: node scripts/run-vitest.mjs test/scripts/check-session-identity-ratchet.test.ts test/scripts/ci-baseline-ratchets.test.ts --maxWorkers=1 — 6 passed; runner wall time 1.35 seconds; new checker file 77 ms. CI timings are not yet available.
  • pnpm check:session-identity-ratchet --base df315eb3bb99eeb23e5395893e61a9e9daba80e3 --no-merge-base passes after generated pruning, without --prune.
  • Typechecks: node scripts/run-tsgo.mjs -p tsconfig.scripts.json --noEmit and node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.test.root.tooling.json --incremental.
  • AutoReview used Codex, GPT-6.1 Sol, medium reasoning, P0–P2, on the local candidate against df315eb3bb99eeb23e5395893e61a9e9daba80e3, committed as a706a5d9fbde3350c548c91e9e5c96ff9dc36b40. The reviewer assessed the supplied code and context; repository test execution and count validation were performed separately as recorded above.

Contributor: @hannesrudolph reported the issue, authored the original repair, and requested the expanded scope.

Work sessions

Linked for team reference; these sessions aren’t public.

@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: XS labels Nov 17, 2026
@hannesrudolph hannesrudolph changed the title fix(cron): keep checks running when unrelated sessions are created fix: keep automations running when you open another chat 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. labels Nov 17, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: M and removed size: XS labels Nov 17, 2026
@hannesrudolph
hannesrudolph merged commit 809b07c into main Nov 17, 2026
132 checks passed
@hannesrudolph
hannesrudolph deleted the openclaw/glow-lobster branch November 17, 2026 00:45
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
obviyus added a commit that referenced this pull request Nov 17, 2026
…0396)

## 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 #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).

## 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).

Co-authored-by: Ayaan Zaidi <[email protected]>
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 added a commit that referenced this pull request Nov 19, 2026
Co-authored-by: roboclaw-bot <[email protected]>
(cherry picked from commit 809b07c)

Release adaptation: Direct required companion to ChatRef cutover; absent transcript IDs no longer revoke unrelated automation roots.
Follow-up disposition: Presence-check ratchet and operator-source regression included; no broader authority policy change.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 24fc3d405f99acb29c46d0cb4db947eadcb73d4a)
RomneyDa added a commit that referenced this pull request Nov 19, 2026
Release adaptation: Regenerate the shrink-only ratchet after composing #200328 with #200191 and #200314. Only the obsolete update-doctor-result allowance is removed.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit cfcd57db7ed4758d2a6013f8f66fe1a84e13d015)
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

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. docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Unrelated same-agent session creation aborts cron conditions and can disable watchers

2 participants