Repository navigation
fix(cron): manual runs lose tool access after the starting turn ends - #168037
Conversation
Worked on by: - @obviyus Co-authored-by: obviyus <[email protected]> OpenClaw-Publication: 44089780-8e1a-455d-b495-689848b449fe
|
🦞👀 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. |
|
Codex review: needs maintainer review before merge. What this changesAccepted 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherCron 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +6, Tests +451, Docs +6. Total +463 across 8 files. Added test files: 2. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed October 10, 2026, 1:21 AM ET / 05:21 UTC (Revision 5). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
CI attribution for
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 ( |
|
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. |
…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]>
…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)
…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)
…law#165373, openclaw#166843, openclaw#166991, openclaw#168037) (cherry picked from commit a4511e5) Co-authored-by: RomneyDa <[email protected]>
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 activeoroperator 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
cron.runhandler, 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.src/cron/isolated-agent/run.manual-tool-authority.test.ts). An admin creates the job through the realcron.addhandler and starts it through the realcron.runhandler. 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 storedtoolsAllow, real tool construction with the embedded runner's allowlist filter, and the realcron.listhandler. Only the model is controlled.automationsreaches the realcron.listhandler once. It receives the job's restricted caller-scoped inventory, not the admin's view. With theops-run.tschange reverted, this case fails withoperator execution authority is no longer active.toolsAllowis["read"]is never offeredautomations, even though the request that started it hadoperator.admin, and the handler is never called. Without the allowlist filter, this case fails.src/cron/service/run-receipt-settlement.test.tsexpects manual execution to be scheduler-owned, the same as stream, on-exit and startup runs (17/17).src/gateway/server-plugin-reload.recovery.test.tsis not from this PR. It fails 9/111 on the PR head, on the PR head with the fix reverted, and on cleanmain(89c0368fe52and1f307d61d0f).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.Check limitation: the aggregate changed-file check stops on unused exports in untouched baseline files:
extensions/telegram/src/sequential-key.ts:isTelegramReadOnlyControlLaneTextandsrc/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