Skip to content

fix: background command completions lose the owner's owner-only tools - #185476

Merged
obviyus merged 11 commits into
mainfrom
fix/exec-wake-owner-authority
Oct 28, 2026
Merged

obviyus merged 11 commits into
mainfrom
fix/exec-wake-owner-authority

Conversation

@obviyus

@obviyus obviyus commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: an agent cannot use owner-only tools (such as openclaw or plugins) to finish a task after a background command it started for the owner completes; the owner has to send another message first.

User Impact

User impact: when a channel owner asks the agent to do something that runs a background command, the completion turn can finish the job with the same owner tools, without asking the owner to reply "go". Commands started by other senders keep the current restrictions.

Why This Change Was Made

Owner-only tools follow the turn's sender. A background-exec completion turn has no sender, so it was never treated as the owner, even when the owner's own turn started the command. Plugin-reload and tool handoffs already continue owner authority, but only for a Gateway-owner operatorAuthority; channel owners configured through commands.ownerAllowFrom have none, so they lost it.

The exec producer now asks the session event target to keep its requester as command owner. The target takes the requester identity from the host-owned tool caller (never from the producer), prepares it once with the existing prepareCommandOwnerAuthority, and stores it only if the requester is an owner. The completion context binds the existing command-owner capability, whose check reruns isCurrent against the current config each time. A batch refuses to merge completions from different requesters, keyed on the captured sender rather than the shared configured-owner label, so one owner's completion can't run under another owner's authority.

Main has since added ownerContinuation for operator-authority tool handoffs (publish, plugin reload). Both now sit in the same target scope: operator handoffs bind through ownerContinuation, exec completions bind through the requester's commandOwner, the context binds only one of them, and a batch refuses to mix either.

Not covered on purpose: lost-process wakes after a Gateway restart (the capability is in memory only, so they keep today's gate), and plugin/tool handoffs for channel owners (same pattern, separate change).

Evidence

  • Real Gateway, unmocked effect (new QA Lab flow exec-completion-owner-authority, pnpm openclaw qa suite --scenario exec-completion-owner-authority --provider-mode mock-openai): a real Gateway child, the QA channel plugin, real exec, and the real automations tool persisting through the Gateway's cron.add. Only the model is the scripted mock-openai. Each sender DMs the agent, which starts sleep 6; echo … in the background. The completion turn then calls the owner-only automations tool to add a disabled job, and the flow checks cron.list. Run on b2d0255, result pass:
    owner completion persists an automation   pass  job=o270eccda persisted=true
      completionToolOutput={"tool":{"id":"openclaw:core:automations",…},"result":{…"id":"8ec9e0cc-…"
    guest completion is refused               pass  job=g001c8b48 persisted=false
      completionToolOutput={"status":"error","tool":"dispatch_action","error":"Unknown tool id: automations. …"}
    
    The guest's completion turn doesn't have automations in its catalog at all, so the call fails before any Gateway request and nothing is persisted.
  • Revocation: owner status is rechecked against the Gateway's applied config when the completion is captured, when it's admitted, and at the effect (unit cases revoked-before-admission and revoked-after-admission below). On a real Gateway, a change to commands.ownerAllowFrom takes effect when the Gateway applies it, and that waits for active work the same way it already does for owner message turns. This PR doesn't change that reload policy.
  • Requester identity for owner-checked effects: the completion now carries the captured requester's SenderId/SenderE164, but only when the completion goes back to that requester's own channel and account (a raw ID on another channel never becomes a sender). Before this, owner-only tools were enabled but the real Gateway restart handler refused the owner as having "no current owner principal" (ClawSweeper finding on 1eb0b80).
  • End-to-end through real completion admission (session-event-permissions): an exec completion is captured under the host-owned caller with a Telegram requester, enqueued as source: "exec", admitted by the ordinary reply path, and the synthetic model turn calls gateway restart through the turn's assembled tool surface. The call reaches the real gateway.restart.request handler, which rechecks the requester against current config; only the in-process transport and the final restart scheduler are stubbed.
    • owner (456 in commands.ownerAllowFrom): the handler receives requester telegram/456, passes its owner check, and schedules exactly one restart.
    • guest (789): the tool is gated ({ gated: true }); no Gateway request.
    • owner revoked before admission: gated; no Gateway request.
    • owner revoked after admission: publishing the config change retires the admitted turn's tool host, so the call fails ("agent harness host capability is no longer active") before reaching the Gateway; nothing is scheduled.
    • Without the requester projection, the owner case fails with exactly the handler's "Gateway maintenance requires a current owner principal".
  • Exec-notify: gives the completion turn the current owner authority of its owner requester fails on main and passes here; removing the owner from config revokes the bound capability.
  • Handoff batching: the same owner's completions batch; a guest's or a different configured owner's do not (owners share the configured-owner source label, so batching keys on the captured requester).
  • Passing locally on b2d0255: session-event-permissions (28), session-event-config-readmission, session-event-handoff, session-event-context and bash-tools.exec-notify (98 total), and the QA flow above. pnpm check:changed: format, typecheck, ratchets (including test-lines) and guards pass. Its whole-extension lint lane reports only existing findings in files this PR doesn't touch (workboard, x, memory-core, copilot, knowledge and tlon fixtures); the two new qa-lab files lint clean. Independent autoreview (P1 threshold) on the branch: clean.
  • Test setup: the three copies of event-turn tool-host setup in session-event-permissions / session-event-config-readmission are now one openEventToolHost test-support helper, which offsets most of the new test lines. The test-lines ratchet passes against current main without a baseline change.
  • Independent autoreview (P1 threshold) found that batching keyed on the shared source label could let a revoked owner's completion run under another owner's authority. That's fixed in c6a4c083 and covered above, and the re-review was clean.
  • Inherited CI failure: checks-node-changed-1 fails extensions/qa-lab/src/gateway-kill-restart-send.e2e.test.ts > recovers a killed run and replies (the post-restart reply has replyToId: undefined). The lane picked the test up because this PR touches qa-lab. It reproduces identically on main at dafda2f without this PR, and no later main commit touches that test or the restart-recovery reply path. Related: [Bug]: Restart recovery after SIGKILL aborts and tombstones the orphaned session (gateway-kill-restart-send e2e fails on main) #167602.
  • Gap: no live Telegram/Discord run. The real-Gateway proof uses the QA channel plugin through the same channel plugin boundary.

Size against main: production +100/−0, tests +231/−105 (including shared event test support), docs +1.

@clawsweeper

clawsweeper Bot commented Oct 27, 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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: S labels Oct 27, 2026
@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 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Background command completions retain their original requester's owner-only tools while that requester remains authorized.

Example: Telegram owner 456 starts a background command, then its completion needs to restart the Gateway.

  • Before: The completion lacks owner authority and requires another owner message.
  • After: The completion can request the restart; guests and revoked owners remain blocked.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused repair with real-Gateway effect evidence and distinct authority controls; broad CI failure attribution remains unsettled.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied exact-head QA CLI output exercises a real Gateway, channel ingress, background exec completion, and automation persistence for an owner and guest; production-path permission cases additionally cover revocation before and after admission and the real restart handler.
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 owner's background command finishes, but the agent loses the owner-only tools needed to complete the task.
Reason: Restores continuity for the initiating owner's task using existing authorization contracts; the collaborator-authored direction is already authorized.

Merge readiness

✅ Ready for maintainer review

This PR fixes a remaining channel-owner continuation bug on current main; no introduced correctness or security defect was found.

Priority: P2
Reviewed head: b2d02551fb617cd76af1676f3815f278826a6b12

Before merge

None.

Findings

None.

Agent review details

How this fits together

The exec notification producer captures the initiating requester, session-event admission builds the continuation, and existing tool and Gateway owners enforce current authority before effects.

flowchart LR
  A[Owner or guest request] --> B[Background exec]
  B --> C[Captured event target]
  C --> D[Session event admission]
  D --> E[Live command owner check]
  E --> F[Tool execution]
  F --> G[Gateway effect]
Loading

Technical review

Best possible solution:

Retain this focused repair through the existing event-target, command-owner, and execution-admission owners.

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

Current-main source shows the missing channel-owner capability, and the supplied proof demonstrates the repaired completion path; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch repairs requester authority at the existing producer and context boundaries, preserves live revocation checks, and prevents different requesters from sharing a batch.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Exec requester authority keeps the original intent (147df8d: Preserve the original guest's supported operator capabilities and restrictions after background execution.)
  • Operator-backed owner continuation keeps the original intent (5fddba9: Continue the yielding owner's own decision through publish and reload handoffs under a live captured operator source.)
  • Shared event-tool test setup keeps the original intent (e8b2511: Consolidate repeated managed-tool fixture construction without changing production authorization or distinct test contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 753a7a5 adds src/auto-reply/reply/session-event-target.ts:203 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 753a7a57be10; files: src/auto-reply/reply/session-event-target.ts)
  • Shakker: Raw commit 147df8d adds src/agents/bash-tools.exec-notify.ts:332 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 147df8d9edf5; files: src/agents/bash-tools.exec-notify.ts)

PR surface

Source +167, Tests +126, Docs +1, Other +181. Total +475 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 168 1 +167
Tests 5 231 105 +126
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 181 0 +181
Total 12 581 106 +475

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A background completion cannot finish an owner's task with owner-only tools until the owner sends another message.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 (5 earlier review cycles)
  • reviewed 2026-10-27T05:18:34.250Z sha 7be51b0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-28T01:38:03.567Z sha c6a4c08 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-28T01:57:15.698Z sha 1eb0b80 :: needs real behavior proof before merge. :: [P2] Carry the captured requester identity into owner-checked actions
  • reviewed 2026-10-28T02:42:46.886Z sha 6178ed0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-28T03:26:23.514Z sha b2d0255 :: needs maintainer review before merge. :: none

Reviewed October 27, 2026, 11:33 PM ET / October 28, 2026, 03:33 UTC (Revision 6).

roboclaw-bot and others added 3 commits October 28, 2026 01:18
Keep main's operator ownerContinuation for publish and plugin-reload handoffs
alongside the channel requester's commandOwner for exec completions. The
context binds one of them, and batches refuse to mix either.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: obviyus <[email protected]>
Configured owners share the "configured-owner" source label while each
authority rechecks only its own sender, so batching keyed on the label could
run a revoked owner's completion under another owner's authority. Key the
retained authority on the captured requester instead.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: obviyus <[email protected]>
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 28, 2026 01:33
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 28, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 28, 2026
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: landing past one unrelated red check.

  • Failing job: checks-node-changed-1 (run 40626240837). The only failure is extensions/qa-lab/src/gateway-kill-restart-send.e2e.test.ts > recovers a killed run and replies (AssertionError: expected { …(14) } to match object { …(2) }).
  • openclaw/ci-gate is red only because it reports that job.
  • The same test fails locally without this PR, on main at dafda2f722f1 (the commit this branch merged) and on current main at 7df9d7971664. This PR does not change that test or the kill/restart path.
  • ClawSweeper review is ready for head b2d02551fb61, and every other required check passed.

@obviyus
obviyus merged commit aa8b35b into main Oct 28, 2026
170 of 173 checks passed
@obviyus
obviyus deleted the fix/exec-wake-owner-authority branch October 28, 2026 04:33
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as aa8b35b.

  • Bug: a background command's completion turn has no sender. So a channel owner (set through commands.ownerAllowFrom) lost owner-only tools when their own command finished.
  • Fix: the completion carries the requesting owner as commandOwner through admission and owner-checked effects. A batch never mixes completions from different owners. Operator handoffs still use ownerContinuation.
  • Proof: focused completion and handoff tests, plus the qa-lab Gateway scenario exec-completion-owner-authority, which runs an owner-only call from a real exec completion. The one red CI test, gateway-kill-restart-send.e2e, also fails on main without this PR; see the Maintainer override above.

Thanks @jalehman for the co-authored work.

obviyus added a commit that referenced this pull request Oct 28, 2026
…er the owner is removed (#185796)

Related: #185597, #185476

## What Problem This Solves

Fixes: a subagent spawned by a channel owner (for example a Telegram owner in `commands.ownerAllowFrom`) keeps running on its native runtime, such as Muse, after that person stops being an owner.

## User Impact

An owner's subagent keeps remembered native runtime consent (`nativeRuntimeConsent`) only while the spawner is still an owner. When an operator removes the owner, the child stops before its next native dispatch. Children spawned by non-owners still get refused, and owner-spawned children still dispatch.

## Why This Change Was Made

#185597 made remembered consent cover an owner's own turns. A child run already gets its owner fact from the spawner's live requester check (`prepareCommandOwnerAuthority`), not from the stored `spawnedBySenderIsOwner` receipt. But that check ran only while the Gateway admitted the child. After that, nothing checked it again, so removing the owner did not stop the child.

This change adds the same check to the child run's source assertion. A channel owner's own turn already uses this pattern (`captureCommandOwnerAssertion` in the run's `assertSourceCurrent`). The harness host checks that assertion just before native dispatch. If the check fails, it stays failed for the rest of the run.

## Evidence

Regression test (in-process): production-boundary test `fences remembered native consent for a child spawned by a channel %s`. It runs the real `sessions_spawn` tool, then the in-process Gateway `agent` admission, then the child's run parameters. The parent turn is a Telegram sender. The agent config has `nativeRuntimeConsent: ["native-fixture"]` and the child session modes are unset. The model-facing `senderIsOwner` receipt is `true` in both rows.

- Owner (`telegram:456`): the child gets `senderIsOwner: true` and `assertAgentHarnessExecutionEnvironment` returns consent. When the owner is removed after admission, the captured admitted-run assertion (the one the harness host checks before `runAttempt`) throws.
- Guest (`telegram:789`): the child gets `senderIsOwner: false` and consent is refused, even with an owner receipt.
- Negative control: without the production change, the owner row fails because nothing stops the child after revocation.

Also ran:
- The full spawn production-boundary file (106 tests), `agent.test.ts` and `agent.followup-owner.test.ts` (414 tests), and `execution-environment.test.ts`: all pass.
- `pnpm tsgo:core`, `pnpm tsgo:core:test`, oxlint and `git diff --check`: clean.


### Live proof: Telegram Test Server + real Muse

Isolated Gateway with a leased Telegram Test Server bot and user. The parent agent is a deterministic mock model that issues a real `sessions_spawn`. Children run on the real Muse runtime (`meta/muse-spark-1.3`, Muse Code 1.4.11). Config: `nativeRuntimeConsent: ["muse"]`, `agents.defaults.subagents.model: meta/muse-spark-1.3`, `subagents.maxConcurrent: 1`. The tester is made an owner through `commands.ownerAllowFrom`, then removed by editing the config file while child A runs on Muse.

A Gateway detail controls the timing: it defers an owner-removal config reload until active runs end, or until its 300 s timeout. Child A runs a 330 s shell `sleep` on Muse, so the removal takes effect while A is still running.

| Step | `main` (`32f9477bf4`) | This PR |
| --- | --- | --- |
| Owner's child A dispatches to Muse | Yes: Muse replies (`muse-spark-1.3`) | Yes: Muse replies (`muse-spark-1.3`) |
| Owner removed; reload applies after 300 s timeout | Applied | Applied |
| Child A's next native dispatch | **Continues**: `FIRST_CHILD_DONE` is delivered to Telegram | **Stopped**: "Requester owner authority changed; send a new request." |
| Queued child B (admitted before removal) | Refused, no Muse turn | Refused, no Muse turn |
| Guest's child (tester not an owner) | — | Refused before Muse I/O: "Muse Code cannot enforce this conversation's tool policy." No Muse assistant turn. |

So the discriminating case is a child that is already running when the removal applies. A queued child was already refused on `main`.

## Merge danger

Two-way door. The change writes no state and does not change config or protocol, so a revert undoes it fully. Blast radius: only child runs whose owner fact comes from a channel requester (`requesterOwner`). If the owner is removed while such a child runs, the child now stops instead of finishing. Operator, admin-scope and non-owner children do not change. Restart replay of a final reply keeps its current behavior.

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

## What Problem This Solves

Fixes: an agent cannot use owner-only tools (such as `openclaw` or `plugins`) to finish a task after a background command it started for the owner completes; the owner has to send another message first.

## User Impact

User impact: when a channel owner asks the agent to do something that runs a background command, the completion turn can finish the job with the same owner tools, without asking the owner to reply "go". Commands started by other senders keep the current restrictions.

## Why This Change Was Made

Owner-only tools follow the turn's sender. A background-exec completion turn has no sender, so it was never treated as the owner, even when the owner's own turn started the command. Plugin-reload and tool handoffs already continue owner authority, but only for a Gateway-owner `operatorAuthority`; channel owners configured through `commands.ownerAllowFrom` have none, so they lost it.

The exec producer now asks the session event target to keep its requester as command owner. The target takes the requester identity from the host-owned tool caller (never from the producer), prepares it once with the existing `prepareCommandOwnerAuthority`, and stores it only if the requester is an owner. The completion context binds the existing command-owner capability, whose check reruns `isCurrent` against the current config each time. A batch refuses to merge completions from different requesters, keyed on the captured sender rather than the shared `configured-owner` label, so one owner's completion can't run under another owner's authority.

Main has since added `ownerContinuation` for operator-authority tool handoffs (publish, plugin reload). Both now sit in the same target scope: operator handoffs bind through `ownerContinuation`, exec completions bind through the requester's `commandOwner`, the context binds only one of them, and a batch refuses to mix either.

Not covered on purpose: lost-process wakes after a Gateway restart (the capability is in memory only, so they keep today's gate), and plugin/tool handoffs for channel owners (same pattern, separate change).

## Evidence

- **Real Gateway, unmocked effect** (new QA Lab flow `exec-completion-owner-authority`, `pnpm openclaw qa suite --scenario exec-completion-owner-authority --provider-mode mock-openai`): a real Gateway child, the QA channel plugin, real `exec`, and the real `automations` tool persisting through the Gateway's `cron.add`. Only the model is the scripted `mock-openai`. Each sender DMs the agent, which starts `sleep 6; echo …` in the background. The completion turn then calls the owner-only `automations` tool to add a disabled job, and the flow checks `cron.list`. Run on `b2d0255`, result `pass`:
  ```
  owner completion persists an automation   pass  job=o270eccda persisted=true
    completionToolOutput={"tool":{"id":"openclaw:core:automations",…},"result":{…"id":"8ec9e0cc-…"
  guest completion is refused               pass  job=g001c8b48 persisted=false
    completionToolOutput={"status":"error","tool":"dispatch_action","error":"Unknown tool id: automations. …"}
  ```
  The guest's completion turn doesn't have `automations` in its catalog at all, so the call fails before any Gateway request and nothing is persisted.
- Revocation: owner status is rechecked against the Gateway's applied config when the completion is captured, when it's admitted, and at the effect (unit cases `revoked-before-admission` and `revoked-after-admission` below). On a real Gateway, a change to `commands.ownerAllowFrom` takes effect when the Gateway applies it, and that waits for active work the same way it already does for owner message turns. This PR doesn't change that reload policy.
- Requester identity for owner-checked effects: the completion now carries the captured requester's `SenderId`/`SenderE164`, but only when the completion goes back to that requester's own channel and account (a raw ID on another channel never becomes a sender). Before this, owner-only tools were enabled but the real Gateway restart handler refused the owner as having "no current owner principal" (ClawSweeper finding on `1eb0b80`).
- End-to-end through real completion admission (`session-event-permissions`): an exec completion is captured under the host-owned caller with a Telegram requester, enqueued as `source: "exec"`, admitted by the ordinary reply path, and the synthetic model turn calls `gateway` `restart` through the turn's assembled tool surface. The call reaches the **real** `gateway.restart.request` handler, which rechecks the requester against current config; only the in-process transport and the final restart scheduler are stubbed.
  - owner (`456` in `commands.ownerAllowFrom`): the handler receives requester `telegram/456`, passes its owner check, and schedules exactly one restart.
  - guest (`789`): the tool is gated (`{ gated: true }`); no Gateway request.
  - owner revoked before admission: gated; no Gateway request.
  - owner revoked after admission: publishing the config change retires the admitted turn's tool host, so the call fails ("agent harness host capability is no longer active") before reaching the Gateway; nothing is scheduled.
  - Without the requester projection, the owner case fails with exactly the handler's "Gateway maintenance requires a current owner principal".
- Exec-notify: `gives the completion turn the current owner authority of its owner requester` fails on `main` and passes here; removing the owner from config revokes the bound capability.
- Handoff batching: the same owner's completions batch; a guest's or a different configured owner's do not (owners share the `configured-owner` source label, so batching keys on the captured requester).
- Passing locally on `b2d0255`: `session-event-permissions` (28), `session-event-config-readmission`, `session-event-handoff`, `session-event-context` and `bash-tools.exec-notify` (98 total), and the QA flow above. `pnpm check:changed`: format, typecheck, ratchets (including test-lines) and guards pass. Its whole-extension lint lane reports only existing findings in files this PR doesn't touch (workboard, x, memory-core, copilot, knowledge and tlon fixtures); the two new qa-lab files lint clean. Independent autoreview (P1 threshold) on the branch: clean.
- Test setup: the three copies of event-turn tool-host setup in `session-event-permissions` / `session-event-config-readmission` are now one `openEventToolHost` test-support helper, which offsets most of the new test lines. The test-lines ratchet passes against current `main` without a baseline change.
- Independent autoreview (P1 threshold) found that batching keyed on the shared source label could let a revoked owner's completion run under another owner's authority. That's fixed in `c6a4c083` and covered above, and the re-review was clean.
- Inherited CI failure: `checks-node-changed-1` fails `extensions/qa-lab/src/gateway-kill-restart-send.e2e.test.ts > recovers a killed run and replies` (the post-restart reply has `replyToId: undefined`). The lane picked the test up because this PR touches qa-lab. It reproduces identically on `main` at `8f5cb65` without this PR, and no later `main` commit touches that test or the restart-recovery reply path. Related: openclaw#167602.
- Gap: no live Telegram/Discord run. The real-Gateway proof uses the QA channel plugin through the same channel plugin boundary.

Size against `main`: production +100/−0, tests +231/−105 (including shared event test support), docs +1.

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: jalehman <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…er the owner is removed (openclaw#185796)

Related: openclaw#185597, openclaw#185476

## What Problem This Solves

Fixes: a subagent spawned by a channel owner (for example a Telegram owner in `commands.ownerAllowFrom`) keeps running on its native runtime, such as Muse, after that person stops being an owner.

## User Impact

An owner's subagent keeps remembered native runtime consent (`nativeRuntimeConsent`) only while the spawner is still an owner. When an operator removes the owner, the child stops before its next native dispatch. Children spawned by non-owners still get refused, and owner-spawned children still dispatch.

## Why This Change Was Made

openclaw#185597 made remembered consent cover an owner's own turns. A child run already gets its owner fact from the spawner's live requester check (`prepareCommandOwnerAuthority`), not from the stored `spawnedBySenderIsOwner` receipt. But that check ran only while the Gateway admitted the child. After that, nothing checked it again, so removing the owner did not stop the child.

This change adds the same check to the child run's source assertion. A channel owner's own turn already uses this pattern (`captureCommandOwnerAssertion` in the run's `assertSourceCurrent`). The harness host checks that assertion just before native dispatch. If the check fails, it stays failed for the rest of the run.

## Evidence

Regression test (in-process): production-boundary test `fences remembered native consent for a child spawned by a channel %s`. It runs the real `sessions_spawn` tool, then the in-process Gateway `agent` admission, then the child's run parameters. The parent turn is a Telegram sender. The agent config has `nativeRuntimeConsent: ["native-fixture"]` and the child session modes are unset. The model-facing `senderIsOwner` receipt is `true` in both rows.

- Owner (`telegram:456`): the child gets `senderIsOwner: true` and `assertAgentHarnessExecutionEnvironment` returns consent. When the owner is removed after admission, the captured admitted-run assertion (the one the harness host checks before `runAttempt`) throws.
- Guest (`telegram:789`): the child gets `senderIsOwner: false` and consent is refused, even with an owner receipt.
- Negative control: without the production change, the owner row fails because nothing stops the child after revocation.

Also ran:
- The full spawn production-boundary file (106 tests), `agent.test.ts` and `agent.followup-owner.test.ts` (414 tests), and `execution-environment.test.ts`: all pass.
- `pnpm tsgo:core`, `pnpm tsgo:core:test`, oxlint and `git diff --check`: clean.


### Live proof: Telegram Test Server + real Muse

Isolated Gateway with a leased Telegram Test Server bot and user. The parent agent is a deterministic mock model that issues a real `sessions_spawn`. Children run on the real Muse runtime (`meta/muse-spark-1.3`, Muse Code 1.4.11). Config: `nativeRuntimeConsent: ["muse"]`, `agents.defaults.subagents.model: meta/muse-spark-1.3`, `subagents.maxConcurrent: 1`. The tester is made an owner through `commands.ownerAllowFrom`, then removed by editing the config file while child A runs on Muse.

A Gateway detail controls the timing: it defers an owner-removal config reload until active runs end, or until its 300 s timeout. Child A runs a 330 s shell `sleep` on Muse, so the removal takes effect while A is still running.

| Step | `main` (`b5c6e98ca9`) | This PR |
| --- | --- | --- |
| Owner's child A dispatches to Muse | Yes: Muse replies (`muse-spark-1.3`) | Yes: Muse replies (`muse-spark-1.3`) |
| Owner removed; reload applies after 300 s timeout | Applied | Applied |
| Child A's next native dispatch | **Continues**: `FIRST_CHILD_DONE` is delivered to Telegram | **Stopped**: "Requester owner authority changed; send a new request." |
| Queued child B (admitted before removal) | Refused, no Muse turn | Refused, no Muse turn |
| Guest's child (tester not an owner) | — | Refused before Muse I/O: "Muse Code cannot enforce this conversation's tool policy." No Muse assistant turn. |

So the discriminating case is a child that is already running when the removal applies. A queued child was already refused on `main`.

## Merge danger

Two-way door. The change writes no state and does not change config or protocol, so a revert undoes it fully. Blast radius: only child runs whose owner fact comes from a channel requester (`requesterOwner`). If the owner is removed while such a child runs, the child now stops instead of finishing. Operator, admin-scope and non-owner children do not change. Restart replay of a final reply keeps its current behavior.

Co-authored-by: Ayaan Zaidi <[email protected]>
amittell added a commit to amittell/openclaw that referenced this pull request Nov 7, 2026
…urns

A completion turn restored only the requester's sender id. Without the
conversation id, requester policy skips the channel's direct-message policy,
so a requester allowed by an unchanged toolsBySender entry kept exec after
their DM revoked it (channels.telegram.direct[<chat>].tools.deny).

Retain the requester's chat type and conversation id with their identity,
and restore ChatId with the sender. Restore them only on a turn of the
requester's own conversation type: a turn routed to another chat is not a
direct turn and would skip the DM policy again, so it stays senderless and
gets the unknown-sender policy. Command-owner completions use the same
restore, since openclaw#185476 projected the sender with the same gap.
amittell added a commit to amittell/openclaw that referenced this pull request Nov 11, 2026
A branch-native equivalent of upstream openclaw#190472 (head ee3411e,
"exec completions keep the requester's current sender and DM tool
policy", issue openclaw#177510). Upstream's fix builds on openclaw#157806
(fd2a6ca, requester identity on the tool caller) and openclaw#185476
(aa8b35b, completion requester retention); neither is on this
branch. Drop this commit when a release that carries upstream's fix is
carried.

The defect here: a background exec's completion turn is built with no
sender (session-event-context.ts), and ordinary turns apply sender policy
(conversation-capability-profile.ts, senderPolicyMode "always"), so the
toolsBySender "*" entry applies and a sender allowed exec only by their
own entry loses it on the completion turn. Reproduced before the fix
(see proof); with "*" not denying exec the same test runs exec, so the
refusal is that sender policy.

What it captures, and where:
- At exec construction, from the host-owned run context and never from
  tool arguments: createOpenClawCodingTools passes
  resolveExecCompletionRequester(options) (new
  src/agents/exec-completion-requester.ts) into the exec defaults: the
  turn's sender id, E164, name, username, chat type, group space and
  group channel. A senderless turn captures nothing.
- runExecProcess keeps it on the process session as a start-time notify
  fact, cleared at settlement with the others. prepareExecExitNotification
  passes it, with that exec's own notify route, to
  captureSessionEventTargetForHost, which keeps a frozen copy with the
  target.
- buildSessionEventContext restores SenderId, SenderE164, SenderName,
  SenderUsername, GroupSpace and GroupChannel only when the completion's
  route exactly matches the captured route and the turn has the
  requester's chat type (set only on the session's own conversation).
  Anywhere else the turn stays senderless and gets the "*" policy.
- It never widens. The completion still runs inside the starting turn's
  captured tool surface (toolsAllow), which already carries that DM's own
  policy; the restored sender's current toolsBySender entry and group
  policy can only narrow it. Event turns never derive owner authority
  from identity (command-auth.ts), so completion turns stay non-owner.
  combineSessionEventTargetsForHost refuses to batch targets whose
  requesters differ.

Differences from upstream:
- Owner tools: upstream, with openclaw#185476, lets an owner's completion keep
  owner-only tools while they remain an owner. Here a completion turn is
  never an owner turn (as before this commit).
- DM policy: upstream re-resolves the DM's current policy; here the DM
  restriction is the one in force at launch (through the captured tool
  surface), so a DM deny added mid-run is not applied. Upstream notes a
  live Gateway defers channels.telegram.direct changes until background
  execs finish. Sender and group policy are current.
- Only Gateway/sandbox exec through runExecProcess; node system.run
  completions are not covered. No QA Lab scenario (upstream's needs
  main's mock-openai owner-completion fixtures).

Line cap: bash-tools.exec-runtime.ts is over its cap, so applyShellPath
moves unchanged to bash-tools.exec-path-prepend.ts, next to the other
exec PATH helpers.

Proof (M4, Node 26.12.1):
- New session-event-exec-requester.test.ts (8 rows). Only the model is
  synthetic: real exec, completion admission, tool host and policy, and
  the real Discord plugin's guild policy (without its gateway-started
  binding adapter). Three rows launch a real background exec through
  createOpenClawCodingTools; the rest capture as exec now does. 8/8 pass:
  the requester's own DM runs exec and keeps the DM's read deny; a
  command-owner requester runs exec and stays non-owner; a command
  started in another chat, a different sender, no captured sender, the
  requester's entry revoked before completion and a guild deny added
  before completion all leave exec absent; the Discord guild channel
  runs exec. session-event-handoff.test.ts adds the batch refusal.
- Reproduction before the fix: the requester's DM row fails with exec
  not offered; with "*" not denying exec it passes.
- Red-before (production files reverted, tests kept): 4 fail, the three
  rows that run exec and the batch refusal; the five denial rows pass.
- Mutation: with the owner guard removed the owner row fails
  (owner true); with GroupSpace/GroupChannel not restored the guild-deny
  row fails (exec runs).
- Every test file importing a touched module (172 files): 2590 passed,
  8 skipped, 0 failed.
- check-line-cap-ratchet and check-test-mock-exports (base v2026.11.2),
  run-oxlint on the 16 touched .ts files, tsgo:core, tsgo:test:src,
  oxfmt --check and format:docs:check: exit 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: qa-lab 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. size: L 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.

2 participants