Skip to content

fix(cron): keep a started cron turn running when its job is edited - #207947

Merged
obviyus merged 1 commit into
mainfrom
fix/cron-midrun-source-recheck
Nov 29, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/cron-midrun-source-recheck

Conversation

@obviyus

@obviyus obviyus commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A started cron turn died when someone edited its job. Daily refusal watch, 2026-11-28:

[gateway] cron: job updated
[agent/embedded] session target preparation refused reason=scope_authority_refused
lane task error: lane=cron-nested durationMs=36667 error="Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed"

captureCronJobTurnTarget (src/gateway/cron-job-turn-target.ts) gave the session event target an assertCurrent that re-read the job on every fence check. It compared the stored operatorSource (or the scheduled requester) with the value captured at start. cron.update changes that value, so the next fence check threw. The run's assertScopeCurrent turned it into scope_authority_refused. The cron notice and failure-repair turns use this target. A repair turn that fixes its own job killed itself.

Root AGENTS.md "Decide authority once" does not allow this: authority is checked once, when work starts. The only stop after start is a permission writer stopping a named person's work. Editing a job is neither. This is the same class as R7 source_authority_refused (removed in #205268).

Change

  • Remove both job re-reads from captureCronJobTurnTarget: the operator-source comparison ("Automation operator source changed") and the scheduled-requester comparison ("Automation requester changed.").
  • The edited source applies from the next occurrence. Admission at that start decides it.
  • Kept: admission at start, data fences (attempt lifecycle, session identity, target fields), the run abort signal, and the cron remove/disable cancellation (active-job marker → run AbortController).
  • scope_authority_refused stays. The run-registry binding (source-closed) still produces it. scripts/lib/no-operator-permission-read.mjs lists no removed site.

What the user sees

A cron notice or repair turn finishes after the job is edited. Before, it failed with "This agent run is no longer active. Start a new turn to retry."

Evidence

  • New test keeps a started cron turn running when its job is edited (src/gateway/operator-run-recovery.effects.test.ts). It uses the real CronService, captureCronJobTurnTarget and prepareSessionEventTargetForHost, then edits the stored job's operatorSource.
    • Base 848732ff: red, Error: Automation operator source changed.
    • Head: green.
  • ocx test on the four test files that import cron-job-turn-target.ts: 35/35 pass.
  • pnpm check:changed: typecheck, lint, format and guards pass. The dead-export scan fails on base-only entries (AgentCommandPluginIngressOpts, clearNativeRepositorySourceModulesForTest, resolveUpdateInstallSurfaceMock). None of them are in this diff.
  • Live Gateway E2E (isolated Gateway, real openai/gpt-5.5, scratch state). Steps: the agent creates a cron job from chat with a 3 s timeout. cron.run fails, and the failure-repair turn starts in the owner session. The repair turn calls the cron tool to set timeoutSeconds: 120 (cron.update), then runs one more exec and replies.
    • Base 848732ff: the job edit lands, then the repair turn ends state: error with Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed. The Gateway log has scope_authority_refused. This is the incident.
    • Head 4d50bb57: the job edit lands and the repair turn ends state: final. The log has no scope_authority_refused.
  • One-admission E2E Q/R/S on head 4d50bb57: all PASS. Revoking access while work is queued refuses it visibly, revoking access while a turn runs stops it (access-reduced), and Stop cancels the turn.

Production: −18/+6 lines. Test: +56/−1.

Admission decides a cron turn's authority once at start. The session event
target also re-compared the job's operator source (or scheduled requester)
on every fence check, so cron.update mid-run killed the turn with
"Automation operator source changed" (scope_authority_refused).
Drop that re-check; the edit applies from the next occurrence.
@clawsweeper

clawsweeper Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Nov 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. labels Nov 29, 2026
@obviyus
obviyus merged commit 7895017 into main Nov 29, 2026
124 checks passed
@obviyus
obviyus deleted the fix/cron-midrun-source-recheck branch November 29, 2026 04:10
@obviyus

obviyus commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 7895017.

  • Bug: if someone edited a cron job while its notice or repair turn was running, the turn failed with "Automation operator source changed". A repair turn that fixed its own job was killed by its own edit.
  • Fix: the job is no longer re-read during the turn. Admission at start decides authority, and the edit applies from the next occurrence.
  • Proof: the new test fails on the base and passes on the head. On a live Gateway, the base repair turn failed with the incident error and the head repair turn finished. One-admission Q/R/S passes on the head, and CI is green.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 29, 2026
…penclaw#207947)

## Problem

A started cron turn died when someone edited its job. Daily refusal watch, 2026-11-28:

```
[gateway] cron: job updated
[agent/embedded] session target preparation refused reason=scope_authority_refused
lane task error: lane=cron-nested durationMs=36667 error="Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed"
```

`captureCronJobTurnTarget` (`src/gateway/cron-job-turn-target.ts`) gave the session event target an `assertCurrent` that re-read the job on every fence check. It compared the stored `operatorSource` (or the scheduled requester) with the value captured at start. `cron.update` changes that value, so the next fence check threw. The run's `assertScopeCurrent` turned it into `scope_authority_refused`. The cron notice and failure-repair turns use this target. A repair turn that fixes its own job killed itself.

Root `AGENTS.md` "Decide authority once" does not allow this: authority is checked once, when work starts. The only stop after start is a permission writer stopping a named person's work. Editing a job is neither. This is the same class as R7 `source_authority_refused` (removed in openclaw#205268).

## Change

- Remove both job re-reads from `captureCronJobTurnTarget`: the operator-source comparison ("Automation operator source changed") and the scheduled-requester comparison ("Automation requester changed.").
- The edited source applies from the next occurrence. Admission at that start decides it.
- Kept: admission at start, data fences (attempt lifecycle, session identity, target fields), the run abort signal, and the cron remove/disable cancellation (active-job marker → run `AbortController`).
- `scope_authority_refused` stays. The run-registry binding (`source-closed`) still produces it. `scripts/lib/no-operator-permission-read.mjs` lists no removed site.

## What the user sees

A cron notice or repair turn finishes after the job is edited. Before, it failed with "This agent run is no longer active. Start a new turn to retry."

## Evidence

- New test `keeps a started cron turn running when its job is edited` (`src/gateway/operator-run-recovery.effects.test.ts`). It uses the real `CronService`, `captureCronJobTurnTarget` and `prepareSessionEventTargetForHost`, then edits the stored job's `operatorSource`.
  - Base `9e839f97`: red, `Error: Automation operator source changed`.
  - Head: green.
- `ocx test` on the four test files that import `cron-job-turn-target.ts`: 35/35 pass.
- `pnpm check:changed`: typecheck, lint, format and guards pass. The dead-export scan fails on base-only entries (`AgentCommandPluginIngressOpts`, `clearNativeRepositorySourceModulesForTest`, `resolveUpdateInstallSurfaceMock`). None of them are in this diff.
- Live Gateway E2E (isolated Gateway, real `openai/gpt-5.5`, scratch state). Steps: the agent creates a cron job from chat with a 3 s timeout. `cron.run` fails, and the failure-repair turn starts in the owner session. The repair turn calls the cron tool to set `timeoutSeconds: 120` (`cron.update`), then runs one more `exec` and replies.
  - Base `9e839f97`: the job edit lands, then the repair turn ends `state: error` with `Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed`. The Gateway log has `scope_authority_refused`. This is the incident.
  - Head `4d50bb57`: the job edit lands and the repair turn ends `state: final`. The log has no `scope_authority_refused`.
- One-admission E2E Q/R/S on head `4d50bb57`: all PASS. Revoking access while work is queued refuses it visibly, revoking access while a turn runs stops it (`access-reduced`), and Stop cancels the turn.

Production: −18/+6 lines. Test: +56/−1.

Co-authored-by: Ayaan Zaidi <[email protected]>
vincentkoc added a commit that referenced this pull request Nov 29, 2026
* commit '99b4afc696081eda8aefd8e91250c112f53a8a73': (564 commits)
  test(ios): verify send-at-tap feedback and work grouping (#207913)
  test(agents): reject unsuccessful live replay completions (#207724)
  fix(cron): keep a started cron turn running when its job is edited (#207947)
  improve(ui): put waiting for a free agent under automation timing (#201282)
  chore(ui): refresh control ui locales (#207514)
  fix: distinguish unresolved delivery failures from delivery history (#207897)
  test(doctor): require security check in proxy ordering assertion (#207912)
  fix: keep update rollback tests in sync with shipped workers (#207822)
  test(agents): fix provider header filtering coverage (#207732)
  refactor: remove the bundled GBrain adapter (#207924)
  improve(ui): show optional run limits beside the automation schedule (#201283)
  test(onboarding): inspect recorded output for credential leaks (#207872)
  perf(exec): reduce host memory sampler allocations (#207927)
  test(mcp-relay): isolate the Connected apps fallback locale (#207923)
  fix(acp): deliver bound channel replies to the pending question (#207035)
  fix(cron): keep required reports from going silent when nothing changes (#207044)
  test(sessions): assert participant queue rollback state (#207891)
  perf(gateway): skip session display preparation for transcript recall (#207916)
  test(agents): verify complete bracketed paste payload (#207733)
  test: stop timing out the cron recovery settlement test on slow runners (#207920)
  ...
vincentkoc added a commit that referenced this pull request Nov 29, 2026
* commit '1b246c09b0c1d41ed0f090f07fc50381decba90d': (574 commits)
  fix: stop the manual handoff UI test from hanging after completion (#207945)
  fix: surface favorites and recommended models in picker search (#201450)
  fix: show the saved quota reset when chat skips its only model (#207210)
  fix: avoid reloading unchanged plugins after Gateway boot (#207949)
  fix: keep Task progress double-clicks from changing the window (#207937)
  fix(doctor): continue repairs past retained conflicting exec approvals (#207951)
  test(reply): make account isolation assertion decisive (#207793)
  fix: keep task progress compact when reopening Details (#207943)
  fix(ui): restore the saved reading position after an empty search (#207673)
  fix: remove four Memory Wiki settings that had no effect (#207882)
  test(ios): verify send-at-tap feedback and work grouping (#207913)
  test(agents): reject unsuccessful live replay completions (#207724)
  fix(cron): keep a started cron turn running when its job is edited (#207947)
  improve(ui): put waiting for a free agent under automation timing (#201282)
  chore(ui): refresh control ui locales (#207514)
  fix: distinguish unresolved delivery failures from delivery history (#207897)
  test(doctor): require security check in proxy ordering assertion (#207912)
  fix: keep update rollback tests in sync with shipped workers (#207822)
  test(agents): fix provider header filtering coverage (#207732)
  refactor: remove the bundled GBrain adapter (#207924)
  ...
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
…207947)

## Problem

A started cron turn died when someone edited its job. Daily refusal watch, 2026-11-28:

```
[gateway] cron: job updated
[agent/embedded] session target preparation refused reason=scope_authority_refused
lane task error: lane=cron-nested durationMs=36667 error="Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed"
```

`captureCronJobTurnTarget` (`src/gateway/cron-job-turn-target.ts`) gave the session event target an `assertCurrent` that re-read the job on every fence check. It compared the stored `operatorSource` (or the scheduled requester) with the value captured at start. `cron.update` changes that value, so the next fence check threw. The run's `assertScopeCurrent` turned it into `scope_authority_refused`. The cron notice and failure-repair turns use this target. A repair turn that fixes its own job killed itself.

Root `AGENTS.md` "Decide authority once" does not allow this: authority is checked once, when work starts. The only stop after start is a permission writer stopping a named person's work. Editing a job is neither. This is the same class as R7 `source_authority_refused` (removed in #205268).

## Change

- Remove both job re-reads from `captureCronJobTurnTarget`: the operator-source comparison ("Automation operator source changed") and the scheduled-requester comparison ("Automation requester changed.").
- The edited source applies from the next occurrence. Admission at that start decides it.
- Kept: admission at start, data fences (attempt lifecycle, session identity, target fields), the run abort signal, and the cron remove/disable cancellation (active-job marker → run `AbortController`).
- `scope_authority_refused` stays. The run-registry binding (`source-closed`) still produces it. `scripts/lib/no-operator-permission-read.mjs` lists no removed site.

## What the user sees

A cron notice or repair turn finishes after the job is edited. Before, it failed with "This agent run is no longer active. Start a new turn to retry."

## Evidence

- New test `keeps a started cron turn running when its job is edited` (`src/gateway/operator-run-recovery.effects.test.ts`). It uses the real `CronService`, `captureCronJobTurnTarget` and `prepareSessionEventTargetForHost`, then edits the stored job's `operatorSource`.
  - Base `848732ff`: red, `Error: Automation operator source changed`.
  - Head: green.
- `ocx test` on the four test files that import `cron-job-turn-target.ts`: 35/35 pass.
- `pnpm check:changed`: typecheck, lint, format and guards pass. The dead-export scan fails on base-only entries (`AgentCommandPluginIngressOpts`, `clearNativeRepositorySourceModulesForTest`, `resolveUpdateInstallSurfaceMock`). None of them are in this diff.
- Live Gateway E2E (isolated Gateway, real `openai/gpt-5.5`, scratch state). Steps: the agent creates a cron job from chat with a 3 s timeout. `cron.run` fails, and the failure-repair turn starts in the owner session. The repair turn calls the cron tool to set `timeoutSeconds: 120` (`cron.update`), then runs one more `exec` and replies.
  - Base `848732ff`: the job edit lands, then the repair turn ends `state: error` with `Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed`. The Gateway log has `scope_authority_refused`. This is the incident.
  - Head `4d50bb57`: the job edit lands and the repair turn ends `state: final`. The log has no `scope_authority_refused`.
- One-admission E2E Q/R/S on head `4d50bb57`: all PASS. Revoking access while work is queued refuses it visibly, revoking access while a turn runs stops it (`access-reduced`), and Stop cancels the turn.

Production: −18/+6 lines. Test: +56/−1.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 7895017)

Release adaptation: Remove the mutable job-source assertions while retaining beta.2 requesterOwner and delegated ownerContinuation option shapes; preserve the existing source-conversation fence.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…207947)

A started cron turn died when someone edited its job. Daily refusal watch, 2026-11-28:

```
[gateway] cron: job updated
[agent/embedded] session target preparation refused reason=scope_authority_refused
lane task error: lane=cron-nested durationMs=36667 error="Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed"
```

`captureCronJobTurnTarget` (`src/gateway/cron-job-turn-target.ts`) gave the session event target an `assertCurrent` that re-read the job on every fence check. It compared the stored `operatorSource` (or the scheduled requester) with the value captured at start. `cron.update` changes that value, so the next fence check threw. The run's `assertScopeCurrent` turned it into `scope_authority_refused`. The cron notice and failure-repair turns use this target. A repair turn that fixes its own job killed itself.

Root `AGENTS.md` "Decide authority once" does not allow this: authority is checked once, when work starts. The only stop after start is a permission writer stopping a named person's work. Editing a job is neither. This is the same class as R7 `source_authority_refused` (removed in #205268).

- Remove both job re-reads from `captureCronJobTurnTarget`: the operator-source comparison ("Automation operator source changed") and the scheduled-requester comparison ("Automation requester changed.").
- The edited source applies from the next occurrence. Admission at that start decides it.
- Kept: admission at start, data fences (attempt lifecycle, session identity, target fields), the run abort signal, and the cron remove/disable cancellation (active-job marker → run `AbortController`).
- `scope_authority_refused` stays. The run-registry binding (`source-closed`) still produces it. `scripts/lib/no-operator-permission-read.mjs` lists no removed site.

A cron notice or repair turn finishes after the job is edited. Before, it failed with "This agent run is no longer active. Start a new turn to retry."

- New test `keeps a started cron turn running when its job is edited` (`src/gateway/operator-run-recovery.effects.test.ts`). It uses the real `CronService`, `captureCronJobTurnTarget` and `prepareSessionEventTargetForHost`, then edits the stored job's `operatorSource`.
  - Base `848732ff`: red, `Error: Automation operator source changed`.
  - Head: green.
- `ocx test` on the four test files that import `cron-job-turn-target.ts`: 35/35 pass.
- `pnpm check:changed`: typecheck, lint, format and guards pass. The dead-export scan fails on base-only entries (`AgentCommandPluginIngressOpts`, `clearNativeRepositorySourceModulesForTest`, `resolveUpdateInstallSurfaceMock`). None of them are in this diff.
- Live Gateway E2E (isolated Gateway, real `openai/gpt-5.5`, scratch state). Steps: the agent creates a cron job from chat with a 3 s timeout. `cron.run` fails, and the failure-repair turn starts in the owner session. The repair turn calls the cron tool to set `timeoutSeconds: 120` (`cron.update`), then runs one more `exec` and replies.
  - Base `848732ff`: the job edit lands, then the repair turn ends `state: error` with `Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed`. The Gateway log has `scope_authority_refused`. This is the incident.
  - Head `4d50bb57`: the job edit lands and the repair turn ends `state: final`. The log has no `scope_authority_refused`.
- One-admission E2E Q/R/S on head `4d50bb57`: all PASS. Revoking access while work is queued refuses it visibly, revoking access while a turn runs stops it (`access-reduced`), and Stop cancels the turn.

Production: −18/+6 lines. Test: +56/−1.

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

Release adaptation: Replace the stable restored source snapshot equality assertion with the job-incarnation fence, retaining the revoked-device and profile checks and stable target ownership. Prove edits and removal against admitted repair target and authority.

Companion audit: 213f9b9 applied immediately before this source; no other required companions.

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

gateway Gateway runtime impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant