Repository navigation
refactor(cron): refuse a scheduled run whose occurrence admission failed - #205297
Conversation
A cron or hook run whose occurrence admission failed started with no admitted context; the automations trigger fallback was then its only job limit. The start now refuses with the cause and a next step (run record + failure notice), and the trigger fallback is deleted. Co-authored-by: obviyus <[email protected]>
Service fixtures that run real isolated turns now admit occurrences like the Gateway; the trigger-scope suite admits its cron case, and owner/admin/member creators of cron and hook runs whose admission failed get the same refusal (red on base). The test of the removed missing-occurrence guard is deleted. Co-authored-by: obviyus <[email protected]>
|
🦞👀 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. |
|
E2E on head
A creator who lost access still takes the existing |
|
Codex review: needs maintainer review before merge. What this changesThis PR refuses scheduled runs whose execution context was not admitted and removes the trigger-based automations scope fallback. Example: The parent-session read for automation job-1 fails with “worker unavailable.”
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a current admission failure path using the existing run owner, and no definite production defect was found in the patch. Reviewed head: Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherCron and hook executors mint an execution context from an occurrence, pass it through shared run admission, and use the bound context to construct scoped tools. flowchart TD
A[Cron or hook occurrence] --> B[Occurrence context mint]
B --> C[Shared run admission]
C --> D[Refusal and error result]
C --> E[Admitted run context]
E --> F[Scoped tools and executor]
Technical reviewBest possible solution: Keep the ready-result check in shared run admission and derive scheduled tool scope from its bound execution context. Do we have a high-confidence way to reproduce the issue? Source establishes the path: a failed parent read produces a fail execution object that main accepts, and its bind method installs no context; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch fixes the invariant at the existing admission owner and removes the redundant fallback without adding state, wrappers, or configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2ac011e302a3. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -8, Tests +37, Other -1. Total +28 across 9 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 Reviewed November 25, 2026, 6:38 AM ET / 11:38 UTC. |
|
Landed as 89e944a. When a cron or hook occurrence's admission fails, the run is now refused before it starts. The run record and the failure notice give the cause and the next step. The automations trigger fallback is deleted, because no scheduled run starts without its admitted context. Proof: 6 creator × trigger cells fail on base and pass on head; Q/R/S E2E pass; CI is green (one check-lint checkout infrastructure failure, green on rerun); the local review is clean. |
…mission (#205346) ## Problem OA2 PR 6c, part 1 (DESIGN §4.8; split from #205297). A cron job saved without an operator source names its requester as a channel sender or a profile. Its owner bit was decided outside admission, by `checkRequesterOwner` in `src/cron/execution-context-admission.ts`, at two places: each scheduled run (occurrence mint) and each scheduler turn about the job (repair, notices) through `session-event-target`. That check used its own rules: a configured or linked-admin channel owner; for a profile, "named roles are off, or the Gateway owner profile". So a profile whose named role is `admin` was the owner in the Control UI but not in its own scheduled runs. ## Fix - New `admitScheduledRequesterGrant` in `src/gateway/operator-admission.ts` returns the requester's `TurnGrant`: - channel requester: `decideChannelOwnerPrincipal` (configured owner), else the sender's linked admin profile (`prepareChannelOperatorAdmin`, the same gatherer as before); - profile requester: `person` facts (with the job's agent, so a role's `agents` list applies) through `prepareOperatorAdmission` + `decideOperatorAdmission`. - Occurrence mint and scheduler turns take the owner bit from `grant.owner`. The run gets only the grant, never operator scopes (no scope widening). - Deleted `checkRequesterOwner` and the `requesterOwner` capture in `session-event-target` / `session-event-context` / `cron-job-turn-target` (renamed to `scheduledRequester` with its admitted `grant`). - Lint lists shrink: `OWNER_PRODUCER_FILES` 28 → 24, `TURN_FLAG_FILES` 19 → 18, `ADMISSION_FILES` 59 → 58. - Doctor's read-only replay (`execution-context-check.ts`) reads the requester's own profile (a transferred job's `ownerProfileId`, not its creator's). An admin-role profile requester is reported as unverified: its owner bit depends on the role's `agents` list and access policy, which only admission reads. New Doctor cells: admin-role requester (unverified), transferred job whose creator is admin and requester is member (loses owner tools; red without the fix). ## Decisions (recorded, not asked) - **Named widening:** a profile requester with an admin named role is now the owner of its scheduled runs (was not). This is the design rule (owner = `operator.admin` in the admitted scopes), the same answer the person gets in the Control UI. - **Kept fallback (today's answer, named):** on an install without named roles, every profile requester stays the owner. `person` facts would refuse them (no role → no scopes; PR 4 left that cell for later), which would take owner-only tools from existing jobs. The fallback lives inside the admission module, next to the decision, not in cron. - **Unchanged (today's answer):** trusted-policy jobs, unlinked legacy jobs and unbound parents keep owner via the existing `legacy`/`trusted-policy` basis in `execution-context.ts`. - **Scheduler turns for a channel owner** no longer carry the command-owner recovery reference; their queued successors re-admit the native sender, as every channel owner's queued work does (`prepareReplyCommandOwnerAuthority`). - **Split (next PR):** plugin requester-owner continuation (`openclaw-plugin-tools`, `tool-factory-context`, `bindRequesterOwnerIdentity`, the cron creator `requesterOwner` chain), `scheduled-message-invocation`, `message-action-dispatch`, `execution-context-registry`, `openclaw-tools`. That chain runs through `agent-run-user-turn`, `chat-send` and subagent requester custody and would put this PR over the file cap. ## Tests - New cell `execution-context-admission.test.ts` "admits a stored profile requester through its named role": admin role → owner, admin role limited to another agent → not owner, member role → not owner, untiered → owner. **Red on base `5cb1764fc2de`** (admin role: `owner: false, basis: "none"`), green on head. - Unchanged and green: `execution-context-owner-authority.test.ts` (trusted policy, unbound parent, untiered profile, removed profile, no requester: real embedded/Codex/CLI tool surfaces), the Discord configured-owner cell, `server-cron-notifications.repair.test.ts`. ## Evidence - Production lines (`src` + `scripts`, non-test, vs merge base): +126 / −127. - Pre-push: one `ocx test` call over 64 files (touched tests + direct importers of every changed source + importers of the cron test-support files). All green except `src/cron/service.pr-automation.test.ts` and `service.pr-automation-feedback.test.ts` (37 cases, "occurrence admission is not configured"): red on base `5cb1764fc2de` too (37 failed there), from #205297's fixture gap; imports no changed file. `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint clean; `pnpm check:changed` reds only on main's `CHANGELOG/2026.11.10.md` bot attribution and main's dead exports (none in this diff). - E2E (`one-admission-e2e/run.sh`, isolated Gateway, real `gpt-5.5`) on the final head (see PR comments): Q queued input refused visibly, R running turn finishes after revoke, S Stop cancels: all pass. - Legacy-job owner tools: proven at the integration tier (`execution-context-owner-authority.test.ts` builds the real embedded, Codex and CLI tool surfaces for an untiered profile job (owner tools) and a removed/non-owner requester (no owner tools)) plus the new admission cell for named roles. No real-Gateway run of a hand-written legacy job row; such rows cannot be created through the product any more. ## Review - Round 1 (P1, real): person admission skipped the role's `agents` check; the job's agent is now passed. Cell added. - Round 2 (P2, real): Doctor's preview ignored the same `agents` list; fixed, cells added. - Round 3 on `f0370ee7da42` (P2, real): Doctor read the creator's profile for a transferred job's requester; fixed, cell added. Review on the final head is the merge gate. - Round 4 on `e555208d1f82` (P2, real): Doctor's admin-role preview ignored access policy. Cut less: Doctor no longer re-derives that answer; it reports the requester as unverified. - Round 5 on final head `7f016c02292e`: clean (`patch is correct`, no findings). Five review runs exceeded the two-round cap in the pipeline; rounds 3-4 were Doctor-preview findings, each real and fixed (round 4 by cutting the re-derivation, not adding to it). Co-authored-by: Ayaan Zaidi <[email protected]>
… 24 toHex in Vitest (#205383) ## Problem On `main`, 43 cron tests in 5 files fail (#205368). They have two causes; the second one only showed up after the first was fixed. 1. **Occurrence admission is missing (#205297).** These `CronService` fixtures do not pass `admitScheduledOccurrence`. Since #205297, a scheduled run whose occurrence is not admitted is refused: "This automation's access could not be admitted (occurrence admission is not configured), so the run did not start." This breaks all 43 cases. 2. **Node 24 `toHex` writes wrong hex in Vitest workers (since 9651d63, 11-07).** Vitest starts Node 24.22.1 with `--js-base-64`. The experimental native `Uint8Array.prototype.toHex` writes bytes >= 0x80 as `O0`..`Vf` once the array has 8 or more bytes (`new Uint8Array(8).fill(0xab).toHex()` returns `QbQbQbQb…`). `@noble/hashes` `bytesToHex` uses the native method when it exists, so the PR auto-fix `declarationKey` (`session-pr:v1:<sha256 hex>:autoFix`) fails the `[a-f0-9]{64}` recipe check. Native GitHub observation is then skipped and the trigger throws "Cannot destructure property 'previous' of 'trigger.state' as it is null." 32 of the `service.pr-automation*` cases fail this way. They fail the same way on `89e944a83bd3^` (before #205297); the admission refusal hid it on `main`. Production is not affected: production Node runs without `--js-base-64`, so `toHex` is undefined and noble uses its own lookup table. ## Fix (test-only) - `run.account-policy`, `service.failure-alert-silent-reply`, `service.restart-session-event` and `service.pr-automation.test-support` (used by `service.pr-automation` and `service.pr-automation-feedback`) pass the real `admitScheduledOccurrence({ cfg, job, agentId: "main", trigger: "cron" })`, which is what the Gateway passes (`admitGatewayCronOccurrence`). The run-without-admission fallback stays deleted. No test now asserts the old behavior; each one admits the occurrence as production does. - `test/jsdom-compat.mts`: the existing Node 24 byte-view adapter (it already corrects `byteOffset`) now encodes `toHex` through `Buffer`. `toBase64` and `fromHex` are correct on 24.22.1 (checked for lengths 0-299) and keep the native path. Regression case in `test/jsdom-compat.test.ts`. - One line removed in `service.pr-automation.test-support.ts` (`const persisted …; return persisted` → `return …`) so the file stays under the 700-line limit. Production lines: +0 / −0. ## Evidence - Base `2a1418049ffc`: the 5 files had 43 failed / 8 passed. - With only the fixture change: 32 failed (all `service.pr-automation*`, the `trigger.state` error). Same 32 failed on `89e944a83bd3^` (before #205297). - Head: one `ocx test` call over the 5 cron files, `test/jsdom-compat.test.ts`, `test/jsdom-custom-elements.test.ts` and the hex-using tests (`ui/src/lib/bytes-base64`, `device-signing.node`, `owner-approval`, `openclaw-id/authority.nodes`, `freshness`): all passed (cron 51/51). - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint pass on the changed files. Fixes #205368 Co-authored-by: Ayaan Zaidi <[email protected]>
…led (openclaw#205297) ## Problem OA2 PR 4f (DESIGN §4.7). If a cron or hook occurrence's admission failed (`admitScheduledOccurrence` / `mint()` returned `status: "fail"`), the run **still started**: `bind()` bound no execution context, and the run had no admitted scope. Only the trigger fallback in `automations-run-scope.ts` limited it: a cron turn could act only on its own job, and a hook turn got no automations tool. Every other entry kind refuses a start that admission did not admit. ## Fix - `prepareCronRunAdmission`, the single run admission for every scheduled executor (isolated agent, in-session turn, trigger script, plugin command), refuses a minted result that is not `ready`. The error names the cause and the next step: "This automation's access could not be admitted (<cause>), so the run did not start. Recreate the automation from a chat that still has access." The run record shows it (`status: "error"`, embedded run never called), and the job's failure notice delivers it to the delivery target (default `failureAlert.after` is 1). - The trigger fallback in `resolveAutomationsRunScope` is deleted. Every scheduled run now has its admitted context, so the scope always comes from admission. `automations-run-scope.ts` leaves `CAPABILITY_PROVENANCE_FILES` (4 → 3). ## Decisions (recorded, not asked) - **Refuse instead of carrying the scope.** This is the same rule as every other entry kind. No new state: the existing refusal path (error result + failure notice) carries it. - **Accepted edge:** a plugin-command job whose parent conversation is archived between occurrence admission and the run's mint now gets a refusal instead of running without context. - **Split (PR 6c, not in this PR):** the cron/requester-owner continuation producers (`execution-context-admission` `checkRequesterOwner`, `session-event-target`/`session-event-context` requester owner, `cron-job-turn-target`, `execution-context-registry`, `openclaw-tools`, `openclaw-plugin-tools` + `tool-factory-context` owner continuation, `scheduled-message-invocation`, `message-action-dispatch`) all derive from legacy scheduled requesters (channel / profile / unknown, no stored operator source) that have no admitted grant. Moving them onto `grant.owner` first needs occurrence admission to admit those requesters through `decideOperatorAdmission` (channel → `decideChannelOwnerPrincipal`, profile → `person` facts). That is over the ~25-file cap together with this change, so it is a separate PR. ## Tests - New matrix cells (`run.event-trigger-automations-scope.test.ts`): owner / admin / member job creators × cron / hook trigger, occurrence admission failed → `status: "error"` with the cause and next step, no embedded run, no automations RPC. **All 6 red on base `26cdef5cc1df`, green on head.** - Changed: the cron-trigger scope case now admits its occurrence (scope from admission, not the fallback). The "unadmitted event turn gets a gated tool" case is replaced by the refusal cells. Two `CronService` fixtures that run real isolated turns (`isolated-agent.auth-continuity.integration`, `message-tool.cron.test-support`) now pass the real `admitScheduledOccurrence` dep, as the Gateway does. `TEST_SCHEDULED_OCCURRENCE`/`EXECUTION` mint a ready context that binds nothing. - Deleted: `prepareCronRunAdmission` "refuses a scheduled run that carries no admitted occurrence" (a type-required argument cast away; the guard is replaced by the result check). ## Evidence - Production lines (`src` + `scripts`, non-test): +13 / −22. - Pre-push: one `ocx test` call over 60 files (touched tests + importers of every changed source / test-support). Every failure was fixed and rerun green, except `session-companion-ask.test.ts` (7 cases), which is red on base `26cdef5cc1df` too and imports no changed file. `pnpm tsgo:core`, `tsgo:test`, oxfmt and oxlint are clean on changed files. - E2E: see the PR comments (Q/R/S). Co-authored-by: Ayaan Zaidi <[email protected]>
…mission (openclaw#205346) ## Problem OA2 PR 6c, part 1 (DESIGN §4.8; split from openclaw#205297). A cron job saved without an operator source names its requester as a channel sender or a profile. Its owner bit was decided outside admission, by `checkRequesterOwner` in `src/cron/execution-context-admission.ts`, at two places: each scheduled run (occurrence mint) and each scheduler turn about the job (repair, notices) through `session-event-target`. That check used its own rules: a configured or linked-admin channel owner; for a profile, "named roles are off, or the Gateway owner profile". So a profile whose named role is `admin` was the owner in the Control UI but not in its own scheduled runs. ## Fix - New `admitScheduledRequesterGrant` in `src/gateway/operator-admission.ts` returns the requester's `TurnGrant`: - channel requester: `decideChannelOwnerPrincipal` (configured owner), else the sender's linked admin profile (`prepareChannelOperatorAdmin`, the same gatherer as before); - profile requester: `person` facts (with the job's agent, so a role's `agents` list applies) through `prepareOperatorAdmission` + `decideOperatorAdmission`. - Occurrence mint and scheduler turns take the owner bit from `grant.owner`. The run gets only the grant, never operator scopes (no scope widening). - Deleted `checkRequesterOwner` and the `requesterOwner` capture in `session-event-target` / `session-event-context` / `cron-job-turn-target` (renamed to `scheduledRequester` with its admitted `grant`). - Lint lists shrink: `OWNER_PRODUCER_FILES` 28 → 24, `TURN_FLAG_FILES` 19 → 18, `ADMISSION_FILES` 59 → 58. - Doctor's read-only replay (`execution-context-check.ts`) reads the requester's own profile (a transferred job's `ownerProfileId`, not its creator's). An admin-role profile requester is reported as unverified: its owner bit depends on the role's `agents` list and access policy, which only admission reads. New Doctor cells: admin-role requester (unverified), transferred job whose creator is admin and requester is member (loses owner tools; red without the fix). ## Decisions (recorded, not asked) - **Named widening:** a profile requester with an admin named role is now the owner of its scheduled runs (was not). This is the design rule (owner = `operator.admin` in the admitted scopes), the same answer the person gets in the Control UI. - **Kept fallback (today's answer, named):** on an install without named roles, every profile requester stays the owner. `person` facts would refuse them (no role → no scopes; PR 4 left that cell for later), which would take owner-only tools from existing jobs. The fallback lives inside the admission module, next to the decision, not in cron. - **Unchanged (today's answer):** trusted-policy jobs, unlinked legacy jobs and unbound parents keep owner via the existing `legacy`/`trusted-policy` basis in `execution-context.ts`. - **Scheduler turns for a channel owner** no longer carry the command-owner recovery reference; their queued successors re-admit the native sender, as every channel owner's queued work does (`prepareReplyCommandOwnerAuthority`). - **Split (next PR):** plugin requester-owner continuation (`openclaw-plugin-tools`, `tool-factory-context`, `bindRequesterOwnerIdentity`, the cron creator `requesterOwner` chain), `scheduled-message-invocation`, `message-action-dispatch`, `execution-context-registry`, `openclaw-tools`. That chain runs through `agent-run-user-turn`, `chat-send` and subagent requester custody and would put this PR over the file cap. ## Tests - New cell `execution-context-admission.test.ts` "admits a stored profile requester through its named role": admin role → owner, admin role limited to another agent → not owner, member role → not owner, untiered → owner. **Red on base `8ea184867868`** (admin role: `owner: false, basis: "none"`), green on head. - Unchanged and green: `execution-context-owner-authority.test.ts` (trusted policy, unbound parent, untiered profile, removed profile, no requester: real embedded/Codex/CLI tool surfaces), the Discord configured-owner cell, `server-cron-notifications.repair.test.ts`. ## Evidence - Production lines (`src` + `scripts`, non-test, vs merge base): +126 / −127. - Pre-push: one `ocx test` call over 64 files (touched tests + direct importers of every changed source + importers of the cron test-support files). All green except `src/cron/service.pr-automation.test.ts` and `service.pr-automation-feedback.test.ts` (37 cases, "occurrence admission is not configured"): red on base `8ea184867868` too (37 failed there), from openclaw#205297's fixture gap; imports no changed file. `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint clean; `pnpm check:changed` reds only on main's `CHANGELOG/2026.11.10.md` bot attribution and main's dead exports (none in this diff). - E2E (`one-admission-e2e/run.sh`, isolated Gateway, real `gpt-5.5`) on the final head (see PR comments): Q queued input refused visibly, R running turn finishes after revoke, S Stop cancels: all pass. - Legacy-job owner tools: proven at the integration tier (`execution-context-owner-authority.test.ts` builds the real embedded, Codex and CLI tool surfaces for an untiered profile job (owner tools) and a removed/non-owner requester (no owner tools)) plus the new admission cell for named roles. No real-Gateway run of a hand-written legacy job row; such rows cannot be created through the product any more. ## Review - Round 1 (P1, real): person admission skipped the role's `agents` check; the job's agent is now passed. Cell added. - Round 2 (P2, real): Doctor's preview ignored the same `agents` list; fixed, cells added. - Round 3 on `f0370ee7da42` (P2, real): Doctor read the creator's profile for a transferred job's requester; fixed, cell added. Review on the final head is the merge gate. - Round 4 on `e555208d1f82` (P2, real): Doctor's admin-role preview ignored access policy. Cut less: Doctor no longer re-derives that answer; it reports the requester as unverified. - Round 5 on final head `7f016c02292e`: clean (`patch is correct`, no findings). Five review runs exceeded the two-round cap in the pipeline; rounds 3-4 were Doctor-preview findings, each real and fixed (round 4 by cutting the re-derivation, not adding to it). Co-authored-by: Ayaan Zaidi <[email protected]>
… 24 toHex in Vitest (openclaw#205383) ## Problem On `main`, 43 cron tests in 5 files fail (openclaw#205368). They have two causes; the second one only showed up after the first was fixed. 1. **Occurrence admission is missing (openclaw#205297).** These `CronService` fixtures do not pass `admitScheduledOccurrence`. Since openclaw#205297, a scheduled run whose occurrence is not admitted is refused: "This automation's access could not be admitted (occurrence admission is not configured), so the run did not start." This breaks all 43 cases. 2. **Node 24 `toHex` writes wrong hex in Vitest workers (since 5219fd6, 11-07).** Vitest starts Node 24.22.1 with `--js-base-64`. The experimental native `Uint8Array.prototype.toHex` writes bytes >= 0x80 as `O0`..`Vf` once the array has 8 or more bytes (`new Uint8Array(8).fill(0xab).toHex()` returns `QbQbQbQb…`). `@noble/hashes` `bytesToHex` uses the native method when it exists, so the PR auto-fix `declarationKey` (`session-pr:v1:<sha256 hex>:autoFix`) fails the `[a-f0-9]{64}` recipe check. Native GitHub observation is then skipped and the trigger throws "Cannot destructure property 'previous' of 'trigger.state' as it is null." 32 of the `service.pr-automation*` cases fail this way. They fail the same way on `db9817c10d7d^` (before openclaw#205297); the admission refusal hid it on `main`. Production is not affected: production Node runs without `--js-base-64`, so `toHex` is undefined and noble uses its own lookup table. ## Fix (test-only) - `run.account-policy`, `service.failure-alert-silent-reply`, `service.restart-session-event` and `service.pr-automation.test-support` (used by `service.pr-automation` and `service.pr-automation-feedback`) pass the real `admitScheduledOccurrence({ cfg, job, agentId: "main", trigger: "cron" })`, which is what the Gateway passes (`admitGatewayCronOccurrence`). The run-without-admission fallback stays deleted. No test now asserts the old behavior; each one admits the occurrence as production does. - `test/jsdom-compat.mts`: the existing Node 24 byte-view adapter (it already corrects `byteOffset`) now encodes `toHex` through `Buffer`. `toBase64` and `fromHex` are correct on 24.22.1 (checked for lengths 0-299) and keep the native path. Regression case in `test/jsdom-compat.test.ts`. - One line removed in `service.pr-automation.test-support.ts` (`const persisted …; return persisted` → `return …`) so the file stays under the 700-line limit. Production lines: +0 / −0. ## Evidence - Base `9c9aa3325401`: the 5 files had 43 failed / 8 passed. - With only the fixture change: 32 failed (all `service.pr-automation*`, the `trigger.state` error). Same 32 failed on `db9817c10d7d^` (before openclaw#205297). - Head: one `ocx test` call over the 5 cron files, `test/jsdom-compat.test.ts`, `test/jsdom-custom-elements.test.ts` and the hex-using tests (`ui/src/lib/bytes-base64`, `device-signing.node`, `owner-approval`, `openclaw-id/authority.nodes`, `freshness`): all passed (cron 51/51). - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint pass on the changed files. Fixes openclaw#205368 Co-authored-by: Ayaan Zaidi <[email protected]>
…led (#205297) ## Problem OA2 PR 4f (DESIGN §4.7). If a cron or hook occurrence's admission failed (`admitScheduledOccurrence` / `mint()` returned `status: "fail"`), the run **still started**: `bind()` bound no execution context, and the run had no admitted scope. Only the trigger fallback in `automations-run-scope.ts` limited it: a cron turn could act only on its own job, and a hook turn got no automations tool. Every other entry kind refuses a start that admission did not admit. ## Fix - `prepareCronRunAdmission`, the single run admission for every scheduled executor (isolated agent, in-session turn, trigger script, plugin command), refuses a minted result that is not `ready`. The error names the cause and the next step: "This automation's access could not be admitted (<cause>), so the run did not start. Recreate the automation from a chat that still has access." The run record shows it (`status: "error"`, embedded run never called), and the job's failure notice delivers it to the delivery target (default `failureAlert.after` is 1). - The trigger fallback in `resolveAutomationsRunScope` is deleted. Every scheduled run now has its admitted context, so the scope always comes from admission. `automations-run-scope.ts` leaves `CAPABILITY_PROVENANCE_FILES` (4 → 3). ## Decisions (recorded, not asked) - **Refuse instead of carrying the scope.** This is the same rule as every other entry kind. No new state: the existing refusal path (error result + failure notice) carries it. - **Accepted edge:** a plugin-command job whose parent conversation is archived between occurrence admission and the run's mint now gets a refusal instead of running without context. - **Split (PR 6c, not in this PR):** the cron/requester-owner continuation producers (`execution-context-admission` `checkRequesterOwner`, `session-event-target`/`session-event-context` requester owner, `cron-job-turn-target`, `execution-context-registry`, `openclaw-tools`, `openclaw-plugin-tools` + `tool-factory-context` owner continuation, `scheduled-message-invocation`, `message-action-dispatch`) all derive from legacy scheduled requesters (channel / profile / unknown, no stored operator source) that have no admitted grant. Moving them onto `grant.owner` first needs occurrence admission to admit those requesters through `decideOperatorAdmission` (channel → `decideChannelOwnerPrincipal`, profile → `person` facts). That is over the ~25-file cap together with this change, so it is a separate PR. ## Tests - New matrix cells (`run.event-trigger-automations-scope.test.ts`): owner / admin / member job creators × cron / hook trigger, occurrence admission failed → `status: "error"` with the cause and next step, no embedded run, no automations RPC. **All 6 red on base `ca087d400832`, green on head.** - Changed: the cron-trigger scope case now admits its occurrence (scope from admission, not the fallback). The "unadmitted event turn gets a gated tool" case is replaced by the refusal cells. Two `CronService` fixtures that run real isolated turns (`isolated-agent.auth-continuity.integration`, `message-tool.cron.test-support`) now pass the real `admitScheduledOccurrence` dep, as the Gateway does. `TEST_SCHEDULED_OCCURRENCE`/`EXECUTION` mint a ready context that binds nothing. - Deleted: `prepareCronRunAdmission` "refuses a scheduled run that carries no admitted occurrence" (a type-required argument cast away; the guard is replaced by the result check). ## Evidence - Production lines (`src` + `scripts`, non-test): +13 / −22. - Pre-push: one `ocx test` call over 60 files (touched tests + importers of every changed source / test-support). Every failure was fixed and rerun green, except `session-companion-ask.test.ts` (7 cases), which is red on base `ca087d400832` too and imports no changed file. `pnpm tsgo:core`, `tsgo:test`, oxfmt and oxlint are clean on changed files. - E2E: see the PR comments (Q/R/S). Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 89e944a) Release adaptation: Enforce the existing ready result in the host admission owner; keep the stable synchronous fixture contract, no-result guard and defensive legacy tool scoping. Exclude the main-only lint and authority cleanup. Companion audit: PR #205297 is the selected behavior; no later companion required. Preserve legacy saved jobs and event scope through existing exact host admission. Co-authored-by: RomneyDa <[email protected]>
Problem
OA2 PR 4f (DESIGN §4.7). If a cron or hook occurrence's admission failed (
admitScheduledOccurrence/mint()returnedstatus: "fail"), the run still started:bind()bound no execution context, and the run had no admitted scope. Only the trigger fallback inautomations-run-scope.tslimited it: a cron turn could act only on its own job, and a hook turn got no automations tool. Every other entry kind refuses a start that admission did not admit.Fix
prepareCronRunAdmission, the single run admission for every scheduled executor (isolated agent, in-session turn, trigger script, plugin command), refuses a minted result that is notready. The error names the cause and the next step: "This automation's access could not be admitted (), so the run did not start. Recreate the automation from a chat that still has access." The run record shows it (status: "error", embedded run never called), and the job's failure notice delivers it to the delivery target (defaultfailureAlert.afteris 1).resolveAutomationsRunScopeis deleted. Every scheduled run now has its admitted context, so the scope always comes from admission.automations-run-scope.tsleavesCAPABILITY_PROVENANCE_FILES(4 → 3).Decisions (recorded, not asked)
execution-context-admissioncheckRequesterOwner,session-event-target/session-event-contextrequester owner,cron-job-turn-target,execution-context-registry,openclaw-tools,openclaw-plugin-tools+tool-factory-contextowner continuation,scheduled-message-invocation,message-action-dispatch) all derive from legacy scheduled requesters (channel / profile / unknown, no stored operator source) that have no admitted grant. Moving them ontogrant.ownerfirst needs occurrence admission to admit those requesters throughdecideOperatorAdmission(channel →decideChannelOwnerPrincipal, profile →personfacts). That is over the ~25-file cap together with this change, so it is a separate PR.Tests
run.event-trigger-automations-scope.test.ts): owner / admin / member job creators × cron / hook trigger, occurrence admission failed →status: "error"with the cause and next step, no embedded run, no automations RPC. All 6 red on baseca087d400832, green on head.CronServicefixtures that run real isolated turns (isolated-agent.auth-continuity.integration,message-tool.cron.test-support) now pass the realadmitScheduledOccurrencedep, as the Gateway does.TEST_SCHEDULED_OCCURRENCE/EXECUTIONmint a ready context that binds nothing.prepareCronRunAdmission"refuses a scheduled run that carries no admitted occurrence" (a type-required argument cast away; the guard is replaced by the result check).Evidence
src+scripts, non-test): +13 / −22.ocx testcall over 60 files (touched tests + importers of every changed source / test-support). Every failure was fixed and rerun green, exceptsession-companion-ask.test.ts(7 cases), which is red on baseca087d400832too and imports no changed file.pnpm tsgo:core,tsgo:test, oxfmt and oxlint are clean on changed files.