Skip to content

fix(automations): let automation notice turns read caller-visible automations - #180304

Merged
VACInc merged 3 commits into
openclaw:mainfrom
VACInc:fix/event-turn-automation-reads
Oct 22, 2026
Merged

VACInc merged 3 commits into
openclaw:mainfrom
VACInc:fix/event-turn-automation-reads

Conversation

@VACInc

@VACInc VACInc commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

High Level TLDR

When an automation fails and gets auto-disabled, OpenClaw posts a notice into the owning conversation: "Check automation history for details." That notice starts a new agent turn. Because no human sent it, the turn has no owner identity, and the automations tool refuses every call with "automations needs the owner's authority, and this turn was not started by the owner." So the agent cannot do the one thing the notice tells it to do, and the owner has to send another message just to get the failure reason.

This PR lets that scheduler notice turn run the read-only, caller-scoped automations actions (list, get, runs). Every write (add, update, remove, run, wake), Gateway-wide management, and every other owner-only tool (gateway, nodes, sessions, ...) stay gated exactly as before.

Root Cause

  • resolveTurnToolSurface (src/agents/agent-tools.turn-authority.ts) gates every tool in GATEWAY_OWNER_ONLY_CORE_TOOLS (src/security/dangerous-tools.ts) when senderIsOwner === false. automations is in that list.
  • Scheduler notices enter through enqueueSessionEventForHost with source: "cron" (src/gateway/server-cron-targets.ts). buildSessionEventContext (src/auto-reply/reply/session-event-context.ts) builds a sender-less context (InputProvenance {kind: "internal_system", sourceTool: "cron"}, CommandAuthorized: false, no SenderId), so resolveCommandAuthorization returns senderIsOwner: false. This is intended: a system turn must not borrow the owner's identity.
  • Without an owner grant, the scheduler itself already limits the automations tool to caller-visible records: bindCronManagementGrant only mints Gateway-wide management for fresh owner or Control UI admin turns, and cron.list/get/runs filter through readCronCallerScope + cronJobMatchesCallerScope (agent-created jobs are bound to their creator session). The tool description already promises this ("Other turns see caller-visible jobs and scoped counts only"). The owner-only gate blocks the whole tool before that existing caller scope can apply.

Evidence from a production Gateway (Telegram group topic, Claude CLI runtime over the MCP loopback):

  • A one-shot automation failed at its first run (Automation has no recorded inference account ...) and was auto-disabled.
  • The notice turn's transcript row: provenance: {kind: "internal_system", sourceTool: "cron"}, senderIsOwner: false.
  • The agent's automations get and runs calls on that turn both returned automations needs the owner's authority, and this turn was not started by the owner. Do not retry automations.
  • One owner message later, the same runs call returned the failure reason immediately.
  • Over the previous 8 days on that install, 52 automations calls were refused this way, all on automation failure notices.

Change

  • isSchedulerSystemTurn({trigger, inputProvenance}): true only for trigger === "event" (derived by the session-event executor from internalEventExecution, which clients cannot set) and internal_system provenance with sourceTool === "cron". This covers scheduler notices and wakes. It excludes scheduled runs (cron trigger, which can carry hook-mapped external content), webhook wakes (hook source), exec completions (exec source), inter-session input, and client-asserted provenance on the agent RPC (its trigger is never event).
  • resolveTurnToolSurface takes schedulerSystemTurn. On such a turn, the owner-gated automations tool keeps its stable definition (no prompt-prefix change) but its executor is split: actions in CRON_SCOPED_READ_ACTIONS (list, get, runs, the same set the recovery read-only mode uses) run the turn-policy instance; everything else returns the owner gate. The action is read with readToolStringParam, like the executor.
  • The split applies only when the turn policy itself admits the tool (a completion handoff's requester denial still wins) and the tool has no prepare hooks (otherwise it falls back to the full gate). The tool stays marked execution-unavailable and out of exportedTools/callableTools, so descendants never inherit it.
  • Both tool assembly owners pass the flag: the embedded runner (src/agents/agent-tools.ts) and the Gateway MCP loopback used by CLI runtimes (src/gateway/tool-resolution.ts).
  • CRON_SCOPED_READ_ACTIONS moves to the light automations-tool-name.ts so the turn-authority module does not import the cron schema module.

Scope boundary

  • No change to senderIsOwner, to GATEWAY_OWNER_ONLY_CORE_TOOLS, or to any other owner-only tool on system turns.
  • No change to which records the scheduler returns; this only stops the owner gate from pre-empting the scheduler's existing caller scope.
  • Not covered: exec completion wakes, scheduled runs in the same session, plugin events, and heartbeat-delivered reminders (heartbeat delivery is retired by the automations migration).
  • Not covered: the failure-repair turn (sourceTool: "cron_failure_repair"). When a failure-alert route exists, a failed owned one-shot gets that turn instead of the auto-disable notice. It runs through the agent RPC, where a client can assert the same provenance, so there is no host-only signal to key a read exception on yet. Its brief already embeds the last error. This PR covers the auto-disable notice, which is what installs with cron.failureAlert.enabled: false receive.
  • Which jobs a notice turn can see is decided entirely by the scheduler's existing caller scope: jobs owned by the chat that receives the notice. A job created with sessionTarget: "isolated" has no sessionKey, so its notice goes to the agent's main session, and that session cannot see a job owned by another chat. That is unchanged scheduler behavior.

Verification

Real behavior proof

Final-effect boundaries on a real failed automation (test/e2e/qa-lab/runtime/system-turn-automation-read-boundaries.e2e.test.ts, new in this update). This runs an isolated in-process Gateway with its own temp HOME and state dir, the real cron scheduler (clock-controlled), real session-event admission, the embedded runtime, and the real cron.get / cron.list / cron.runs handlers. Model HTTP is the only synthetic part. Two test seams sit around the real code: one pauses readCronRunHistoryRecords after it returns, so a change can be injected during the awaited read, and one records what the real cron.runs handler responded.

  1. An owner turn in chat A creates two one-shot automations (Owned proof, Closing proof). An owner turn in chat B creates Foreign proof. The config has cron.failureAlert.enabled: false, same as the production install.
  2. The clock reaches Owned proof. Its run fails (the provider returns 400), and the scheduler disables the one-shot and posts the real notice into chat A: ⚠️ Automation "Owned proof" was auto-disabled after 1 consecutive run failures.
  3. On that notice turn the model calls each action in turn. Tool results as recorded (IDs shortened):
get  <owned>    -> {"id":"<owned>","name":"Owned proof","enabled":false,"owner":{"agentId":"main","sessionKey":"agent:main:dashboard:<chat-A>","accountId":"default"}}
runs <owned>    -> {"total":1,"entries":[{"jobId":"<owned>","status":"error","completionStatus":"failed","error":"LLM request rejected: proof model rejected the run | 400"}]}
get  <foreign>  -> cron job not found: <foreign>. List automations and retry with a current job id. ...
runs <foreign>  -> Automation not found: <foreign>. List automations and retry with a current job id. ...
list            -> scope "caller", jobs: [Closing proof, Owned proof]   (Foreign proof absent)
update/remove/add/run/status -> On this automation-started turn, automations runs only the list, get, runs actions. Other actions need the owner's authority, and this turn was not started by the owner. Do not retry them.
gateway         -> gateway needs the owner's authority, and this turn was not started by the owner. Do not retry gateway.
  1. Ownership ends during an awaited read. The notice turn calls runs <owned>. While history hydration is paused, an operator calls cron.remove <owned>. The handler's disclosure-time recheck returns Automation not found: <owned> and no entries.
  2. Run closes during an awaited read. The clock reaches Closing proof, which fails the same way and gets its own auto-disable notice. That notice turn calls runs <closing>. While hydration is paused, chat.abort stops the run. The real handler sends no response at all; it throws TypeError: agent runtime authority is no longer active. No provider request ever receives that tool result.
  3. Forged provenance. A second client with only operator.write (not an owner) sends an agent turn into chat A with inputProvenance: {kind: "internal_system", sourceTool: "cron"}. Its automations get <closing> returns automations needs the owner's authority, and this turn was not started by the owner. Do not retry automations., because the event trigger comes from the host and this turn has the user trigger.
  4. After the run, cron.list (operator) shows Closing proof and Foreign proof, so the notice turn's refused remove changed nothing.
node_modules/.bin/vitest run --config test/vitest/vitest.e2e.config.ts \
  test/e2e/qa-lab/runtime/system-turn-automation-read-boundaries.e2e.test.ts \
  test/e2e/qa-lab/runtime/system-turn-automation-reads.e2e.test.ts
 ✓ ...system-turn-automation-read-boundaries.e2e.test.ts > serves an automation notice turn only its own automation reads at the final effect 36238ms
 ✓ ...system-turn-automation-reads.e2e.test.ts > lets an automation notice turn read caller-visible automations 20274ms
      Tests  2 passed (2)

Red on base: with the six production files from main (agent-tools.ts, agent-tools.turn-authority.ts, automations-tool-name.ts, cron-tool-schema.ts, cron-tool.ts, tool-resolution.ts), the same test fails at the first owned read:

AssertionError: expected 'automations needs the owner\'s author…' not to contain 'needs the owner\'s authority'
Received: "automations needs the owner's authority, and this turn was not started by the owner. Do not retry automations."

The original e2e (system-turn-automation-reads.e2e.test.ts) is kept. It sends a notice through the scheduler's producer and checks list. It was red on base at the previous head and is green on this head.

Existing handler suites cover the boundaries that the e2e does not set up end to end, and they pass on this head: cron.validation.test.ts (foreign account: keeps new jobs scoped to their creator account while preserving accountless legacy jobs; scheduled-authority session binding; withholds $scope history when client authority closes during the $phase read; rechecks the scoped job after reading history %s), cron.history.test.ts, cron.ownership-matrix.test.ts, and cron-caller-scope.test.ts: 4 files, 161 tests passed.

Regression tests (red on base, green here):

  • src/agents/agent-tools.turn-authority.test.ts: reads (list, get, runs) reach the executor; status/add/update/remove/run/wake/missing action stay gated; gateway stays gated; nothing is exported to descendants; a completion handoff's requester denial wins; reads run the turn-policy instance; the isSchedulerSystemTurn matrix (event/cron/user trigger, cron/exec source, inter_session kind).
  • src/gateway/tool-resolution.exclude.test.ts (MCP loopback surface with a real admitted run context): reads are served only for trigger=event + internal_system/cron. They are refused for a user trigger with spoofed provenance, an exec source, inter_session, and missing provenance. update and gateway stay gated in every case.

Consumer suites on this head: agent-tools.turn-authority, tool-resolution.exclude, agent-tools.prefix-stability, cron-tool, cron-tool.automation, agent-tools.create-openclaw-coding-tools, agent-tools.construction-routing, gateway-tool.assembly, agent-tools.session-portal, cli-runner/prepare.completion-tools, agent-tools-agent-config: 11 files, 252 tests pass. Root test tsgo shards (including test-root-e2e) pass.

Merge conflict: main merged in (merge commit, no rebase). The only conflict was in agent-tools.turn-authority.ts. The resolution keeps main's removal of the unused withheld input, and schedulerSystemTurn plus the split executor are unchanged.

check:changed against main (run locally; main's pinned pnpm 12.15.0 is newer than this host's minimum release age, so the run used the installed pnpm): format, lint, core tsgo shards, assertion SAFETY and line-cap ratchets pass for the changed files. Three checks fail on files outside this diff: the max-lines suppression ratchet (three ui/ files), the core test shard root budget (gateway-root: 724, infra: 738 > 720; this PR adds no core test roots), and the full-tree dead export scan (exports in heartbeat, channels, and other files that this PR does not touch).

Performance: resolveTurnToolSurface micro-benchmark (75 tools, 15 owner-only denied, scheduler turn, 2000 warmup + 15x5000 calls, Node 24.19, same host), three runs each. Median µs/call: base 10.23 / 10.56 / 9.64, PR 9.98 / 10.67 / 10.42. No measurable difference. The merge from main only removed the unused withheld filter from this function.

What was not tested

  • A real Claude CLI process over the MCP loopback on an isolated Gateway. That would need real model credentials inside the isolated HOME, and a real model would pick its own tool calls, so the boundary cases could not be scripted. The loopback assembles the same automations tool, which calls the same cron.get/list/runs handlers, and resolveGatewayScopedTools is covered with a real admitted run context. The embedded runtime is proven end to end above.
  • A foreign account through the e2e: WebChat has only the default account. The account boundary is covered by the existing handler tests listed above.
  • tools.toolSearch / code mode dispatch on the notice turn (the e2e turns both off).
  • A live Telegram notice on the patched build.

@VACInc VACInc self-assigned this Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 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 gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: d10334a2ddfaa19daa5221d4e865c6050401d273
  • Maintainer: @VACInc
  • Repository role: maintain

These security sensitive changes were made:

  • src/agents/agent-tools.turn-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Allows trusted scheduler notice turns to list and inspect caller-visible automations while retaining owner gates for other actions.

Example: The one-shot automation “Owned proof” fails and posts an auto-disable notice into its creating conversation.

  • Before: The notice turn cannot read the automation’s failure history because automations requires owner authority.
  • After: The notice turn reads the failed run, while another conversation’s automation and all write actions remain inaccessible.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused repair with sufficient final-effect authority proof and green exact-head CI; duplicate E2E coverage adds avoidable maintenance cost.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): For this maintainer-authored authority change, the supplied isolated Gateway trace and inspected production-path harness exercise allowed reads, foreign-chat rejection, forbidden writes, forged provenance, job removal, and run cancellation before disclosure; model HTTP is synthetic, and a live Claude CLI or Telegram run is not claimed.
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 failure notice asks the agent to inspect history, but its senderless turn cannot perform that inspection.
Reason: The maintainer-authored direction repairs a recorded workflow failure while preserving caller scope and all write restrictions.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current automation-notice inspection failure without granting owner identity; no introduced correctness or security defect was found.

Priority: P2
Reviewed head: d10334a2ddfaa19daa5221d4e865c6050401d273

Before merge

None.

Findings

None.

Tests

  • Low-value test test/e2e/qa-lab/runtime/system-turn-automation-reads.e2e.test.ts: Remove this earlier single-read Gateway smoke test: the new boundary E2E exercises the same notice admission and list path through a real scheduler failure, with stronger ownership and cancellation assertions.
Agent review details

How this fits together

Embedded agents and CLI loopback clients assemble tools through a shared turn-authority gate; permitted automation reads then reach scheduler handlers that enforce current caller visibility.

flowchart TD
  A[Scheduler failure notice] --> B[Host session event admission]
  B --> C[Embedded or CLI tool assembly]
  C --> D[Shared turn authority gate]
  D --> E[Caller scoped scheduler reads]
  D --> F[Owner gated other actions]
  E --> G[Visible automation and run history]
Loading

Technical review

Best possible solution:

Keep the narrow read exception in the shared turn-authority owner and retain scheduler-owned visibility enforcement.

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

Current-main source blocks every automation call on the senderless notice turn, and the contributor records the same failure through the Gateway with base production files; this review executed no target code.

Is this the best way to solve the issue?

The fix preserves stable tool definitions and uses the existing authority gate and scheduler visibility owners, with both embedded and CLI assembly callers updated.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main still denies notice reads: Fetched main retains the blanket owner-only executor gate, so the central failure remains unresolved upstream. (src/agents/agent-tools.turn-authority.ts:32, b1094285fc42)
  • Narrow exception at the existing owner: The introduced diff requires the host event trigger and scheduler provenance, preserves requester-policy denial, dispatches only list/get/runs, and excludes partial access from descendant snapshots. (src/agents/agent-tools.turn-authority.ts:61, d10334a2ddfa)
  • Disclosure-time authority remains enforced: The existing history handler rechecks active runtime authority and current job visibility after awaited history hydration and before returning entries. (src/gateway/server-methods/cron-runs.ts:141, d10334a2ddfa)
  • Supplied final-effect proof: The full PR body records an isolated Gateway exercising an actual failed automation, owned reads, foreign-chat rejection, denied writes, forged provenance, removal during hydration, and cancellation before disclosure; it also records the intended first-read failure with base production files. (test/e2e/qa-lab/runtime/system-turn-automation-read-boundaries.e2e.test.ts:174, d10334a2ddfa)
  • Exact-head CI: Paginated check results include a successful openclaw/ci-gate and no failed or pending check runs. (d10334a2ddfa)
  • Policy and scope: Root and all applicable ancestor AGENTS.md files were read and applied; no maintainer-notes directory exists, and the patch changes no persisted format, config option, dependency, or release-owned changelog. (AGENTS.md, d10334a2ddfa)

Likely related people:

  • Ayaan Zaidi: Raw commit b326dc0 adds src/agents/agent-tools.turn-authority.ts:15 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b326dc020122; files: src/agents/agent-tools.turn-authority.ts)
  • Peter Steinberger: Raw commit 335b425 adds src/gateway/tool-resolution.ts:679 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 335b425d2fd6; files: src/gateway/tool-resolution.ts)

PR surface

Source +67, Tests +942. Total +1009 across 10 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 6 79 12 +67
Tests 4 943 1 +942
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 1022 13 +1009

Review metrics

Metric Value Why it matters
Production versus test changes Production +79/-12 lines; tests +943/-1 lines Production growth implements the shared authorization exception; most test growth covers real scheduler and stale-authority boundaries, with one redundant smoke test.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Restores automatic failure-history inspection for scheduler notices with a bounded read-only change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-22T04:59:09.614Z sha 0d47baa :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-22T06:46:57.145Z sha d10334a :: needs maintainer review before merge. :: none
  • reviewed 2026-10-22T06:53:10.885Z sha d10334a :: needs maintainer review before merge. :: none

Reviewed October 22, 2026, 4:34 AM ET / 08:34 UTC (Revision 4).

…tion-reads

# Conflicts:
#	src/agents/agent-tools.turn-authority.ts
…fect

Drive a real failed one-shot through the scheduler's auto-disable notice
on an isolated Gateway and check, at the cron handlers, that the notice
turn reads only its own chat's automation and history, every write and
other owner-only tool stays gated, removal or run closure during an
awaited history read discloses nothing, and a non-owner agent turn that
asserts scheduler provenance gets the owner gate.
@VACInc

VACInc commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 22, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Oct 22, 2026
@VACInc
VACInc merged commit 3afef59 into openclaw:main Oct 22, 2026
155 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
…omations (openclaw#180304)

* fix(automations): let automation notice turns read caller-visible automations

* test(automations): prove notice-turn automation reads at the final effect

Drive a real failed one-shot through the scheduler's auto-disable notice
on an isolated Gateway and check, at the cron handlers, that the notice
turn reads only its own chat's automation and history, every write and
other owner-only tool stays gated, removal or run closure during an
awaited history read discloses nothing, and a non-owner agent turn that
asserts scheduler provenance gets the owner gate.

---------

Co-authored-by: VACInc <[email protected]>
obviyus added a commit that referenced this pull request Oct 30, 2026
…188105)

Related: #161007, #180304, #187346

## What Problem This Solves

Fixes: an automation's failure repair turn cannot read or change the job it was asked to repair, so it asks the user to fix it instead.

## User Impact

User impact: when an owned automation fails, the repair turn in its owner conversation can now read the job's runs and update the job when the job's requester is still an owner, so most repairs no longer need a human reply. Scheduler notices about a job follow the same rule.

Risk to note: a job whose requester is not an owner (or whose stored operator source can no longer be restored) now gets read-only automation access in its repair and notice turns, and no session-owner fallback. Jobs that record no requester keep the session owner's current access, as other system turns do since #187346.

## Why This Change Was Made

System-started turns got their authority from what kind of turn they were: a label match for notices (#180304), a caller rule for completions (#187346, which left cron out), and nothing for repairs, which went through the public `agent` RPC. Any client can send the repair's provenance label on that RPC, so it could never carry authority.

Now:
- A scheduler turn about a job acts for the job's recorded requester, the same requester and owner check its scheduled runs use (channel sender, profile, or restored operator source). Owner status is rechecked before each owner-only effect.
- Repairs run on the host session-event path, like notices and completions.
- Every host system turn gets one rule for caller-scoped automation reads; the `sourceTool === "cron"` match is gone.

## Evidence

Production repair transcripts (read-only, one Gateway, since the repair feature shipped): 57 repair turns, 3 fixed their job, 28 asked the user. No repair turn ever completed an `automations` call: before 2026-10-19 the tool was absent, then a schema check failed, and since 2026-10-22 all 18 calls were refused by the owner gate. All 3 script-payload repairs were refused.

Final-effect test `src/gateway/server-cron-failure-repair.final-effect.test.ts` runs the real repair dispatcher, real session-event admission, the turn's real tool surface and in-process Gateway dispatch into a real `CronService` and its store (model synthetic). Each case reports the tool result and the stored job afterwards:

| Job requester | `automations update` | Stored description |
|---|---|---|
| Channel owner | ok | changed |
| Channel non-owner | gated | unchanged |
| Channel owner revoked while the repair was queued | turn refused at admission, no tool ran | unchanged |
| Channel owner revoked after admission | refused: tool host retired by the config change | unchanged |
| Restored Control UI admin operator source | ok | changed |
| Restored non-admin operator source | gated | unchanged |
| Operator source with its device revoked before the repair | gated (no session fallback) | unchanged |
| Operator source device revoked while queued | turn refused at admission, no tool ran | unchanged |

Two fixes came out of this proof:
- The queued-revocation case first let the update through: the requester recheck read the config captured at capture time. It now reads the Gateway's current config, as completion turns do (`authority.isCurrent(getSessionEventRuntimeConfig())`).
- A restored operator source is an owner only when it was a Control UI administrator, matching the job's in-session runs (`session-run.ts`). The non-admin case fails without this rule.

On the base commit the file fails (the repair cannot dispatch outside the old lifecycle path); production transcripts above show the base refusal itself.

Runtime-error suppression from #162772 is kept: repair session events set a host-owned `suppressErrorDelivery`, so error payloads stay in the transcript and out of chat. The owner-topic Gateway test now has the repair return a provider-error payload and asserts no chat delivery; without the flag that test fails (`prepareSessionEventDelivery` called once).

Gateway cron suite (`server.cron.test.ts`): the owner-topic repair and NO_REPLY repair cases drive the real reply runtime; they check the owner topic's session and thread route, repair pending through retries until the turn settles (success and error), one escalation, and that a forged public `cron_failure_repair` label still gets no silence. The monotonic deadline cases in `server-cron-notifications.repair.test.ts` now run against the session-event dispatcher.

Focused runs (`pnpm test <file> --maxWorkers=1`, wall time):

| File | Tests | Time |
|---|---|---|
| `src/gateway/server-cron-failure-repair.final-effect.test.ts` (new) | 8 | 34 s |
| `src/gateway/server-cron-notifications.repair.test.ts` | 2 | 7 s |
| `src/gateway/tool-resolution.exclude.test.ts` | 37 | 9 s |
| `src/agents/agent-tools.turn-authority.test.ts` | 14 | 1 s |
| `src/gateway/server.cron.test.ts` | 15 | 30 s |
| `src/auto-reply/reply/session-event-permissions.test.ts` | 27 | 37 s |
| `src/cron/execution-context-admission.test.ts` | 26 | 6 s |

The new test file adds about 8 s of test time (eight cases, one shared fixture). `server.cron.test.ts` stays at its prior cost. `oxfmt`, type-aware `oxlint` on changed files, `pnpm tsgo:core`, the `src` test-type shards and the baseline ratchets (`check:test-mock-exports`, `check:max-lines-ratchet`, `check:assertion-safety`, `check:test-timeout-race-ratchet`) pass. Hosted CI and the ClawSweeper review are green on the merged head.

Gaps:
- Profile requesters reuse the scheduled-run owner check unchanged; channel and operator-source requesters are the tested paths.
- The managed tool host used by `openEventToolHost` does not pass `inputProvenance` into tool construction, so caller-scoped reads for non-owner turns are shown in the unit matrices, not this harness (the embedded attempt path does pass it). Follow-up.
- Live proof needs a deploy; the next real failing job on a production Gateway will show it.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…penclaw#188105)

Related: openclaw#161007, openclaw#180304, openclaw#187346

## What Problem This Solves

Fixes: an automation's failure repair turn cannot read or change the job it was asked to repair, so it asks the user to fix it instead.

## User Impact

User impact: when an owned automation fails, the repair turn in its owner conversation can now read the job's runs and update the job when the job's requester is still an owner, so most repairs no longer need a human reply. Scheduler notices about a job follow the same rule.

Risk to note: a job whose requester is not an owner (or whose stored operator source can no longer be restored) now gets read-only automation access in its repair and notice turns, and no session-owner fallback. Jobs that record no requester keep the session owner's current access, as other system turns do since openclaw#187346.

## Why This Change Was Made

System-started turns got their authority from what kind of turn they were: a label match for notices (openclaw#180304), a caller rule for completions (openclaw#187346, which left cron out), and nothing for repairs, which went through the public `agent` RPC. Any client can send the repair's provenance label on that RPC, so it could never carry authority.

Now:
- A scheduler turn about a job acts for the job's recorded requester, the same requester and owner check its scheduled runs use (channel sender, profile, or restored operator source). Owner status is rechecked before each owner-only effect.
- Repairs run on the host session-event path, like notices and completions.
- Every host system turn gets one rule for caller-scoped automation reads; the `sourceTool === "cron"` match is gone.

## Evidence

Production repair transcripts (read-only, one Gateway, since the repair feature shipped): 57 repair turns, 3 fixed their job, 28 asked the user. No repair turn ever completed an `automations` call: before 2026-10-19 the tool was absent, then a schema check failed, and since 2026-10-22 all 18 calls were refused by the owner gate. All 3 script-payload repairs were refused.

Final-effect test `src/gateway/server-cron-failure-repair.final-effect.test.ts` runs the real repair dispatcher, real session-event admission, the turn's real tool surface and in-process Gateway dispatch into a real `CronService` and its store (model synthetic). Each case reports the tool result and the stored job afterwards:

| Job requester | `automations update` | Stored description |
|---|---|---|
| Channel owner | ok | changed |
| Channel non-owner | gated | unchanged |
| Channel owner revoked while the repair was queued | turn refused at admission, no tool ran | unchanged |
| Channel owner revoked after admission | refused: tool host retired by the config change | unchanged |
| Restored Control UI admin operator source | ok | changed |
| Restored non-admin operator source | gated | unchanged |
| Operator source with its device revoked before the repair | gated (no session fallback) | unchanged |
| Operator source device revoked while queued | turn refused at admission, no tool ran | unchanged |

Two fixes came out of this proof:
- The queued-revocation case first let the update through: the requester recheck read the config captured at capture time. It now reads the Gateway's current config, as completion turns do (`authority.isCurrent(getSessionEventRuntimeConfig())`).
- A restored operator source is an owner only when it was a Control UI administrator, matching the job's in-session runs (`session-run.ts`). The non-admin case fails without this rule.

On the base commit the file fails (the repair cannot dispatch outside the old lifecycle path); production transcripts above show the base refusal itself.

Runtime-error suppression from openclaw#162772 is kept: repair session events set a host-owned `suppressErrorDelivery`, so error payloads stay in the transcript and out of chat. The owner-topic Gateway test now has the repair return a provider-error payload and asserts no chat delivery; without the flag that test fails (`prepareSessionEventDelivery` called once).

Gateway cron suite (`server.cron.test.ts`): the owner-topic repair and NO_REPLY repair cases drive the real reply runtime; they check the owner topic's session and thread route, repair pending through retries until the turn settles (success and error), one escalation, and that a forged public `cron_failure_repair` label still gets no silence. The monotonic deadline cases in `server-cron-notifications.repair.test.ts` now run against the session-event dispatcher.

Focused runs (`pnpm test <file> --maxWorkers=1`, wall time):

| File | Tests | Time |
|---|---|---|
| `src/gateway/server-cron-failure-repair.final-effect.test.ts` (new) | 8 | 34 s |
| `src/gateway/server-cron-notifications.repair.test.ts` | 2 | 7 s |
| `src/gateway/tool-resolution.exclude.test.ts` | 37 | 9 s |
| `src/agents/agent-tools.turn-authority.test.ts` | 14 | 1 s |
| `src/gateway/server.cron.test.ts` | 15 | 30 s |
| `src/auto-reply/reply/session-event-permissions.test.ts` | 27 | 37 s |
| `src/cron/execution-context-admission.test.ts` | 26 | 6 s |

The new test file adds about 8 s of test time (eight cases, one shared fixture). `server.cron.test.ts` stays at its prior cost. `oxfmt`, type-aware `oxlint` on changed files, `pnpm tsgo:core`, the `src` test-type shards and the baseline ratchets (`check:test-mock-exports`, `check:max-lines-ratchet`, `check:assertion-safety`, `check:test-timeout-race-ratchet`) pass. Hosted CI and the ClawSweeper review are green on the merged head.

Gaps:
- Profile requesters reuse the scheduled-run owner check unchanged; channel and operator-source requesters are the tested paths.
- The managed tool host used by `openEventToolHost` does not pass `inputProvenance` into tool construction, so caller-scoped reads for non-owner turns are shown in the unit matrices, not this harness (the embedded attempt path does pass it). Follow-up.
- Live proof needs a deploy; the next real failing job on a production Gateway will show it.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…penclaw#188105)

Related: openclaw#161007, openclaw#180304, openclaw#187346

Fixes: an automation's failure repair turn cannot read or change the job it was asked to repair, so it asks the user to fix it instead.

User impact: when an owned automation fails, the repair turn in its owner conversation can now read the job's runs and update the job when the job's requester is still an owner, so most repairs no longer need a human reply. Scheduler notices about a job follow the same rule.

Risk to note: a job whose requester is not an owner (or whose stored operator source can no longer be restored) now gets read-only automation access in its repair and notice turns, and no session-owner fallback. Jobs that record no requester keep the session owner's current access, as other system turns do since openclaw#187346.

System-started turns got their authority from what kind of turn they were: a label match for notices (openclaw#180304), a caller rule for completions (openclaw#187346, which left cron out), and nothing for repairs, which went through the public `agent` RPC. Any client can send the repair's provenance label on that RPC, so it could never carry authority.

Now:
- A scheduler turn about a job acts for the job's recorded requester, the same requester and owner check its scheduled runs use (channel sender, profile, or restored operator source). Owner status is rechecked before each owner-only effect.
- Repairs run on the host session-event path, like notices and completions.
- Every host system turn gets one rule for caller-scoped automation reads; the `sourceTool === "cron"` match is gone.

Production repair transcripts (read-only, one Gateway, since the repair feature shipped): 57 repair turns, 3 fixed their job, 28 asked the user. No repair turn ever completed an `automations` call: before 2026-10-19 the tool was absent, then a schema check failed, and since 2026-10-22 all 18 calls were refused by the owner gate. All 3 script-payload repairs were refused.

Final-effect test `src/gateway/server-cron-failure-repair.final-effect.test.ts` runs the real repair dispatcher, real session-event admission, the turn's real tool surface and in-process Gateway dispatch into a real `CronService` and its store (model synthetic). Each case reports the tool result and the stored job afterwards:

| Job requester | `automations update` | Stored description |
|---|---|---|
| Channel owner | ok | changed |
| Channel non-owner | gated | unchanged |
| Channel owner revoked while the repair was queued | turn refused at admission, no tool ran | unchanged |
| Channel owner revoked after admission | refused: tool host retired by the config change | unchanged |
| Restored Control UI admin operator source | ok | changed |
| Restored non-admin operator source | gated | unchanged |
| Operator source with its device revoked before the repair | gated (no session fallback) | unchanged |
| Operator source device revoked while queued | turn refused at admission, no tool ran | unchanged |

Two fixes came out of this proof:
- The queued-revocation case first let the update through: the requester recheck read the config captured at capture time. It now reads the Gateway's current config, as completion turns do (`authority.isCurrent(getSessionEventRuntimeConfig())`).
- A restored operator source is an owner only when it was a Control UI administrator, matching the job's in-session runs (`session-run.ts`). The non-admin case fails without this rule.

On the base commit the file fails (the repair cannot dispatch outside the old lifecycle path); production transcripts above show the base refusal itself.

Runtime-error suppression from openclaw#162772 is kept: repair session events set a host-owned `suppressErrorDelivery`, so error payloads stay in the transcript and out of chat. The owner-topic Gateway test now has the repair return a provider-error payload and asserts no chat delivery; without the flag that test fails (`prepareSessionEventDelivery` called once).

Gateway cron suite (`server.cron.test.ts`): the owner-topic repair and NO_REPLY repair cases drive the real reply runtime; they check the owner topic's session and thread route, repair pending through retries until the turn settles (success and error), one escalation, and that a forged public `cron_failure_repair` label still gets no silence. The monotonic deadline cases in `server-cron-notifications.repair.test.ts` now run against the session-event dispatcher.

Focused runs (`pnpm test <file> --maxWorkers=1`, wall time):

| File | Tests | Time |
|---|---|---|
| `src/gateway/server-cron-failure-repair.final-effect.test.ts` (new) | 8 | 34 s |
| `src/gateway/server-cron-notifications.repair.test.ts` | 2 | 7 s |
| `src/gateway/tool-resolution.exclude.test.ts` | 37 | 9 s |
| `src/agents/agent-tools.turn-authority.test.ts` | 14 | 1 s |
| `src/gateway/server.cron.test.ts` | 15 | 30 s |
| `src/auto-reply/reply/session-event-permissions.test.ts` | 27 | 37 s |
| `src/cron/execution-context-admission.test.ts` | 26 | 6 s |

The new test file adds about 8 s of test time (eight cases, one shared fixture). `server.cron.test.ts` stays at its prior cost. `oxfmt`, type-aware `oxlint` on changed files, `pnpm tsgo:core`, the `src` test-type shards and the baseline ratchets (`check:test-mock-exports`, `check:max-lines-ratchet`, `check:assertion-safety`, `check:test-timeout-race-ratchet`) pass. Hosted CI and the ClawSweeper review are green on the merged head.

Gaps:
- Profile requesters reuse the scheduled-run owner check unchanged; channel and operator-source requesters are the tested paths.
- The managed tool host used by `openEventToolHost` does not pass `inputProvenance` into tool construction, so caller-scoped reads for non-owner turns are shown in the unit matrices, not this harness (the embedded attempt path does pass it). Follow-up.
- Live proof needs a deploy; the next real failing job on a production Gateway will show it.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 8100c60)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 12819b3dac7eab80d73e174c19363fe1e29679e4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: XL 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