Skip to content

fix(cron): manual runs lose tool access after the starting turn ends - #168037

Merged
obviyus merged 5 commits into
mainfrom
openclaw/cron-job-execution-failure-causes
Oct 10, 2026
Merged

obviyus merged 5 commits into
mainfrom
openclaw/cron-job-execution-failure-causes

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: manually started automations lose tool access after the chat turn or tool invocation that started them finishes, failing with operator execution authority is no longer active or operator tool invocation authority expired.

Reported as P0 by @obviyus after repeated automation permission failures. This PR fixes the reproduced manual-run lifetime failure; it does not claim every cron permission error has the same cause.

User Impact

User impact: accepted manual runs can keep using their scheduled tools and deliver their results after the initiating request ends, just like timer-fired runs. Existing jobs need no recreation, permission expansion, new configuration, or migration.

Real revocation, missing saved accounts, job cancellation, and stored tool restrictions remain enforced. A separate missing repository-workspace binding is not repaired here.

A manual run no longer carries the caller's identity or request scope once it is accepted; it runs like a timer-fired run. A job that only worked when an admin started it by hand now behaves the same way it does on its schedule.

Revoking the caller's device after the run starts does not stop the accepted run, the same as for timer-fired runs. Revocation before the run starts still rejects it.

Why This Change Was Made

The manual command queue preserves its submitting async context. Although it already detached root-work admission and transcript writes, it retained both operator-tool authority and the request-scope client. Those temporary authorities could expire while the accepted cron was still running.

After guarded activation finishes, hand execution and finalization to the existing scheduler-owned Gateway context outside the initiating operator-tool scope. Keep preparation and activation under the original commit guards; the stored job and its run receipt still own permissions, cancellation, and delivery. Direct manual, stream, and on-exit execution converge on this boundary. Do not broadly weaken the generic scheduler or authorization checks.

Evidence

  • Before: isolated reproduction through the real cron.run handler, queue, and GitHub-status tool fails with the exact inactive-authority error; an invocation-scope case fails with expired authority; timer control passes. Model execution and the GitHub response are synthetic.
  • After: 36/36 focused manual-run, cancellation, queued-caller revocation, FIFO, and transcript-delivery cases pass. 28/28 regression/stored-policy/requester-provenance cases pass (three overlap the first group).
  • 7/7 real isolated-agent account-policy/history cases pass, including a manually queued job after invocation closure: its removed saved account is still rejected, model execution stays at zero, and error history is recorded.
  • Authority chain, 4/4 (src/cron/isolated-agent/run.manual-tool-authority.test.ts). An admin creates the job through the real cron.add handler and starts it through the real cron.run handler. The request then ends before the job's tool call. From there the run uses the real queue, the scheduler runner, runCronIsolatedAgentTurn, the job's stored toolsAllow, real tool construction with the embedded runner's allowlist filter, and the real cron.list handler. Only the model is controlled.
    • (a) A job allowed to use automations reaches the real cron.list handler once. It receives the job's restricted caller-scoped inventory, not the admin's view. With the ops-run.ts change reverted, this case fails with operator execution authority is no longer active.
    • (b) A job whose stored toolsAllow is ["read"] is never offered automations, even though the request that started it had operator.admin, and the handler is never called. Without the allowlist filter, this case fails.
    • (c) Disabling or removing the job after preparation, before the tool runs, cancels the run. The pending tool call is rejected as aborted and the handler is never called. Without the run abort signal, this case fails.
  • After the change, src/cron/service/run-receipt-settlement.test.ts expects manual execution to be scheduler-owned, the same as stream, on-exit and startup runs (17/17).
  • The failure in src/gateway/server-plugin-reload.recovery.test.ts is not from this PR. It fails 9/111 on the PR head, on the PR head with the fix reverted, and on clean main (89c0368fe52 and 1f307d61d0f).
  • Test cost, one worker: pnpm test src/cron/service/ops.operator-lifetime.test.ts --maxWorkers=1 — 3 cases, 15.31 s command wall / 12.41 s Vitest. pnpm test src/cron/isolated-agent/run.account-policy.test.ts --maxWorkers=1 — 7 cases, 44.60 s wall / 42.90 s Vitest including cold compiled-worker preparation; the added negative case takes 309 ms. Hosted CI seconds are pending.
  • Core production and all 27 core-test typecheck graphs pass. Independent autoreview is scoped-clean through P2. No live Gateway, credentials, or automation definition changed during validation.

Check limitation: the aggregate changed-file check stops on unused exports in untouched baseline files: extensions/telegram/src/sequential-key.ts:isTelegramReadOnlyControlLaneText and src/auto-reply/reply/model-selection.ts:resolveContextTokens. Their source and scanner configuration are unchanged by this PR; the aggregate is not reported as green. The remaining scoped lint/guards pass when run separately.

Worked on by

Work sessions


View the OpenClaw team session

Worked on by:
- @obviyus

Co-authored-by: obviyus <[email protected]>
OpenClaw-Publication: 44089780-8e1a-455d-b495-689848b449fe
@clawsweeper

clawsweeper Bot commented Oct 10, 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 docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 10, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 10, 2026 00:23
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Accepted manual automation runs switch to scheduler-owned execution so their tools remain usable after the initiating request ends.

Example: An operator manually starts a job allowed to use automations, then the initiating request ends before the job lists automations.

  • Before: The tool call fails with operator execution authority is no longer active.
  • After: The call succeeds with the job's restricted inventory rather than the operator's administrative view.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused repair with meaningful authority-boundary coverage and no actionable findings; evidence remains an in-process harness rather than a shipped-entry-point run.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (none): For this collaborator-authored PR, the supplied production-path authority harness covers real admission, queueing, isolated-agent preparation, tool construction, and final cron.list dispatch after source closure; forbidden tools and disabled or removed jobs never reach the handler.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Manual automations fail to use tools after the chat turn or tool invocation that started them finishes.
Reason: The collaborator-authored direction explicitly adopts scheduled execution semantics after activation, restoring useful automation behavior without new settings or permission expansion.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs a current manual-run lifetime failure, and review found no actionable introduced defect.

Priority: P1
Reviewed head: 01edc50ffc4dfbfe6b4b1f832c28ddbd8c4dde01

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not exercise a shipped CLI or live Gateway; it establishes the changed authority boundary through an isolated production-path harness.
Agent review details

How this fits together

Cron admits and activates manual requests under caller guards, then executes stored jobs and settles their receipts through the owning Gateway.

flowchart TD
A[Manual run request] --> B[Caller admission guards]
B --> C[Durable queue and activation]
C --> D[Scheduler Gateway context]
D --> E[Stored job tool policy]
E --> F[Tool handler]
F --> G[Receipt settlement]
Loading

Technical review

Best possible solution:

Retain guarded manual activation and let the existing scheduler owner execute and settle the job under its stored authority.

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

Current main retains the initiating execution context, and the supplied regression reports the exact authority error with the repair reverted; this read-only review ran no target code.

Is this the best way to solve the issue?

The repair addresses context inheritance at the shared manual execution boundary and reuses existing scheduler ownership without weakening generic authorization checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Manual execution and caller lifetime changes intended behavior with a stated reason (1125da0: Retain queued caller identity and device revocation through settlement while guarding mutations and preserving committed outcomes.)
  • Scheduler context versus RPC context changes intended behavior with a stated reason (9feb1db: Supply instance-owned context to scheduled work while preserving direct RPC caller context; the current PR explains why accepted manual execution must outlive that context.)
  • Detached transcript-write ownership keeps the original intent (510beb8: Prevent accepted manual runs from writing through the disposed initiating attempt; this PR retains that separation.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 037feb1 adds src/gateway/scheduled-run-gateway-context.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 037feb16edd5; files: src/gateway/scheduled-run-gateway-context.ts)
  • Ayaan Zaidi: Raw commit 510beb8 adds src/cron/service/ops-run.ts:1 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 510beb8d52bd; files: src/cron/service/ops-run.ts)
  • Shakker: Raw commit 1125da0 adds src/cron/service/ops-run.ts:1 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1125da02a0c2; files: src/cron/service/ops-run.ts)

PR surface

Source +6, Tests +451, Docs +6. Total +463 across 8 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 2 9 3 +6
Tests 5 471 20 +451
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 486 23 +463

Labels

Label changes:

No label changes.

Label justifications:

  • P1: A manually started automation can lose tool access after its initiating turn ends, breaking an active automation workflow.
  • merge-risk: 🚨 security-boundary: Execution transfers from transient caller authority to stored job authority; post-activation caller-device revocation is explicitly accepted, and production-path controls cover job restrictions and cancellation.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-10T00:29:22.536Z sha 94e5877 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T01:21:13.242Z sha 151f8bf :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T02:08:22.870Z sha fed8240 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T05:00:01.881Z sha ab71cd3 :: needs maintainer review before merge. :: none

Reviewed October 10, 2026, 1:21 AM ET / 05:21 UTC (Revision 5).

@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

CI attribution for src/gateway/server-plugin-reload.recovery.test.ts (CI run https://github.com/openclaw/openclaw/actions/runs/38009777874, job checks-node-changed-compact-small-11):

Tree Result
PR head 151f8bfa2de 9 failed / 111
PR head with the src/cron/service/ops-run.ts fix reverted 9 failed / 111
clean origin/main 89c0368fe52 9 failed / 111
clean origin/main 1f307d61d0f (latest) 9 failed / 111 — still failing

The same 9 cases fail in each tree: memory watcher restart after provider-only reload (initialized/rollback/separate-registry) and retained/replaced memory indexing recovery after early before-drain/checkpoint/restart failure (expected [] to deeply equal [ 1 ]). This PR does not touch plugin reload or memory code; the failure is present on main without it.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 10, 2026
@obviyus
obviyus merged commit 2790eea into main Oct 10, 2026
125 checks passed
@obviyus
obviyus deleted the openclaw/cron-job-execution-failure-causes branch October 10, 2026 05:23
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Landed. Accepted manual automations now use scheduler-owned execution after guarded activation, so tools keep working after the starting request ends without inheriting the caller’s extra permissions. Stored tool/account restrictions and job cancellation remain enforced. The real-handler authority harness covers the lifetime and policy boundary; the updated Gateway context regression passes, and final-head CI is green with ClawSweeper ready. Thanks @obviyus for reporting and helping reproduce the failure.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…penclaw#168037)

## What Problem This Solves

Fixes: manually started automations lose tool access after the chat turn or tool invocation that started them finishes, failing with `operator execution authority is no longer active` or `operator tool invocation authority expired`.

Reported as P0 by @obviyus after repeated automation permission failures. This PR fixes the reproduced manual-run lifetime failure; it does not claim every cron permission error has the same cause.

## User Impact

User impact: accepted manual runs can keep using their scheduled tools and deliver their results after the initiating request ends, just like timer-fired runs. Existing jobs need no recreation, permission expansion, new configuration, or migration.

Real revocation, missing saved accounts, job cancellation, and stored tool restrictions remain enforced. A separate missing repository-workspace binding is not repaired here.

A manual run no longer carries the caller's identity or request scope once it is accepted; it runs like a timer-fired run. A job that only worked when an admin started it by hand now behaves the same way it does on its schedule.

Revoking the caller's device after the run starts does not stop the accepted run, the same as for timer-fired runs. Revocation before the run starts still rejects it.

## Why This Change Was Made

The manual command queue preserves its submitting async context. Although it already detached root-work admission and transcript writes, it retained both operator-tool authority and the request-scope client. Those temporary authorities could expire while the accepted cron was still running.

After guarded activation finishes, hand execution and finalization to the existing scheduler-owned Gateway context outside the initiating operator-tool scope. Keep preparation and activation under the original commit guards; the stored job and its run receipt still own permissions, cancellation, and delivery. Direct manual, stream, and on-exit execution converge on this boundary. Do not broadly weaken the generic scheduler or authorization checks.

## Evidence

- Before: isolated reproduction through the real `cron.run` handler, queue, and GitHub-status tool fails with the exact inactive-authority error; an invocation-scope case fails with expired authority; timer control passes. Model execution and the GitHub response are synthetic.
- After: **36/36** focused manual-run, cancellation, queued-caller revocation, FIFO, and transcript-delivery cases pass. **28/28** regression/stored-policy/requester-provenance cases pass (three overlap the first group).
- **7/7** real isolated-agent account-policy/history cases pass, including a manually queued job after invocation closure: its removed saved account is still rejected, model execution stays at zero, and error history is recorded.
- **Authority chain, 4/4** (`src/cron/isolated-agent/run.manual-tool-authority.test.ts`). An admin creates the job through the real `cron.add` handler and starts it through the real `cron.run` handler. The request then ends before the job's tool call. From there the run uses the real queue, the scheduler runner, `runCronIsolatedAgentTurn`, the job's stored `toolsAllow`, real tool construction with the embedded runner's allowlist filter, and the real `cron.list` handler. Only the model is controlled.
  - (a) A job allowed to use `automations` reaches the real `cron.list` handler once. It receives the job's restricted caller-scoped inventory, not the admin's view. With the `ops-run.ts` change reverted, this case fails with `operator execution authority is no longer active`.
  - (b) A job whose stored `toolsAllow` is `["read"]` is never offered `automations`, even though the request that started it had `operator.admin`, and the handler is never called. Without the allowlist filter, this case fails.
  - (c) Disabling or removing the job after preparation, before the tool runs, cancels the run. The pending tool call is rejected as aborted and the handler is never called. Without the run abort signal, this case fails.
- After the change, `src/cron/service/run-receipt-settlement.test.ts` expects manual execution to be scheduler-owned, the same as stream, on-exit and startup runs (17/17).
- The failure in `src/gateway/server-plugin-reload.recovery.test.ts` is not from this PR. It fails 9/111 on the PR head, on the PR head with the fix reverted, and on clean `main` (`76b5258bc0f` and `1933eab6da2`).
- Test cost, one worker: `pnpm test src/cron/service/ops.operator-lifetime.test.ts --maxWorkers=1` — 3 cases, **15.31 s** command wall / 12.41 s Vitest. `pnpm test src/cron/isolated-agent/run.account-policy.test.ts --maxWorkers=1` — 7 cases, **44.60 s** wall / 42.90 s Vitest including cold compiled-worker preparation; the added negative case takes **309 ms**. Hosted CI seconds are pending.
- Core production and all 27 core-test typecheck graphs pass. Independent autoreview is scoped-clean through P2. No live Gateway, credentials, or automation definition changed during validation.

**Check limitation:** the aggregate changed-file check stops on unused exports in untouched baseline files: `extensions/telegram/src/sequential-key.ts:isTelegramReadOnlyControlLaneText` and `src/auto-reply/reply/model-selection.ts:resolveContextTokens`. Their source and scanner configuration are unchanged by this PR; the aggregate is not reported as green. The remaining scoped lint/guards pass when run separately.

## Worked on by

- @obviyus

## Work sessions

- [Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/dashboard/7717e248-9669-41ac-93f6-28066e55c080)

<!-- openclaw-publication:44089780-8e1a-455d-b495-689848b449fe -->

---
[View the OpenClaw team session](https://team.openclaw.ai/chat/roboclaw/dashboard/7717e248-9669-41ac-93f6-28066e55c080)

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

Fixes: manually started automations lose tool access after the chat turn or tool invocation that started them finishes, failing with `operator execution authority is no longer active` or `operator tool invocation authority expired`.

Reported as P0 by @obviyus after repeated automation permission failures. This PR fixes the reproduced manual-run lifetime failure; it does not claim every cron permission error has the same cause.

User impact: accepted manual runs can keep using their scheduled tools and deliver their results after the initiating request ends, just like timer-fired runs. Existing jobs need no recreation, permission expansion, new configuration, or migration.

Real revocation, missing saved accounts, job cancellation, and stored tool restrictions remain enforced. A separate missing repository-workspace binding is not repaired here.

A manual run no longer carries the caller's identity or request scope once it is accepted; it runs like a timer-fired run. A job that only worked when an admin started it by hand now behaves the same way it does on its schedule.

Revoking the caller's device after the run starts does not stop the accepted run, the same as for timer-fired runs. Revocation before the run starts still rejects it.

The manual command queue preserves its submitting async context. Although it already detached root-work admission and transcript writes, it retained both operator-tool authority and the request-scope client. Those temporary authorities could expire while the accepted cron was still running.

After guarded activation finishes, hand execution and finalization to the existing scheduler-owned Gateway context outside the initiating operator-tool scope. Keep preparation and activation under the original commit guards; the stored job and its run receipt still own permissions, cancellation, and delivery. Direct manual, stream, and on-exit execution converge on this boundary. Do not broadly weaken the generic scheduler or authorization checks.

- Before: isolated reproduction through the real `cron.run` handler, queue, and GitHub-status tool fails with the exact inactive-authority error; an invocation-scope case fails with expired authority; timer control passes. Model execution and the GitHub response are synthetic.
- After: **36/36** focused manual-run, cancellation, queued-caller revocation, FIFO, and transcript-delivery cases pass. **28/28** regression/stored-policy/requester-provenance cases pass (three overlap the first group).
- **7/7** real isolated-agent account-policy/history cases pass, including a manually queued job after invocation closure: its removed saved account is still rejected, model execution stays at zero, and error history is recorded.
- **Authority chain, 4/4** (`src/cron/isolated-agent/run.manual-tool-authority.test.ts`). An admin creates the job through the real `cron.add` handler and starts it through the real `cron.run` handler. The request then ends before the job's tool call. From there the run uses the real queue, the scheduler runner, `runCronIsolatedAgentTurn`, the job's stored `toolsAllow`, real tool construction with the embedded runner's allowlist filter, and the real `cron.list` handler. Only the model is controlled.
  - (a) A job allowed to use `automations` reaches the real `cron.list` handler once. It receives the job's restricted caller-scoped inventory, not the admin's view. With the `ops-run.ts` change reverted, this case fails with `operator execution authority is no longer active`.
  - (b) A job whose stored `toolsAllow` is `["read"]` is never offered `automations`, even though the request that started it had `operator.admin`, and the handler is never called. Without the allowlist filter, this case fails.
  - (c) Disabling or removing the job after preparation, before the tool runs, cancels the run. The pending tool call is rejected as aborted and the handler is never called. Without the run abort signal, this case fails.
- After the change, `src/cron/service/run-receipt-settlement.test.ts` expects manual execution to be scheduler-owned, the same as stream, on-exit and startup runs (17/17).
- The failure in `src/gateway/server-plugin-reload.recovery.test.ts` is not from this PR. It fails 9/111 on the PR head, on the PR head with the fix reverted, and on clean `main` (`89c0368fe52` and `1f307d61d0f`).
- Test cost, one worker: `pnpm test src/cron/service/ops.operator-lifetime.test.ts --maxWorkers=1` — 3 cases, **15.31 s** command wall / 12.41 s Vitest. `pnpm test src/cron/isolated-agent/run.account-policy.test.ts --maxWorkers=1` — 7 cases, **44.60 s** wall / 42.90 s Vitest including cold compiled-worker preparation; the added negative case takes **309 ms**. Hosted CI seconds are pending.
- Core production and all 27 core-test typecheck graphs pass. Independent autoreview is scoped-clean through P2. No live Gateway, credentials, or automation definition changed during validation.

**Check limitation:** the aggregate changed-file check stops on unused exports in untouched baseline files: `extensions/telegram/src/sequential-key.ts:isTelegramReadOnlyControlLaneText` and `src/auto-reply/reply/model-selection.ts:resolveContextTokens`. Their source and scanner configuration are unchanged by this PR; the aggregate is not reported as green. The remaining scoped lint/guards pass when run separately.

- @obviyus

- [Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/dashboard/7717e248-9669-41ac-93f6-28066e55c080)

<!-- openclaw-publication:44089780-8e1a-455d-b495-689848b449fe -->

---
[View the OpenClaw team session](https://team.openclaw.ai/chat/roboclaw/dashboard/7717e248-9669-41ac-93f6-28066e55c080)

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 2790eea)
RomneyDa pushed a commit that referenced this pull request Oct 13, 2026
…168037)

## What Problem This Solves

Fixes: manually started automations lose tool access after the chat turn or tool invocation that started them finishes, failing with `operator execution authority is no longer active` or `operator tool invocation authority expired`.

Reported as P0 by @obviyus after repeated automation permission failures. This PR fixes the reproduced manual-run lifetime failure; it does not claim every cron permission error has the same cause.

## User Impact

User impact: accepted manual runs can keep using their scheduled tools and deliver their results after the initiating request ends, just like timer-fired runs. Existing jobs need no recreation, permission expansion, new configuration, or migration.

Real revocation, missing saved accounts, job cancellation, and stored tool restrictions remain enforced. A separate missing repository-workspace binding is not repaired here.

A manual run no longer carries the caller's identity or request scope once it is accepted; it runs like a timer-fired run. A job that only worked when an admin started it by hand now behaves the same way it does on its schedule.

Revoking the caller's device after the run starts does not stop the accepted run, the same as for timer-fired runs. Revocation before the run starts still rejects it.

## Why This Change Was Made

The manual command queue preserves its submitting async context. Although it already detached root-work admission and transcript writes, it retained both operator-tool authority and the request-scope client. Those temporary authorities could expire while the accepted cron was still running.

After guarded activation finishes, hand execution and finalization to the existing scheduler-owned Gateway context outside the initiating operator-tool scope. Keep preparation and activation under the original commit guards; the stored job and its run receipt still own permissions, cancellation, and delivery. Direct manual, stream, and on-exit execution converge on this boundary. Do not broadly weaken the generic scheduler or authorization checks.

## Evidence

- Before: isolated reproduction through the real `cron.run` handler, queue, and GitHub-status tool fails with the exact inactive-authority error; an invocation-scope case fails with expired authority; timer control passes. Model execution and the GitHub response are synthetic.
- After: **36/36** focused manual-run, cancellation, queued-caller revocation, FIFO, and transcript-delivery cases pass. **28/28** regression/stored-policy/requester-provenance cases pass (three overlap the first group).
- **7/7** real isolated-agent account-policy/history cases pass, including a manually queued job after invocation closure: its removed saved account is still rejected, model execution stays at zero, and error history is recorded.
- **Authority chain, 4/4** (`src/cron/isolated-agent/run.manual-tool-authority.test.ts`). An admin creates the job through the real `cron.add` handler and starts it through the real `cron.run` handler. The request then ends before the job's tool call. From there the run uses the real queue, the scheduler runner, `runCronIsolatedAgentTurn`, the job's stored `toolsAllow`, real tool construction with the embedded runner's allowlist filter, and the real `cron.list` handler. Only the model is controlled.
  - (a) A job allowed to use `automations` reaches the real `cron.list` handler once. It receives the job's restricted caller-scoped inventory, not the admin's view. With the `ops-run.ts` change reverted, this case fails with `operator execution authority is no longer active`.
  - (b) A job whose stored `toolsAllow` is `["read"]` is never offered `automations`, even though the request that started it had `operator.admin`, and the handler is never called. Without the allowlist filter, this case fails.
  - (c) Disabling or removing the job after preparation, before the tool runs, cancels the run. The pending tool call is rejected as aborted and the handler is never called. Without the run abort signal, this case fails.
- After the change, `src/cron/service/run-receipt-settlement.test.ts` expects manual execution to be scheduler-owned, the same as stream, on-exit and startup runs (17/17).
- The failure in `src/gateway/server-plugin-reload.recovery.test.ts` is not from this PR. It fails 9/111 on the PR head, on the PR head with the fix reverted, and on clean `main` (`89c0368fe52` and `1f307d61d0f`).
- Test cost, one worker: `pnpm test src/cron/service/ops.operator-lifetime.test.ts --maxWorkers=1` — 3 cases, **15.31 s** command wall / 12.41 s Vitest. `pnpm test src/cron/isolated-agent/run.account-policy.test.ts --maxWorkers=1` — 7 cases, **44.60 s** wall / 42.90 s Vitest including cold compiled-worker preparation; the added negative case takes **309 ms**. Hosted CI seconds are pending.
- Core production and all 27 core-test typecheck graphs pass. Independent autoreview is scoped-clean through P2. No live Gateway, credentials, or automation definition changed during validation.

**Check limitation:** the aggregate changed-file check stops on unused exports in untouched baseline files: `extensions/telegram/src/sequential-key.ts:isTelegramReadOnlyControlLaneText` and `src/auto-reply/reply/model-selection.ts:resolveContextTokens`. Their source and scanner configuration are unchanged by this PR; the aggregate is not reported as green. The remaining scoped lint/guards pass when run separately.

## Worked on by

- @obviyus

## Work sessions

- [Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/dashboard/7717e248-9669-41ac-93f6-28066e55c080)

<!-- openclaw-publication:44089780-8e1a-455d-b495-689848b449fe -->

---
[View the OpenClaw team session](https://team.openclaw.ai/chat/roboclaw/dashboard/7717e248-9669-41ac-93f6-28066e55c080)

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 2790eea)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
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 gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

2 participants