Skip to content

refactor(cron): refuse a scheduled run whose occurrence admission failed - #205297

Merged
obviyus merged 2 commits into
mainfrom
refactor/oa2-occurrence-scope
Nov 25, 2026
Merged

obviyus merged 2 commits into
mainfrom
refactor/oa2-occurrence-scope

Conversation

@obviyus

@obviyus obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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 (), 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).

obviyus and others added 2 commits November 25, 2026 16:52
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]>
@clawsweeper

clawsweeper Bot commented Nov 25, 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 scripts Repository scripts agents Agent runtime and tooling size: S labels Nov 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. labels Nov 25, 2026
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on head 82edaca61109 (isolated scratch Gateway, real model through the byte-forwarding relay):

  • R running-turn-finishes: pass
  • Q queued-input-refused-visibly: pass (0 provider requests with the queued marker, refusal visible in the transcript)
  • S stop-cancels: pass

verdict.json and results.jsonl are kept with the proof (pass: true, 62 s).

A creator who lost access still takes the existing CronOperatorSourceError refusal in restoreCronOperatorSource. That refusal runs before the occurrence mint, and this diff does not change it. The new refusal covers the case where occurrence admission itself fails. Six cells (owner, admin and member creators, each on a cron and a hook run) prove it through the real isolated cron runner. All six fail on base and pass on head.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 25, 2026
@clawsweeper

clawsweeper Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.”

  • Before: The failed occurrence can still start an agent run without its scheduled execution context.
  • After: Run admission throws a visible refusal containing the cause and recovery guidance before the agent starts.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and source-consistent, but the supplied live smoke does not demonstrate the changed refusal behavior.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An automation can start after its occurrence admission fails, leaving it without the execution context that defines its scheduled scope.
Reason: Refusing the failed start restores the existing admission contract, and the collaborator-authored PR records the intended compatibility tradeoff.

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: 82edaca61109348c93357e9a99d975d5519c8fd9

Before merge

None.

Findings

None.

Tests

  • Low-value test src/cron/isolated-agent/run.event-trigger-automations-scope.test.ts: Remove the owner/admin/member dimension: these values are profile ID strings, and every cell injects the identical failed occurrence without exercising distinct role admission; retain the cron and event refusal cases.
  • Missing end-to-end proof: Provide redacted Gateway or CLI evidence of an occurrence-mint failure producing the new visible refusal without starting inference, plus an upgrade run from v2026.11.10 showing an existing valid automation and its settings remain intact.
Agent review details

How this fits together

Cron 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]
Loading

Technical review

Best 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

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -8, Tests +37, Other -1. Total +28 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 13 21 -8
Tests 6 71 34 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 9 84 56 +28

Preflight source

Source 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

Metric Value Why it matters
Production versus test changes Production +13/-22; tests and test support +71/-34 Production shrinks by removing duplicate scope policy; fixture updates support the stricter admission contract, though the creator dimension adds redundant cases.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: Existing automations whose occurrence admission fails now refuse execution instead of continuing without context; the maintainer-authored PR explicitly accepts this behavior change.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • merge-risk: 🚨 compatibility: Existing automations whose occurrence admission fails now refuse execution instead of continuing without context; the maintainer-authored PR explicitly accepts this behavior change.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 execution lanes are retired.

Reviewed November 25, 2026, 6:38 AM ET / 11:38 UTC.

@obviyus
obviyus merged commit 89e944a into main Nov 25, 2026
223 of 225 checks passed
@obviyus
obviyus deleted the refactor/oa2-occurrence-scope branch November 25, 2026 11:46
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

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.

obviyus added a commit that referenced this pull request Nov 25, 2026
…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]>
obviyus added a commit that referenced this pull request Nov 25, 2026
… 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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
… 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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: S 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.

1 participant