Repository navigation
fix(cron): scheduled automations act only on their own job on CLI backends, and session jobs can't yield - #183987
Conversation
…yield from the execution context Scheduled occurrences on embedded and CLI runtimes read the automations scope from context.toolPolicy.automations: the tool is restricted to the run's own job (status, list, get, remove, runs), and a run with no scope gets none. The CLI loopback now carries that self scope, which replaces the automations denial 0d5.10 left on scheduled CLI runs. A self-and-parent-wake scope offers the same self actions; the parent wake action is a follow-up. sessions_yield is refused for every scheduled placement, so session: jobs match isolated ones. The exec target pin also reads from the context. Ingress turns keep their existing CLI surface and yield. Refs #178812
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesScheduled CLI runs receive self-scoped automation tools, and in-session scheduled runs reject yield calls while keeping the tool listed. Example: A scheduled CLI run for self-job calls automations.remove.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a remaining runtime parity bug and prevents stranded scheduled yields; the reviewed head has no actionable findings and a successful CI gate. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCron admission supplies an occurrence-bound execution context to embedded and CLI tool construction; scoped tool calls then reach Gateway handlers and production persistence under live run authority. flowchart TD
A[Stored automation] --> B[Occurrence admission]
B --> C[Execution context]
C --> D[Embedded tools]
C --> E[CLI loopback tools]
D --> F[Gateway authority checks]
E --> F
F --> G[Cron service and store]
Technical reviewBest possible solution: Merge the scoped runtime repair while leaving the broader execution-context and parent-wake work separately tracked. Do we have a high-confidence way to reproduce the issue? Current-main source shows the explicit scheduled CLI automation denial and yield rejection based only on cron-shaped session keys; the PR supplies matching before-fix Gateway observations. Is this the best way to solve the issue? The repair uses existing occurrence admission, scoped automation tooling, yield admission, and persistence guards rather than introducing another authority owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d4ae3a731187. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +205, Tests +639. Total +844 across 12 files. Added test files: 2. View PR surface stats
Review metrics
LabelsLabel 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 (3 earlier review cycles)
Reviewed October 25, 2026, 10:16 PM ET / October 26, 2026, 02:16 UTC (Revision 4). |
…the call A session: run shares its session's tool catalog, and CLI backends hash that catalog for native session reuse, so the definition stays listed and the scheduled callback refuses the call. Child and detached runs still get no sessions_yield. Adds coverage that a CLI run's retained self-scoped automations tool refuses its own job's removal once the run closes, including a close during an awaited Gateway call.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…source The context copies the same stored exec target, so reading it there changed nothing; keep the existing source until a consumer needs the context's pin.
A scheduled CLI run's self-scoped automations tool removes its own job through the in-process Gateway dispatch and cron.remove handler, and the job stays when the run settles while the removal awaits the store.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…session-job losses in Doctor The context can name a parent wake for an owner child, but the wake action is deferred to the automations wake design; a test pins that both runtimes offer own-job self actions only. Doctor's access review describes the CLI automations narrowing and the sessions_yield loss for session-target jobs, under a heading that no longer attributes every loss to creator authority.
…d store The scheduled CLI run's automations tool removes its own job through the real Gateway cron handlers, CronService and store. When the run settles while the service's removal is held before persistence, the removal is refused and the stored job is unchanged.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…kends, and session jobs can't yield (openclaw#183987) * fix(cron): scheduled runs take their automations scope and requester yield from the execution context Scheduled occurrences on embedded and CLI runtimes read the automations scope from context.toolPolicy.automations: the tool is restricted to the run's own job (status, list, get, remove, runs), and a run with no scope gets none. The CLI loopback now carries that self scope, which replaces the automations denial 0d5.10 left on scheduled CLI runs. A self-and-parent-wake scope offers the same self actions; the parent wake action is a follow-up. sessions_yield is refused for every scheduled placement, so session: jobs match isolated ones. The exec target pin also reads from the context. Ingress turns keep their existing CLI surface and yield. Refs openclaw#178812 * fix(cron): session-target runs keep sessions_yield listed and refuse the call A session: run shares its session's tool catalog, and CLI backends hash that catalog for native session reuse, so the definition stays listed and the scheduled callback refuses the call. Child and detached runs still get no sessions_yield. Adds coverage that a CLI run's retained self-scoped automations tool refuses its own job's removal once the run closes, including a close during an awaited Gateway call. * fix(agents): keep the scheduled exec pin on its existing tool-policy source The context copies the same stored exec target, so reading it there changed nothing; keep the existing source until a consumer needs the context's pin. * test(cron): CLI self-removal through the real Gateway cron handler A scheduled CLI run's self-scoped automations tool removes its own job through the in-process Gateway dispatch and cron.remove handler, and the job stays when the run settles while the removal awaits the store. * test(cron): pin the self-and-parent-wake scope to self actions; name session-job losses in Doctor The context can name a parent wake for an owner child, but the wake action is deferred to the automations wake design; a test pins that both runtimes offer own-job self actions only. Doctor's access review describes the CLI automations narrowing and the sessions_yield loss for session-target jobs, under a heading that no longer attributes every loss to creator authority. * test(cron): CLI self-removal settles against the real cron service and store The scheduled CLI run's automations tool removes its own job through the real Gateway cron handlers, CronService and store. When the run settles while the service's removal is held before persistence, the removal is refused and the stored job is unchanged.
Related: #178812
What Problem This Solves
Fixes: a scheduled automation on a CLI backend (Claude CLI, Codex CLI) gets no automations tool, so it can't read, remove or record results for its own job. The embedded runtime gives the same job a tool scoped to its own job. Separately, a
session:<key>job can callsessions_yield, even though nothing resumes the scheduled run after a yield. Isolated jobs are already refused.User Impact
User impact: scheduled runs on embedded and CLI runtimes get the same automations tool, limited to their own job (
status,list,get,remove,runsplus the active-run actions). They can't list, edit or remove sibling jobs.session:jobs can no longer yield. The tool stays listed so the session's tool catalog doesn't change (CLI backends hash it for native session reuse), but the call is refused the same way an isolated job's is.Narrower than before (named losses, see the replay below):
session:job's automations tool now covers only its own job. Before, the turn's owner-only rule applied, which gave an owner unscoped access. The embedded runtime already scoped it this way.session:jobs can't yield on either runtime, the same as isolated jobs (the card's resolved design). On Josh's Gateway, 9 storedsession:jobs calledsessions_yieldin their own scheduled turns. All 9 are disabled: 8 PR babysitters plusgranola-knowledge-ingest(last use 2026-10-23). This is a lower bound: only the current incarnation of each target session was scanned. The 2 enabledsession:jobs never yielded in a scheduled turn. Doctor's scheduled-run access review lists every affected job.Not changed:
session:included, already runs withtrigger: "cron", so approvals already treatsession:jobs like isolated ones.triggerand attempt params. Moving them to the context needs a new plugin-SDK harness field, which needs SDK owner review. That's tracked on follow-up cardopenclaw-84c.Why This Change Was Made
Phase 4b of the scheduled-run execution context. Tool construction now reads the scope and placement from the run's admitted
ScheduledExecutionContextinstead of the trigger, job id and session-key shape:toolPolicy.automationson embedded runs and on the CLI loopback. The loopback now carries the run's own job id. This replaces the automations denial fix(cron): scheduled automations get the same owner-only tools on every runtime #182585 left on scheduled CLI runs. The CLI tool keeps the same run guard as the embedded tool: each Gateway call rechecks that the automation invocation is still current, and the loopback grant is revoked when the run ends.self-and-parent-wakefor an owner child, but this PR grants only the self actions. There is nowake, and no sibling list, edit or remove. The parent wake belongs to the paused automations wake design (openclaw-0d5.9 / 0d5.23). A test pins this on both runtimes.sessions_yieldis refused for every scheduled placement. Child and detached runs (cron session keys) still don't list it.session:runs keep the definition and the scheduled callback refuses the call.The dev replay projection gains
automationsCliandrequesterYieldfields, and it now reports the offered automations scope rather than the builder's label. The fixture expectations were regenerated to match.Evidence
Crabbox (AWS), exact head
d4aefd15d68:CRABBOX_AWS_REGION=us-east-1 CRABBOX_CAPACITY_REGIONS=us-east-1,us-east-2,us-west-2 crabbox run --provider aws --ttl 60m --timing-json --download proof-out.tgz=… --shell -- "bash proof/0d512-remote.sh"(hostOPENCLAW_*variables unset)head=d4aefd15d68ec38245188f7b373de29d289dd8b1. SHA-256 of all 11 changed source and test files matches the local head. The proof script, QA scenario and fake CLI plugin are local tooling and are not committed.aws,c7a.8xlarge(32 vCPU, 61 GB), leasecbx_2c8f2d78a4e5, stopped; inspect reports"state":"released"cron-automations-scope-placement(mock-openai, real Gateway child, qa-channel; jobs linked to a seeded operator chat, with a disabled sibling automation): passed 1/1, all 8 steps.automationsoffered,sessions_yieldnot offered.removeon the sibling returns"error": "Automations tool is restricted to the current automation.", andlistshows the run's own job and not the sibling.session:job: same automations results.sessions_yieldstays in the catalog.tools/listandtools/callon the real loopback MCP bridge):{"automationsOffered":true,"yieldOffered":false,"remove":"Automations tool is restricted to the current automation.","listIds":["<own job id>"]}.removeits own job. Result:{"httpStatus":401,"body":"{\"error\":\"unauthorized\"}"}, and the job still exists.session:job: same automations results.sessions_yieldis listed, and calling it returns"Automation turns cannot use sessions_yield because no requester continuation is available. …".cron.removehandler ({"ok": true, "removed": true}).cron.listno longer has it, and the sibling is kept.execution-context-tool-policy.test.ts,execution-context-self-removal-final-effect.test.ts,execution-context-owner-authority.test.ts,execution-context.fixtures.test.tsand the Doctorexecution-context-report.test.ts: 5 files, 78 tests passed.Before, on
main(65f59b8b80b), same scenario, local: the embeddedsession:job'ssessions_yieldwas callable. In a CLI-only variant, the CLI child's automations calls were refused with "automations needs the owner's authority, and this turn was not started by the owner", so the CLI run had no usable automations tool.Focused tests:
src/cron/execution-context-tool-policy.test.ts(new), with real occurrence admission, real tool construction on both runtimes, and the automations tool's real Gateway request guard over a recording transport:self-and-parent-wake), a non-owner child, a detached operator job and asession:job, each run is offered only self actions (noadd/update/run/wake/bind). Siblingget/remove/runsare refused before any Gateway RPC, andlistfilters out the sibling.sessions_yield. Asession:run lists it and the call is refused. Asession:run's CLI catalog and an ordinary turn's CLI catalog for the same session both includesessions_yield.src/cron/isolated-agent/run.tsdoes it:cron.remove {id: "job-1"}.removethrows "Automation invocation is no longer active" with no Gateway call.getis awaiting the Gateway, that call's result is refused, and the followingremoveis refused before dispatch.execution-context-self-removal-final-effect.test.ts(new) uses the realCronService, store, and Gateway cron handlers (thewithCronGatewayStatefixture). It forces a run of a stored job; inside the run, the CLI loopback automations tool removes the run's own job under the run's admitted Gateway caller.removereturnsremoved: true, the job is gone from the store, and the sibling stays.removeis held before it reaches persistence. The run settles (invocation closed, run context released, admission closed), then the real removal continues. The service's commit guard refuses it, the tool returns the refusal, and the stored job is unchanged (still present and enabled).sessions_yield.execution-context-owner-authority.test.tsnow expects the same owner-only tools on CLI as on embedded, including automations. The builder, fixtures, admission, board-effects, owner-final-effect, ingress automations scope, requester-yield and tool-resolution test files also pass (12 files).pnpm tsgo:core,pnpm tsgo:core:test, oxlint and oxfmt are clean on the changed files.Static replay (
scripts/dev/cron-context-replay.mtsover a copy of Josh's Gateway state, 109 jobs; totals: equal 102, gain-intended 52, loss 59, retarget 6, pause 7):gain-unexpected.automations: equal for all 102 ready jobs. Onmainthe 3 owner children were labeled gain-intended forself-and-parent-wake; they are equal now because the wake isn't offered.automationsCli: 42 gain-intended (child and detached CLI runs take the embedded self scope; before they had no tool), 4 equal (cap excludes automations), 56 loss. Every loss is asession:job: on CLI it narrows from the turn's owner-only rule to its own job, the same as embedded.requesterYield: 56 loss, allsession:jobs (2 enabled). Cause:session:jobs follow isolated jobs for yield.main's projection (equal 102, gain-intended 52, retarget 6, pause 7, loss 3). The 3ownerEmbeddedlosses and 7 pauses are the same rows onmain.Autoreview (Claude engine, P2; the Codex CLI failed authentication on this host): scoped-clean on the first head. On the second head it found one P2: an admitted context without an exec pin no longer fell back to the stored policy's pin. Fixed by keeping the exec pin on its existing source (row 15 left unchanged).