Skip to content

fix: preserve caller permissions in session continuations - #187346

Merged
steipete merged 6 commits into
mainfrom
codex/system-turn-caller-authority
Oct 29, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/system-turn-caller-authority

Conversation

@steipete

@steipete steipete commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes person-scoped session tools refusing system continuations while preserving the permissions of the caller who started the work. Replaces the reverted #187105 / #187126 approach.

User Impact

Guest-started exec completions, subagent handoffs, and Goal continuations retain the guest's current authority and policy, including AutoReview. Authority is revalidated before effects. Only host work with no originating caller uses the session principal's current authority. Cron retains its existing model. No configuration or data migration is required.

Why This Change Was Made

Continuation custody belongs to the initiating caller. Host-only metadata distinguishes known callers from unattributed work, and every principal fallback delegates to the existing principal-authority resolver. Revoked caller-bound work cannot fall back to the owner. Missing person authority is reported honestly.

Delayed node exec completion now retains the original authority, policy and delivery target from dispatch through settlement. Existing authorization matching and exec handling move into their existing owners, removing the superseded paths. Source-less node dispatch keeps its existing synchronous timing and lazy expiration behavior.

The node host's omitted-session-key target, legacy Mac run-ID matching and unbounded timeout behavior remain existing protocol contracts. A lost terminal event on a permanently connected unbounded run can retain its source until disconnect; live authority checks still apply.

Production grows by 350 lines, tests shrink by 2, and documentation grows by 7 across 30 files. No baseline, ceiling, dependency, schema, configuration or version changes. Main's inherited cron/registry/mock-ratchet repairs (#187120 and #187134) are integrated unchanged; duplicate repairs are absent from this diff.

Evidence

Exact head: b16e958184ae234caca0cdf1e38c978ab327ec92.

Clean focused proof passed: 21 files, 430 tests, zero unhandled errors. This includes the exec-event → managed tool host → unnamed sessions_spawn regression, guest identity versus an administrator owner, revocation at child-launch effect, guest AutoReview, real delayed node.invoke completion, prior CI-failing files, five heap-interrupted files, and prompt-prefix stability. All eight exact-head static checks passed: core and affected test typechecks, lint, formatting, source caps, test-line and mock-export ratchets, and diff sanity. Independent review found no actionable P0–P2 issues.

The complete requested 3,522-file local inventory finished: 3,501 files admitted and 21 live files gated out. It reported 40,363 passed, 15 failed, 80 skipped tests, plus five approximately 4 GB V8 worker heap failures. All five interrupted files subsequently passed in the clean focused proof. Untouched pinned main reproduced 14 of the 15 failed assertions and the heap-limit failure. The two HTTP entry failures and the human provenance/steering failure also reproduce on main. The macOS web-fetch case invokes unsupported GNU stat -c; repository snapshot setup rejects the volume ancestor permissions. No platform or security guard was bypassed, and no budget was raised.

The earlier broad run recorded one intermittent cron DNS-deadline timer-count failure: clean replay on that head passed 19/19, isolated main passed 19/19, and the matching main cron group passed 2,470/2,470. The original failure and replay evidence are retained; no fix or proven root cause is claimed here. The remaining 14 broad assertion failures reproduce on untouched main.

All six failed jobs in prior CI run 40791570133 were diagnosed from logs fetched once and reproduced locally on the prior head or its actual CI merge. The exec authority regression was red on the redo base; delayed-node caller custody was red before its fix. The omitted-session-key row is green-only proof. An earlier interrupted run's native configuration-unload failure did not recur in the final seven-case recovery file; no repair is claimed. Live provider flags stayed off; no live Gateway, user state, deployment or release was touched.

The architecture failure is repaired at the contract owner: NodeSystemRunEventSource now lives in the existing type-only node-invoke.types.ts leaf, so invocation types do not depend on the system-run implementation. The Madge guard reproduced one cycle before this repair and reports zero afterward; runtime cycle guard also reports zero. No exemption or baseline change.

The requested pr-simplify pass removes 25 production lines versus the pre-simplification revision: inline the now-single-caller exec-notice enqueue helper at its owner, remove the impossible missing-receipt branch and unused exports, and share suppression cleanup. Existing authority, policy, routing and receipt-settlement behavior remain covered.

Necessary delayed-node growth against the merge base:

  • Registry/contracts/dispatch: +47 lines. The existing event map retains the initiating source through completion, expiry and disconnect; matching and cleanup move out of NodeRegistry into its existing system-run owner.
  • RPC source capture: +55 lines. Bind the original current caller, target and guest policy before dispatch; a later node payload cannot supply that identity, and the source must survive ordinary RPC completion.
  • Exec notice/liveness: +20 lines. Transfer source custody to the accepted delivery receipt and release rejected, silent or inline completions. The former handler is moved, and the forwarding helper is deleted.

Node exec handoffs preserve the captured logical global session and loaded agent owner; owner-prefixed queue identities are used only for occurrence storage and cleanup. The prior inlining accidentally passed the queue key to the handoff. The two existing global-owner assertions reproduced red on dc07bd49; current main 56e3422c passes all six cases. This repair fixes the product and keeps those assertions unchanged.

The final exact-head local replay includes all three files matching src/gateway/server-node-events*.test.ts and src/gateway/*system-event*.test.ts, plus the original 19 focused files (21 unique files); all 430 tests pass. Core/affected-test typechecks, lint, format, caps/ratchets and both cycle guards also pass. Full CI remains required before coordinator merge.

@clawsweeper

clawsweeper Bot commented Oct 29, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T05:35:30.765675Z dc07bd4 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XL labels Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 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: b16e958184ae234caca0cdf1e38c978ab327ec92
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-methods/nodes.invoke-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-sharing-authorization-async.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-system-turn-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

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. clawsweeper:intake:needs-repro 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR preserves initiating callers’ permissions across session continuations and reserves session-principal authority for unattributed host work.

Example: An exec completion continues work for original-guest, who has operator.write, in an administrator-owned session.

  • Before: Person-scoped continuation tools can refuse because the continuation lacks person authority.
  • After: The continuation retains original-guest’s authority and policy, without inheriting administrator privileges.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The source change is coherent and no discrete defect was found, but the material authority change lacks final-effect proof; no persisted format or migration is introduced.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Automatic continuations can refuse person-scoped tools even though the originating work was authorized.
Reason: The maintainer-authored direction restores useful continuation behavior while preserving caller restrictions and existing cron semantics.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this maintainer-authored PR addresses a concrete continuation-authority gap; source review found no definite introduced bug.

Priority: P2
Reviewed head: dc07bd495078f392d3a09be198135a4d5663ef61

Before merge

  • Add real behavior proof - Authority-chain proof required: the event-to-managed-tool harness preserves guest identity and checks demotion inside a synthetic spawn, while delayed-node tests mock target capture and event handoff; provide sanitized output showing an allowed real effect and rejection before I/O for a revoked guest and a reassigned session principal, redacting credentials and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Resolve merge risk - Before merge, the PR author must establish final-effect isolation for guest-bound delayed continuations and for host continuations whose session principal changes after admission.

Findings

None.

Tests

  • Missing end-to-end proof: Record allowed and forbidden continuation outcomes through real final effects, including guest revocation and principal reassignment after admission.
Agent review details

How this fits together

Gateway and reply admission accept continuation events, resolve their current caller authority, and pass that authority into managed tools and delayed node-completion delivery.

flowchart TD
Caller[Initiating caller] --> Capture[Capture authority and policy]
Capture --> Continuation[Queued continuation or node completion]
Host[Unattributed host event] --> Principal[Current session principal]
Continuation --> Admission[Session admission]
Principal --> Admission
Admission --> Effect[Live authorization and final effect]
Loading

Technical review

Best possible solution:

Retain caller custody in the existing event and node owners, use the shared principal resolver only for unattributed host work, and demonstrate isolation at real effects.

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

Current-main admission lacks the new principal fallback and caller classification, and the reverted predecessor documents the same refusal; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The approach fixes the owning authority flow rather than bypassing tool checks, and the added lifetime handling is justified by delayed node completion.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Prove the authority boundary (recommended)
    The PR author should record allowed continuation effects and zero effects for revoked guests and reassigned principals through the real child-launch or transport owner.

Provenance checked

  • System continuation authority changes intended behavior with a stated reason (5be92b4: The revert restored missing-person refusals after principal fallback elevated guest work; this PR explicitly distinguishes caller-bound work from unattributed host inputs.)
  • Restart principal resolution keeps the original intent (9344233: Restart resume resolves the recorded principal’s current grants without restoring saved authority; the new shared resolver retains that model.)
  • Node event matching, routing and inline suppression keeps the original intent (8a98a26: Inline results suppress duplicate notices while failed waits retain late completion; earlier provenance matching and originating-route contracts remain in the relocated owner.)
  • Channel requester owner policy keeps the original intent (aa8b35b: Configured channel owners retain their own command-owner capability through exec completion; known callers without profile grants must not become session-principal work.)
  • Goal continuation tests keeps the original intent (0661e52: Local and worker Goal continuation require matching placement and live authority; the consolidated cases retain those distinct rejection paths.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit bf3a182 adds src/auto-reply/reply/reply-run-registry.tool-authority.ts:11 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bf3a182adb45; files: src/auto-reply/reply/reply-run-registry.tool-authority.ts)

PR surface

Source +346, Tests -2, Docs +7. Total +351 across 30 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 25 965 619 +346
Tests 4 477 479 -2
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 30 1449 1098 +351

Review metrics

Metric Value Why it matters
Production versus tests Production net +346 lines; tests net −2 lines The growth retains caller authority through delayed completion and shares principal admission; moved matching and notice handling replace their former implementations.

Root-cause cluster

Relationship: canonical
Canonical: #187346
Summary: This PR is the caller-preserving replacement for the previously merged and reverted session-principal approach.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P2: The fix restores person-scoped tools in automatic continuations, with a limited blast radius around background and host-started work.
  • add merge-risk: 🚨 security-boundary: The PR changes which human authority reaches continuation effects and introduces session-principal fallback, while supplied proof stops at mocked final boundaries.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: The fix restores person-scoped tools in automatic continuations, with a limited blast radius around background and host-started work.
  • merge-risk: 🚨 security-boundary: The PR changes which human authority reaches continuation effects and introduces session-principal fallback, while supplied proof stops at mocked final boundaries.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final-effect proof for revoked guest continuations and prove session-principal reassignment invalidates retained authority before I/O.

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 October 29, 2026, 1:50 AM ET / 05:50 UTC.

@steipete
steipete merged commit 52bc4b5 into main Oct 29, 2026
150 of 154 checks passed
@steipete
steipete deleted the codex/system-turn-caller-authority branch October 29, 2026 06:37
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
openclaw#187346)

System-started turns now continue with the current authority of whoever started the work they continue. Before, they had no person authority: person-scoped tools like sessions_spawn refused with "User is not a participant of this turn" (8 Team-server refusals since 10-02; 4 in real-model stress on main), and the agent silently stopped work as soon as it continued from an event.

- A guest's background exec, subagent or goal continues as that guest, keeping the guest's current policy (AutoReview etc.), revalidated at the point of effect.
- Only system work with no originating caller (restart resume, unattributed events) falls back to the session principal's current authority. An explicit non-human assignment never falls back to a former human creator; no-principal turns get no person authority and an honest refusal.
- Node exec completions keep the captured logical target and agent; the prefixed queue key is used only for storage and cleanup.
- Cron keeps its own authority model.

This redoes openclaw#187105, which was reverted in openclaw#187126 after it continued a guest-started background completion with owner authority (lost the guest's AutoReview).

Proof at exact head b16e958:
- The exec-completion sessions_spawn regression is red on base; guest-continuation, revocation and delayed-node custody tests pass; the node-owner regression is red on dc07bd4 and green here.
- Locally, 21 files (430 tests) and ten static checks pass, including zero-cycle guards.
- Exact-head CI: 93 jobs passed. The single failed job, checks-node-changed-compact-large-23, is sessions-create-thinking-claim.test.ts "...at the same timestamp (delivered-event)". It passed on both previous heads (dc07bd4, 425cbfb), the only change since is the unrelated 4-line node-owner fix, and it passed 6/6 locally on this head, so it is a timing intermittent.
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]>
etzelm added a commit to etzelm/openclaw that referenced this pull request Oct 31, 2026
- Conflicts from openclaw#187346, which moved the node exec.started/finished/
  denied handling out of server-node-events.ts into
  handleNodeExecEvent in server-node-events-exec-notice.ts.
- server-node-events.ts: main's version. The pathPrepend warning hook
  (withNodeExecPathPrependWarning(text, cfg, agentId)) now sits after
  the "Exec finished" text in handleNodeExecEvent (main's code kept
  as is), same cfg and agentId.
- server-node-events.session-events.test.ts: main's version plus this
  branch's run-path-* cases; the route test main removed stays removed.
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

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-sensitive-changed size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant