Skip to content

refactor(agents): drop channel operator re-check and reword run-end refusals - #204048

Merged
obviyus merged 2 commits into
mainfrom
refactor/agents-refusals-part3
Nov 23, 2026
Merged

obviyus merged 2 commits into
mainfrom
refactor/agents-refusals-part3

Conversation

@obviyus

@obviyus obviyus commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Authority is checked once, when work starts. A started run may finish; Stop cancels; data fences stay. After parts 1 and 2 (#203999, #204031), some checks in src/agents, src/channels/inbound-event and the bundled Discord and Telegram native commands still re-read permissions mid-run, or refuse a data/lifecycle condition with text that claims "authority changed / is no longer active".

This is part 3 of the agents/sessions/auto-reply refusal sweep.

Fix

Test for each site: can it fire when only a permission, approval or config changes while nothing about the run or data changes? Yes → authority re-check, deleted. No → Stop, run close or data fence, kept and reworded.

Site Kind Action
channels/inbound-event/host-context-builder.ts channel operator assertCurrent ("Channel operator authority changed; send a new request.") authority (called only once, inside captureChannelOperatorRunAuthority, right after the same isCurrent check) deleted. The operator decision is taken once when the message is admitted (the existing isCurrent gate). The admitted authority's own assertCurrent was already Stop-only (signal?.throwIfAborted()), so queued channel messages do not re-read the enqueue-time operator; they start through the normal queued-start admission (#203468/#203521), unchanged
gateway/operator-run-authority.ts captureChannelOperatorRunAuthority assertCurrent input plumbing for the above (only called once, at capture) deleted. Its other caller, gateway/session-activity-summary-authority.ts, now runs its own one-time check directly before the capture (same check, same moment)
auto-reply/command-owner-authority.ts CommandOwnerRevokedError and the instanceof branch in agents/command/delivery-authority.ts dead after the delete (no thrower left) deleted
agents/harness/node-execution-authority.ts live permissionMode === "full" re-read (retainedFullPermission, fullPermissionAllowed) authority (session permission mode) deleted; Full stays the attempt's admitted mode (attempt.permissionMode, admittedFull)
same file, "admitted node execution authority is no longer current" (signal, plugin registry/lifecycle, Gateway context, plugin id, session occurrence, workspace) Stop / run close / data fence kept, reworded: "The run or its session ended. Start a new turn to retry."
agents/harness/tool-authority.runtime.ts operatorAuthority?.assertCurrent() in assertReplyActive authority (Stop is already covered by assertAdmitted, which reads the run's abort signal) deleted
same file, "embedded tool authority is no longer active" ×2 (lease closed, run instance/run id changed) run close / occurrence kept, reworded: "The agent run ended. Start a new turn to retry."
same file, "reply authority is no longer active", "embedded reply authority is no longer active" (operation route/fingerprint or attachment changed) data fence kept, reworded (existing text): "The reply target changed. Start a new turn to retry."
same file, "Embedded attempt authority changed during steering" data fence kept, reworded (existing text): "Steering target changed"
agents/tools/gateway-caller-context.ts "agent tool caller authority is no longer active" (no active admitted run lease) run close kept, reworded: "The agent run ended. Start a new turn to retry."
agents/tools/presence-tool-authority.ts hasCurrentClientAuthority() === false ("Gateway caller authority is no longer active.") authority (client re-auth) deleted; request Stop (scope.signal) kept
agents/tools/sessions-operator-authority.ts hasCurrentClientAuthority() === false ("Session control caller authority is no longer active.") authority (client re-auth) deleted
agents/subagents/announce/subagent-announce.requester-settle-receipt.ts "Requester settle authority changed during watch admission" (requester entry gone or store source changed) data fence kept, reworded: "Requester session ended during watch admission"
agents/subagents/requester-cron-authority.ts "Requester session authority changed before yield handoff" (session id, archive, lifecycle revision) data fence kept, reworded: "Requester session was reset or archived; yield handoff stopped"
same file, "Requester followup authority is no longer current", "Requester authority is no longer current" (isCurrent: active flag, lifecycle generation, binding, session revision; the channel-owner part is ingress lifetime only since #204031) lifecycle / data fence kept, reworded: "Requester followup ended", "Requester continuation ended"
agents/worktrees/registry-run-end.worker.ts "Managed worktree binding authority changed.", run-end-lifecycle.ts "Managed worktree registry authority changed; …" (registry row revision/owner fences) data fence kept, reworded: "Managed worktree binding changed.", "Managed worktree registry changed; prepare the operation again"
extensions/discord/src/monitor/native-command-auth.ts deprecated CommandAuthorization.assertOwnerCurrent read, assertActive ("Discord command authority changed; send a new request."), assertOwnerCurrent ("Discord owner authority changed; send a new request.") authority (config/owner re-read after admission) deleted. Access is read once at admission (resolveDiscordNativeCommandAccess returns allowed and senderIsOwner); the second isAllowed() after ACP binding readiness and the assertAuthority/assertActive/assertOwnerCurrent plumbing are gone
extensions/telegram/src/{ingress,bot-native-command-dispatch,bot-native-command-plugins}.ts deprecated assertOwnerCurrent reads dead (undefined since #204031) deleted

Left unchanged:

  • bash-tools.exec-host-shared.ts matcher (R6d).
  • agents/worktrees/errors.ts "GitHub publication worktree authority changed" (a registry data fence). Cut less: its only test expectation lives in gateway/github-publication.test.ts, which carries a synthetic credential-URL fixture that the local review's input scanner refuses; the reword goes with the next gateway sweep.
  • operatorAuthority.assertCurrent callers in src/auto-reply/** (~42 files) and src/agents/** (~70 files). Split per the ~25-file rule: this PR is 20 production files; the callers go to part 4.
  • extensions/discord/.../message-handler.draft-preview.ts and extensions/telegram/src/telegram-ingress-non-retryable.ts strings (R6d area).

Production: 20 files, +95/−198. The lifetime-check ratchet counts fall in every touched file; config/session-identity-allowlist.txt is pruned for the reworded "no longer active" strings.

User impact

  • A linked channel user whose operator role or link changes after their message was admitted sees the run finish. The next message is admitted again.
  • A Discord native command whose sender loses command or owner access while it runs now finishes, as admission decided.
  • A session in Full permission mode whose mode is lowered during a run keeps node execution for that run; the next run uses the new mode.
  • Refusals that remain now name what ended and the next step instead of claiming an authority change.
  • No new refusal, prompt or wait. Stop still cancels.

Tests

Deleted (they assert a mid-run permission refusal):

  • discord native-command.interaction-boundary.test.ts revoked-command and revoked-channel rows (config/policy changed during the command).
  • sessions-control-authority.test.ts "keeps the live client check when the ambient authority is passed back as prepared" (client deauth mid-run).
  • gateway.sessions-send-provenance.authority.test-support.ts unlink and reassign phases (linked principal unlinked during final send). The current phase stays: a linked principal's message delivers.
  • host-capability.node-authority.test.ts and agent-runner-node-authority.test.ts permission rows (session lowered from Full to workspace during the run).
  • commands-plugin.channel-native.test.ts fixture cleanup for children that failed with the removed "Channel operator authority changed" text.

Text-only updates (same condition): tool-authority.runtime.participants, .admission, .retention support, sessions-send-followup-revalidation, worker-session-tool-executor, server.requester-pause-authority, local-request-context.session-tools, node-authority run-end text.

Capture-time input removed: operator-run-authority.worker.test.ts (the capture no longer runs a caller check; the caller gates before capture) and operator-access-program.worker.test.ts.

Pre-push (local):

  • ocx test with OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1 on 47 touched and directly related test files (the 537-file importer set is over the 150 cap; CI runs the rest). Reds: 3 text expectations and one capture-time test (updated above), 11 files invalidated by a mid-run edit (rerun: 13 files pass), and gateway.sessions-send-provenance.e2e cross-human phase (collaborativeSteeringRefused), which fails the same way on the merge base 6523d6ace21c.
  • pnpm tsgo:core, pnpm tsgo:test, pnpm tsgo:extensions: clean.
  • oxfmt and oxlint on changed files: clean.
  • lifetime-check and session-identity ratchets: OK (allowlist pruned 6289 → 6281).
  • CI round 1 OURS (4 files: requester-pause text, node-authority permission rows + text, session-tools text) fixed and rerun locally with 15 files that match the old texts: all pass. Round 1 MAIN-ALSO, each red on merge base 6523d6ace21c locally: question.session-access, question.communication, question.own-run, question.recovery, member-profile-role-recovery, mcp-http.personal-authority, mcp-http.async-scope, github-publication-imported-actions, ui sidebar-complete-roster.

Evidence

One-admission E2E (isolated Gateway, real model) on head fbea806e12bd, verdict.json pass:

  • R running-turn-finishes: pass (revoke while running → the turn finishes)
  • Q queued-input-refused-visibly: pass (revoke while queued → refused visibly)
  • S stop-cancels: pass (Stop → aborted)

Local review on fbea806e12bd: "patch is correct", no findings.

…efusals

- Admit the channel operator once at ingress; drop the capture-time assertCurrent plumbing and CommandOwnerRevokedError.
- Delete mid-run permission re-reads: node Full mode, operator assertCurrent in reply tools, client re-auth in presence and session controls, Discord command/owner re-checks.
- Drop the deprecated assertOwnerCurrent reads in bundled Discord and Telegram.
- Reword Stop, run-close and data-fence refusals to name what ended and the next step.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review blocked

Automated review did not run, so no review verdict was produced.

Reason: The input-safety check rejected material in this revision. No detected value, path, or scanner output is reproduced here.

Automatic review is on hold, including after source changes. Request a fresh re-review after resolving the failure; maintainers can also release the hold through an intentional scanner-policy update.

Next step: If this is a genuine credential, remove and rotate it. If it is an intentional test fixture, a maintainer must review and qualify it.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: telegram Channel integration: telegram gateway Gateway runtime agents Agent runtime and tooling size: L labels Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 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: fbea806e12bd8fa2759785bc658a1ac61d8d8b77
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/command/delivery-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/harness/node-execution-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/harness/tool-authority.runtime.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/subagents/requester-cron-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/tools/presence-tool-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/tools/sessions-operator-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/operator-run-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-activity-summary-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-repro Preliminary submission classification; full source review pending. labels Nov 23, 2026
- Remove the permission-mode change rows from the node authority tests (mid-run permission re-check).
- Match the reworded run-end and requester continuation refusals.
- Keep the GitHub publication worktree refusal text unchanged in this PR.

Co-authored-by: obviyus <[email protected]>
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: every red on head fbea806e12bd is MAIN-ALSO (ci-triage below). Each file also fails locally on merge base 6523d6ace21c with the same assertions. None of them asserts a string or behavior this PR changes.

# PR #204048 head fbea806e12bd; main run 45165162201
checks-node-changed-compact-large-22	src/gateway/mcp-http.personal-authority.test.ts	MAIN-ALSO
checks-node-changed-compact-large-33	src/gateway/mcp-http.async-scope.test.ts	MAIN-ALSO
checks-node-changed-compact-large-43	src/gateway/openclaw-id/member-profile-role-recovery.test.ts	MAIN-ALSO
checks-node-changed-compact-large-44-1	src/gateway/server-methods/question.own-run.test.ts	MAIN-ALSO
checks-node-changed-compact-large-44-1	src/gateway/server-methods/question.recovery.test.ts	MAIN-ALSO
checks-node-changed-compact-large-9	src/gateway/github-publication-imported-actions.test.ts	MAIN-ALSO
checks-node-changed-extensions-bundle-2	src/gateway/server-methods/question.communication.test.ts	MAIN-ALSO
checks-node-changed-extensions-bundle-2	src/gateway/server-methods/question.session-access.test.ts	MAIN-ALSO

@obviyus
obviyus merged commit e6b910b into main Nov 23, 2026
136 of 144 checks passed
@obviyus
obviyus deleted the refactor/agents-refusals-part3 branch November 23, 2026 12:28
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as e6b910b. Part 3 of the refusal sweep: the channel operator, Discord command/owner, Full-mode node and client re-auth re-checks are gone, so a started run finishes. Stop, run-close and data-fence refusals stay, reworded to say what ended. Proof: one-admission E2E Q/R/S pass on fbea806, clean local review, CI reds MAIN-ALSO only (override above). Next: part 4 covers the operatorAuthority.assertCurrent callers in src/auto-reply and src/agents.

obviyus added a commit that referenced this pull request Nov 23, 2026
… (R6c part 4a) (#204069)

## Problem

Authority is checked once, when work starts. A started run may finish; Stop cancels; data fences stay. After parts 1-3 (#203999, #204031, #204048), `src/auto-reply/**` still calls `operatorAuthority.assertCurrent()` mid-run in ~37 production files.

This is part 4a of the agents/sessions/auto-reply refusal sweep.

## Fix

Test for each site: can it fire when only a permission, approval or config changes while nothing about the run or data changes? Yes → authority re-check, deleted. No → Stop, run close or data fence, kept and reworded.

`operatorAuthority.assertCurrent()` re-reads the requester's source (request/ingress lifetime, held reference, caller check). Stop is not lost: every site below already checks the run's own abort signal next to it, and `resolveFollowupAbortSignal` already folds `operatorAuthority.signal` into the queued run's abort signal and the reply operation's upstream signal.

| Site | Kind | Action |
|---|---|---|
| `reply-agent-turn-preparation.ts` `assertOperatorCurrent` after the claim (×4) and the preflight-failure `beforeFreshMessageCommit` check | authority (queued start already re-admits through `prepareFollowupRunOperatorAuthority`, unchanged) | **deleted**; `operation.abortSignal` and lifecycle-generation checks stay |
| same file, the one check before the mailbox claim | queued start + data fence: a retired cron delivery fence (`createCronCompletionDeliveryFence`) rides on the queued source's `assertCurrent` | **kept** (cut less, CI round 1: without it a retired cron follow-up was claimed and left session-controller cleanup pending, `cron/service.restart-delivery.test.ts`) |
| `agent-runner-run.ts` (start + enqueue `assertCurrent`) | authority | **deleted**; lifecycle-generation check stays |
| `agent-runner-execute.ts` stalled-turn continuation | authority | **deleted**; the recorded `operatorAuthority.signal` refusal stays (now an `aborted` read, no try/catch) |
| `agent-runner-memory.ts` compaction `assertActive`, memory-flush `assertMemoryFlushCurrent` | authority | **deleted**; abort signal + `authorize()` stay |
| `agent-runner-session-activity.ts` activity commit | authority (only input of its `assertCurrent` param) | **deleted** with the param |
| `agent-runner-steer-adoption.ts`, `agent-runner-question-input.ts` | authority | **deleted**; abort signals stay |
| `followup-delivery-tts.ts` (×2), `followup-turn-execution.ts` (×3) | authority | **deleted**; `turn.operation.abortSignal` stays |
| `queue/delivery-context.ts`, `queue/enqueue.ts`, `queue/lifecycle.ts` (×2) | authority | **deleted**; cancellation/abort checks stay |
| `reply-input-admission.ts`, `reply-source-admission.ts` | authority | **deleted**; abort, lifecycle generation and controller-operation fences stay |
| `reply-source-binding.ts` | authority | **deleted**; source signal stays |
| `reply-tool-authority-inbound.ts` incoming collaborative-steering participant | authority | **deleted**; host-issuer check `assertAdmittedRunOperatorAuthority` stays |
| `reply-workspace.ts` + `get-reply.ts` plumbing | authority | **deleted** `operatorAuthority` param; preprocessing abort stays |
| `get-reply.ts` (×2: after agent scope, before reset hooks) | authority | **deleted**; preprocessing abort stays |
| `goal-continuation.ts` (×2), `goal-continuation-return.ts` (×2) | authority | **deleted**; eligibility, rearm-generation and session fences stay |

Left unchanged:
- `agents/worktrees/errors.ts` "GitHub publication worktree authority changed" (a registry data fence; reword planned: "GitHub publication worktree changed"). Cut less: its only expectation is in `gateway/github-publication.test.ts`, and the local review input scanner scans the whole touched file, including the base blob whose redaction fixture has a `user:password@` URL (trufflehog URI finding at line 403). Replacing the fixture still puts the old line in the reviewed input, so any PR that touches the file is refused until the scanner approves that synthetic value.
- Split per the ~25-file rule (this PR touches 20 production files, +11/−59): `operatorAuthority.assertCurrent` callers in `channel-run-admission`, `commands-compact`, `conversation-label-generator`, `dispatch-from-config.{gather,lifecycle,prepare-context,prepare-delivery,prepare-operation}`, `get-reply-inline-actions`, `get-reply-run-admission`, `get-reply-run-context`, `get-reply.types`, `model-selection`, `request-native-subagent`, `session-event-{context,handoff,target}` (17 files) go to part 4a-2; the `src/agents/**` callers are part 4b.

## User impact

- A requester whose access changes while their reply runs (preparation, compaction, memory flush, steering, TTS, goal continuation) sees the turn finish. The next request is admitted again.
- Queued input still re-admits at its start (`prepareFollowupRunOperatorAuthority`), so revoke-while-queued stays a visible refusal.
- Stop still cancels.
- No new refusal, prompt or wait.

## Tests

Deleted (they assert a mid-run permission refusal through `assertCurrent`):
- `agent-runner-memory.test.ts` `operator` invalidation row; `agent-runner-memory.accounting.test.ts` "rechecks live authority after delayed … accounting".
- `agent-runner.stalled-turn.test.ts` "unrecorded refusal" row (the recorded-revocation row stays).
- `agent-runner-direct-runtime-config.test.ts` "refused during preflight" and "revoked while resolving input" rows.
- `get-reply.workspace-failure.test.ts` operator-revocation half (the abort half stays).
- `agent-runner-steer-adoption.worker.test.ts` "keeps refused pre-handoff steering …" (used `assertCurrent` as the fault trigger).
- `goal-continuation.test.ts` `revoked` row; `queue/enqueue.steering.test.ts` "rechecks channel execution authority after waiting …" and "queues an unaccepted steer after an unrecorded authority refusal".
- `agent-runner-fallback-steering.test.ts` `backend-ready` + `caller revoked` row (the fingerprint rows still pass through agents-side readers, part 4b).
- `reply-agent-turn-preparation.test.ts` `revoked=true` row (operator signal abort during a mocked admission; real admissions follow it through the upstream signal) and the `assertCurrent` call-count expectation.

Pre-push (local):
- CI round 1 (`3c3c172b476d`): OURS `cron/service.restart-delivery.test.ts` teardown (fixed above by cutting less) and `server.chat-goal.test.ts` "lets an admitted owner Goal successor's tool effect finish" (69/69 pass locally on the fix head). Rerun of both plus `reply-agent-turn-preparation.test.ts`: 125/125 pass.
- `ocx test` with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 33 related test files (every direct importer test that builds an operator authority, plus the touched tests; the 382-file direct importer set is over the 150 cap, so CI runs the rest). 16 reds, all mid-run refusals through `assertCurrent`; deleted as listed above. Rerun of all 10 touched test files: 282/282 pass.
- `pnpm tsgo:core`, `pnpm tsgo:test`: clean. oxfmt and oxlint on changed files: clean.
- lifetime-check ratchet: OK (0 in changed files). session-identity ratchet: OK.

## Evidence

One-admission E2E (isolated Gateway, real model) on head `3094468004d1` (and before on `3c3c172b476d`), `verdict.json` `pass: true` both times:
- R `running-turn-finishes`: pass (revoke while running → the turn finishes; 3 tool ends after revoke)
- Q `queued-input-refused-visibly`: pass (revoke while queued → refused visibly in the transcript)
- S `stop-cancels`: pass (Stop → aborted)

Local review: "patch is correct", no findings, on `3c3c172b476d` and on `3094468004d1`.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 23, 2026
…dbox and command (#204093)

## Problem

Authority is checked once, when work starts. A started run may finish; Stop cancels; data fences stay. After parts 1–3 (#203999, #204031, #204048), code in `src/agents/**` still calls `operatorAuthority.assertCurrent()` (the admitted run operator authority) mid-run. That call re-runs the source's check and the authority's revocation signal, so a run that admission already allowed can fail partway through.

This is part 4b of the agents/sessions/auto-reply refusal sweep: the `src/agents/{tools,sandbox,command}` callers. Part 4a (auto-reply callers) is a separate PR.

## Fix

Test for each site: can it fire when only a permission, approval or config changes, and nothing about the run or its data changes? Yes → mid-run authority re-check, deleted. Every site below passed that test. Each path keeps its own Stop signal and data fences; the table says which ones.

| Site | Kind | Action |
|---|---|---|
| `tools/gateway.ts` `readGatewayToolOperatorScopes` | authority (presentation hint; RPC admission decides) | deleted |
| `tools/sessions-operator-authority.ts` `captureSessionControlAuthority` per-source `source.assertCurrent` | authority | deleted. The host-issued check and the same-source check do not change, so they now run once at capture. Invocation Stop and its check stay |
| `tools/sessions-operator-authority.ts` `prepareSandboxSessionTools` | authority | deleted (host-issued check stays) |
| `tools/presence-tool-authority.ts` | authority | deleted. The tool request keeps its `signal` (Stop) |
| `tools/agent-step.ts` returned peer result `operatorSource.assertCurrent` | authority | deleted. `operatorSource.signal` (Stop) and the prepared session source stay |
| `tools/image-tool.ts`, `tools/pdf-tool.ts` (×3) | authority | deleted. The execution signal (tool signal + operator signal), the invocation check and the runtime claim stay |
| `tools/gateway-caller-context.ts` operator selection and `withGatewayToolOperatorContinuation` | authority | deleted. `GatewayToolOperatorSelection.assertCurrent` is now only the selected participant's check, so it is optional |
| `sandbox/docker.ts`, `sandbox/docker-backend.ts` | authority | deleted. The runtime/caller checks and the container lifecycle lease stay |
| `sandbox/context.ts` (×2), `sandbox/stream-context.ts` | authority | deleted. The workspace signal (abort + operator signal), the state owner and the host guard stay |
| `command/prepare.ts`, `maintenance.ts`, `session-preparation.ts`, `post-run.ts` (×3), `cli-compaction.ts` | authority | deleted. The abort signal, the source assertion and the lifecycle generation stay |
| `command/model-selection.ts` (×3, including two `assertCommitAllowed` session writes) | authority | deleted. The host-issued check and the model-policy checks from admission stay |

None of these sites throws its own refusal string, so the lifetime-check ratchet counts do not change. No text was reworded.

Left for part 4c (the next split, 14 production files): `admitted-run-context.ts` (5 internal reads), `bash-tools.exec-runtime.ts`, `model-fallback-runner.ts`, `model-fallback-image.ts`, `operator-run-recovery-source.ts`, `plugin-tool-execution.ts`, `plugin-native-subagent.ts`, `harness/host-source-authority.ts`, `harness/selection.ts`, `cli-runner/tool-authority.ts`, `embedded-agent-runner/compact.queued.ts`, `subagents/spawn/subagent-spawn{,-collector}.ts`, `sessions/session-controller.tool-authority.ts`.

## User impact

- When an operator's role, grant or device changes during a run, a started agent turn no longer fails in the middle of session prep, model selection, post-run delivery, CLI compaction, sandbox setup, or the image, PDF, presence, session-control or agent-step tools. The next request is admitted again.
- Stop still cancels: each path keeps its abort signal.
- No new refusal, prompt or wait.

## Tests

Deleted (they assert a mid-run permission refusal):
- `agents/tools/gateway.operator-scopes.test.ts` (whole file: revoked source throws while scopes are read).
- `agents/tools/sessions-control-authority.test.ts`: source-revocation assertions in 4 cases. The checks on unissued copies, forged sources, insufficient scopes, reassignment and profile facts stay.
- `agents/tools/sessions-create-tool.test.ts`: the revocation step of the catalog projection case.
- `agents/sandbox/docker.access-lifetime.test.ts`: "does not let a revoked queued caller discard another grant's private custody". An admitted caller's grant is revoked while it waits on the container lifecycle lock.
- `agents/tools/sessions-tool.self-archive.test.ts`: the `revoked` row (source revoked during the detached archive) and the `retired-assign` step (a later tool call in the same run after revocation). Found in CI round 1.

## Evidence

- One-admission E2E on `846944a58649` (production is unchanged after it): R `running-turn-finishes`, Q `queued-input-refused-visibly`, S `stop-cancels` all pass. Details: #204093 (comment)
- Local review: clean on each head.
- `tsgo:core`, `tsgo:test`, oxfmt/oxlint on changed files: clean. `check:changed`: all ratchets and guards pass.
- `server-methods/users-personal-file.test.ts` "live" rows fail on main too (merge base `6c8c6dd946b7`, locally; ci-triage MAIN-ALSO).

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 23, 2026
… session events (R6c part 4a-2) (#204105)

## Problem

Authority is checked once, when work starts. A started run may finish, Stop cancels it, and data fences stay. After parts 1-3 and 4a (#203999, #204031, #204048, #204069), 17 files in `src/auto-reply/**` still call `operatorAuthority.assertCurrent()` while a run is in progress.

This is part 4a-2 of the refusal sweep for agents, sessions and auto-reply. Part 4b (`src/agents/**`) runs separately.

## Fix

The test for each site: can it fire when only a permission, approval or config changes, while nothing about the run or its data changes? If yes, it is an authority re-check, and this PR deletes it. If no, it is Stop, run close or a data fence, and this PR keeps it.

`operatorAuthority.assertCurrent()` reads the requester's source again (request or ingress lifetime, held reference, caller check). Stop still works: every site below keeps its own abort-signal, lifecycle-generation, session-data or occurrence check. Where a reply has one, the reply's upstream signal already includes `operatorAuthority.signal`.

| Site | Kind | Action |
|---|---|---|
| `dispatch-from-config.gather.ts`: `assertRequestCurrent` (session lookups ×3, progress check), check after runtime/TTS preparation | authority | **deleted**; abort signal, dispatch signal and lifecycle generation stay |
| `dispatch-from-config.lifecycle.ts` / `.prepare-operation.ts` `assertRequestCurrent`: the `replyOptions.operatorAuthority` branch | authority | **deleted**; the reserved input's own source (`sourceAdapter.authority`) is kept as the queued-start check before the claim, the same as in 4a. `internalEventExecution`, channel authority, retirement and abort checks stay |
| `dispatch-from-config.prepare-context.ts`, `.prepare-delivery.ts` | authority | **deleted**; pre-dispatch abort stays |
| `get-reply-inline-actions.ts` (before an inline tool, before commands) | authority | **deleted**; abort stays |
| `get-reply-run-admission.ts` preparation assertion | authority | **deleted** from the composition; internal-event and scheduled-automation sources (cron fence) stay |
| `get-reply-run-context.ts` scheduled path | authority | **deleted**; `scheduledAutomation.assertCurrent()` (cron run fence) and abort signals stay |
| `get-reply.types.ts` `prepareInternalGetReplyOptions` | authority | **deleted**; the host-issuer check `assertAdmittedRunOperatorAuthority` stays |
| `model-selection.ts` (entry, reset `commitGuard`, `assertSelectionCurrent`) | authority | **deleted**; host-issuer check, model-policy checks and the session-entry/selection data fence stay |
| `request-native-subagent.ts` (invocation `assertCurrent`, accepted-child `assertSourceCurrent`) | authority | **deleted**; guard, abort, state and `owner.assertOwnerCurrent` stay |
| `session-event-context.ts` (event preparation, owner successor `isCurrent`) | authority | **deleted**; the occurrence assertion and `operatorAuthority.signal` (Stop) stay |
| `session-event-handoff.ts` (`assertOwnerCurrent`, `captureSources`) | authority | **deleted**; settlement, acceptance, target, scheduled-automation, generation-lease, controller-operation and config-policy fences stay |
| `session-event-target.ts` (capture entry, `assertCaptureCurrent`) | authority | **deleted**; host-issuer check, capture/producer assertions and caller-occurrence checks stay |
| `commands-compact.ts` (entry, before acceptance) | authority | **deleted**; `rejectUnauthorizedCommand` at start, owner and current-read fences stay |
| `conversation-label-generator.ts` | authority | **deleted**; caller assertion, abort and model-policy check stay |
| `channel-run-admission.ts` `assertSourceCurrent` before admission | authority | **deleted**; caller's `assertSourceCurrent` and closed checks stay |

Left unchanged:
- `reply-agent-turn-preparation.ts` pre-claim check: the 4a cut-less site (cron delivery fence).
- `agents/worktrees/errors.ts`: parked (see #204069).
- No production authority-refusal strings remain in `src/auto-reply/**` or `src/sessions/**`. The lifetime-check ratchet reports 0 in changed files.

## User impact

- A requester whose access changes while a reply is being prepared (dispatch, model selection, inline actions, `/compact`, native subagents, session events, label generation) sees the turn finish. The next request goes through admission again.
- Queued input still goes through admission again when it starts, so a revoke while queued is still refused visibly.
- Stop still cancels.
- No new refusal, prompt or wait.

## Tests

Deleted (they assert a mid-run permission refusal through `assertCurrent`):
- `model-selection.test.ts` `authority` row of "rejects a changed … after awaiting missing-pin provider facts" (the pin/source/provider/session data rows stay).
- `commands-compact.lifecycle.test.ts` `adoption`/`operator` row of "rechecks … authority for … before effects" (CI round 1; the caller, plugin-owner, writer, invocation and session rows stay).
- `session-event-config-readmission.test.ts` "finalizes a failed-before-reply event …": only the assertion that the operator source is re-read after its policy scope closes; the failed-outcome assertions stay.

Pre-push (local):
- `ocx test` with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 61 related test files: every importer test of a changed file that builds an operator authority or tests revocation, plus the direct tests of the changed modules. The full set of 180 importers is over the 150 cap, so CI runs the rest. Reds: the two rows above (fixed; rerun 47/47 pass), and `gateway/server-methods/system-event-routing.test.ts` (3 tests). Those 3 are stale on main: they mock `captureTarget` and expect "Gateway requester authority changed" from the system-event and set-heartbeats handlers, which no longer throw it. They do not import any changed code path.
- `pnpm tsgo:core`, `pnpm tsgo:test`: clean. oxfmt and oxlint on changed files: clean.
- `pnpm check:changed`: all lanes green except the dead-export scan (`scripts/lib/docker-e2e-watchdog.mjs: parseTimeoutMs`, inherited from main; this PR does not touch it).
- Lifetime-check ratchet: OK (0 in changed files). Session-identity ratchet: OK.

## Evidence

One-admission E2E (isolated Gateway, real model) on head `ddbcdf98f7b6`, `verdict.json` `pass: true`:
- R `running-turn-finishes`: pass (revoke while running → the turn finishes)
- Q `queued-input-refused-visibly`: pass (revoke while queued → refused visibly in the transcript; 0 provider requests with the queued marker)
- S `stop-cancels`: pass (Stop → `aborted`)

Local review on `ddbcdf98f7b6`: "patch is correct", no findings.

CI round 1 (`ddbcdf98f7b6`): `commands-compact.lifecycle.test.ts` (OURS: a mid-run operator refusal row, deleted above) and `server.chat-goal.test.ts` "lets an admitted owner Goal successor's tool effect finish after ownership is revoked". That test asserts the behavior this PR keeps, and it passes locally on the head (69/69, the same as in #204069 round 1). The round-2 push (`e01a0ebc21bb`) changes one test only, so the E2E above still applies: production code is the same.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…203176)

## Problem

A requester that calls `sessions_yield` after spawning several completion-mode subagents was woken only when every member of the frozen yield batch was ready. A sibling that keeps running, or that pauses on its own `sessions_yield` while a background command runs, held every finished result back.

Production incident (2026-11-21): a dashboard parent spawned 3 children and yielded at 16:20 IST. Two children finished at 16:26:58 and 16:29:41 with reports that needed a decision. The third kept cycling through exec-yield and resume. The Gateway log has no `announce:requester-settle:…` run for that parent. The parent ran again only at 18:32, when the user typed into the chat. A copy of the state database shows why: both finished rows were `terminal`/`ok` with `delivery.status: pending` and a pending `requesterSettleWake` (`batchRunIds` = all 3, `rearmGeneration: 1`). The third row was still `running`. The gate in `subagent-announce.requester-settle-wake.ts` returned `false` unless every frozen member passed `isRequesterSettleMemberReady`. #200967 had already made an exception for siblings that wait for a message. An exec-yielded or running sibling is the same bug class.

## Change

Rule: every ready result wakes the yielded parent. Siblings that are still working keep their wake, with the same `rearmGeneration`, and wake the parent again when they finish. Each result is delivered once.

- **Settle wake:** removed the all-or-nothing gate and the message-wait exception (`isEndedSubagentMessageWait` is deleted). The wake delivers the ready members of the frozen batch as one partition, and lists the members that are still working. A member whose partition has already started dispatch records its own batch, so a later partition never offers it again. When a partition holds only results that were already delivered and siblings are still pending, it settles without a redundant wake.
- **Wake message:** a partition that leaves members pending no longer says "every subagent has settled… do not call sessions_yield again". It names the siblings that are still working (label, task name or run ID, at most 5, each truncated) and tells the parent: if the request needs those results, call `sessions_yield` to wait; otherwise act on the ready results without reporting the batch as finished.
- **Lifecycle failure path:** `offeredBatch` now offers only ready members, so failure settlement can never consume the wake of a sibling that is still running or exec-yielded.
- **Yield transfer:** when a child ended before the yield and a sibling is still running, `afterRelease` now schedules the settle for the finished child. Before, nothing woke the parent until the sibling ended.
- **Followup owners** (`sessions_send` wait-for-reply, `agent-step`, nested `agent-run-subagent`): the caller is waiting for a single reply. Only the partition that leaves no member pending continues the followup. Earlier partitions wake the session as ordinary settle turns. `successor()` accepts that last partition as a subset of its cohort, so it no longer throws and records the result as a permanent failure.
- **Automation authority:** a yield that carried cron-management authority keeps it for the partition that leaves no member pending. Earlier partitions run without borrowing it, and settling them shrinks the retained cohort instead of discarding the authority.
- **Silent waits:** while siblings are still working, the parent may stay silent (`NO_REPLY`) and wait. Such a turn is not treated as a missing visible reply, so it is not retried.
- **Goal return:** an earlier partition leaves the Goal cohort when it settles. The partition that settles the cohort last resumes the Goal once.
- `isRequesterSettleMemberReady` moved to `subagent-run-liveness.ts`, its only owner, and replaces the deleted message-wait predicate.
- Docs: `tools/subagents/announce.md` and `concepts/subagent-yield-handoff.md`.

Product decisions, under the rules "no stranded user" and "no false done":
- A stopped child is a settled outcome, so its report now wakes the parent right away instead of waiting for its siblings.
- A followup caller gets one reply, after all results are in. The session itself is still woken for each result.

## Evidence

**Regression test** (`subagent-registry.requester-wake.e2e.test.ts`, real registry, lifecycle, yield tool and wake entry point): spawn 2 children, yield, finish one, keep the other exec-yielded. The parent is woken with the finished result, and the wake names the working sibling. The sibling's continuation then wakes the parent again with only its own result. A sweep adds no third wake. A second case covers a child that ended before the yield, while the requester's turn held it.
- Base `eb7ca3d33375`: both cases red (`expected [] to have a length of 1`: no wake).
- Head: both cases green.

**Owner tests:** cron authority (`requester-cron-authority.test.ts`: the early partition neither borrows nor consumes the authority, and the last partition is admitted with it), followup partition (`subagent-announce.requester-settle-followup.test.ts`: early partition runs with no followup successor, last partition carries it). Goal partition (`goal-continuation.test.ts`: early partition does not resume the Goal, last partition resumes it once).

**Updated tests that asserted the all-at-once rule:** `requester-settle-cross-turn` (paused member), `subagent-control.worker` progress card (one wake per result; the card retires once), `requester-wake-settlement` (stopped child).

**Real-Gateway E2E**, incident shape. Scratch `ocx src` Gateway under `env -i`, OpenAI `gpt-5.5` on the OpenClaw runtime. Parent spawns `alpha` (replies at once) and `beta` (`exec` with `background: true` running `sleep 90`, then `sessions_yield`), then yields.

| | alpha ended | first parent wake | beta yielded | beta ended | second parent wake |
|---|---|---|---|---|---|
| base | 19:47:10 | **19:48:53** (one combined run, after beta) | 19:47:13 | 19:48:50 | none |
| head | 19:40:08 | **19:40:11** (`announce:requester-settle:…:<alpha>:yield-1`) | 19:40:12 | 19:41:55 | 19:41:59 (`…:<beta>:yield-1`) |

The parent's replies on head were `alpha: ALPHA-RESULT-7`, then `alpha: ALPHA-RESULT-7 / beta: BETA-RESULT-9`. The live Peanutto launchd pid and `openclaw.json` hash did not change.

**Live sibling suites** (`subagent-yield-pause`, `subagent-followup-yield`, `subagent-yield-resume`, real OpenAI `gpt-5.5`): the same tests fail on base `eb7ca3d33375` and on this branch, with the same assertions (missing `completion.resultText` after a resumed or paused child completes, a Gateway shutdown timeout, an interim reply in the follow-up watch case; follow-up-yield failed 2 of 2 on base). One run of this branch showed a parent that wrote its final report as soon as the first result arrived; the wake message now says to keep waiting when the request needs the remaining results, and that failure no longer appears. The real-Gateway restart e2e files (`test/gateway-*-restart*.e2e.test.ts`) fail locally on base too (11 of 26 on base, 9 of 26 here, same assertions).

**Gates:** `pnpm tsgo:core`, `pnpm check:test-types`, oxlint and oxfmt on the changed files. Every test file in `src/agents/subagents` and `goal-continuation.test.ts` was run across the unit-fast, infra, agents-support, spawn-boundary, core-isolated and e2e projects. Two infra tests failed once under host load and passed when run alone, on head and on base.

## Size

Production code is +96 / −56. The gate, the message-wait exception and its predicate are deleted. The added lines are the partition support the old gate did not need: pending members in the message, the followup last-partition rule, Goal cohort shrink, and pre-yield scheduling, and cron-authority cohort shrink. A census of `batchRunIds`, `requesterYieldBatch`, the frozen branch and `selectConnectedSettledSubagentWave` found every remaining reader still in use. v8 coverage could not attribute lines under the compiled-worker test runner (0 files collected in two attempts), so the census was done by reading the code.

## Accepted edge cases

- If a Goal cohort's last partition is rejected for an unrelated reason (for example, a rearm-generation mismatch), the Goal return stays retained until Stop or a lifecycle rotation. That is the same outcome as a failed final delivery today.
- A nested requester whose early partition answers without yielding reports that answer to its parent. The later result wakes it again as a separate completion.

## Merge danger

- **Two-way door.** No schema, stored-row or config change: the wake rows keep their existing fields and generation. A revert restores the all-at-once wake for every cohort, including rows written while this change ran.
- **Blast radius:** requesters that yield on two or more completion children (dashboard, chat and nested subagent requesters). A defect here would show as an extra or a missing wake for the parent, not as a lost child result: every result stays saved in its child session.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 09d956b)

Release adaptation: Kept stable QA Gateway fixture lifecycle; filtered intentionally silent partial-result wakes.

Companion audit: #203222 selected. #204249, #204069, #204048, #203892, #202513, #198960 not applicable (refactors/test cleanup); #204260, #204178, #204098, #204089, #203839, #203271 missing in lane and not prerequisites.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…efusals (openclaw#204048)

## Problem

Authority is checked once, when work starts. A started run may finish; Stop cancels; data fences stay. After parts 1 and 2 (openclaw#203999, openclaw#204031), some checks in `src/agents`, `src/channels/inbound-event` and the bundled Discord and Telegram native commands still re-read permissions mid-run, or refuse a data/lifecycle condition with text that claims "authority changed / is no longer active".

This is part 3 of the agents/sessions/auto-reply refusal sweep.

## Fix

Test for each site: can it fire when only a permission, approval or config changes while nothing about the run or data changes? Yes → authority re-check, deleted. No → Stop, run close or data fence, kept and reworded.

| Site | Kind | Action |
|---|---|---|
| `channels/inbound-event/host-context-builder.ts` channel operator `assertCurrent` ("Channel operator authority changed; send a new request.") | authority (called only once, inside `captureChannelOperatorRunAuthority`, right after the same `isCurrent` check) | **deleted**. The operator decision is taken once when the message is admitted (the existing `isCurrent` gate). The admitted authority's own `assertCurrent` was already Stop-only (`signal?.throwIfAborted()`), so queued channel messages do not re-read the enqueue-time operator; they start through the normal queued-start admission (openclaw#203468/openclaw#203521), unchanged |
| `gateway/operator-run-authority.ts` `captureChannelOperatorRunAuthority` `assertCurrent` input | plumbing for the above (only called once, at capture) | **deleted**. Its other caller, `gateway/session-activity-summary-authority.ts`, now runs its own one-time check directly before the capture (same check, same moment) |
| `auto-reply/command-owner-authority.ts` `CommandOwnerRevokedError` and the `instanceof` branch in `agents/command/delivery-authority.ts` | dead after the delete (no thrower left) | **deleted** |
| `agents/harness/node-execution-authority.ts` live `permissionMode === "full"` re-read (`retainedFullPermission`, `fullPermissionAllowed`) | authority (session permission mode) | **deleted**; Full stays the attempt's admitted mode (`attempt.permissionMode`, `admittedFull`) |
| same file, "admitted node execution authority is no longer current" (signal, plugin registry/lifecycle, Gateway context, plugin id, session occurrence, workspace) | Stop / run close / data fence | kept, reworded: "The run or its session ended. Start a new turn to retry." |
| `agents/harness/tool-authority.runtime.ts` `operatorAuthority?.assertCurrent()` in `assertReplyActive` | authority (Stop is already covered by `assertAdmitted`, which reads the run's abort signal) | **deleted** |
| same file, "embedded tool authority is no longer active" ×2 (lease closed, run instance/run id changed) | run close / occurrence | kept, reworded: "The agent run ended. Start a new turn to retry." |
| same file, "reply authority is no longer active", "embedded reply authority is no longer active" (operation route/fingerprint or attachment changed) | data fence | kept, reworded (existing text): "The reply target changed. Start a new turn to retry." |
| same file, "Embedded attempt authority changed during steering" | data fence | kept, reworded (existing text): "Steering target changed" |
| `agents/tools/gateway-caller-context.ts` "agent tool caller authority is no longer active" (no active admitted run lease) | run close | kept, reworded: "The agent run ended. Start a new turn to retry." |
| `agents/tools/presence-tool-authority.ts` `hasCurrentClientAuthority() === false` ("Gateway caller authority is no longer active.") | authority (client re-auth) | **deleted**; request Stop (`scope.signal`) kept |
| `agents/tools/sessions-operator-authority.ts` `hasCurrentClientAuthority() === false` ("Session control caller authority is no longer active.") | authority (client re-auth) | **deleted** |
| `agents/subagents/announce/subagent-announce.requester-settle-receipt.ts` "Requester settle authority changed during watch admission" (requester entry gone or store source changed) | data fence | kept, reworded: "Requester session ended during watch admission" |
| `agents/subagents/requester-cron-authority.ts` "Requester session authority changed before yield handoff" (session id, archive, lifecycle revision) | data fence | kept, reworded: "Requester session was reset or archived; yield handoff stopped" |
| same file, "Requester followup authority is no longer current", "Requester authority is no longer current" (`isCurrent`: active flag, lifecycle generation, binding, session revision; the channel-owner part is ingress lifetime only since openclaw#204031) | lifecycle / data fence | kept, reworded: "Requester followup ended", "Requester continuation ended" |
| `agents/worktrees/registry-run-end.worker.ts` "Managed worktree binding authority changed.", `run-end-lifecycle.ts` "Managed worktree registry authority changed; …" (registry row revision/owner fences) | data fence | kept, reworded: "Managed worktree binding changed.", "Managed worktree registry changed; prepare the operation again" |
| `extensions/discord/src/monitor/native-command-auth.ts` deprecated `CommandAuthorization.assertOwnerCurrent` read, `assertActive` ("Discord command authority changed; send a new request."), `assertOwnerCurrent` ("Discord owner authority changed; send a new request.") | authority (config/owner re-read after admission) | **deleted**. Access is read once at admission (`resolveDiscordNativeCommandAccess` returns `allowed` and `senderIsOwner`); the second `isAllowed()` after ACP binding readiness and the `assertAuthority`/`assertActive`/`assertOwnerCurrent` plumbing are gone |
| `extensions/telegram/src/{ingress,bot-native-command-dispatch,bot-native-command-plugins}.ts` deprecated `assertOwnerCurrent` reads | dead (`undefined` since openclaw#204031) | **deleted** |

Left unchanged:
- `bash-tools.exec-host-shared.ts` matcher (R6d).
- `agents/worktrees/errors.ts` "GitHub publication worktree authority changed" (a registry data fence). Cut less: its only test expectation lives in `gateway/github-publication.test.ts`, which carries a synthetic credential-URL fixture that the local review's input scanner refuses; the reword goes with the next gateway sweep.
- `operatorAuthority.assertCurrent` callers in `src/auto-reply/**` (~42 files) and `src/agents/**` (~70 files). Split per the ~25-file rule: this PR is 20 production files; the callers go to part 4.
- `extensions/discord/.../message-handler.draft-preview.ts` and `extensions/telegram/src/telegram-ingress-non-retryable.ts` strings (R6d area).

Production: 20 files, +95/−198. The lifetime-check ratchet counts fall in every touched file; `config/session-identity-allowlist.txt` is pruned for the reworded "no longer active" strings.

## User impact

- A linked channel user whose operator role or link changes after their message was admitted sees the run finish. The next message is admitted again.
- A Discord native command whose sender loses command or owner access while it runs now finishes, as admission decided.
- A session in Full permission mode whose mode is lowered during a run keeps node execution for that run; the next run uses the new mode.
- Refusals that remain now name what ended and the next step instead of claiming an authority change.
- No new refusal, prompt or wait. Stop still cancels.

## Tests

Deleted (they assert a mid-run permission refusal):
- `discord native-command.interaction-boundary.test.ts` `revoked-command` and `revoked-channel` rows (config/policy changed during the command).
- `sessions-control-authority.test.ts` "keeps the live client check when the ambient authority is passed back as prepared" (client deauth mid-run).
- `gateway.sessions-send-provenance.authority.test-support.ts` `unlink` and `reassign` phases (linked principal unlinked during final send). The `current` phase stays: a linked principal's message delivers.
- `host-capability.node-authority.test.ts` and `agent-runner-node-authority.test.ts` `permission` rows (session lowered from Full to workspace during the run).
- `commands-plugin.channel-native.test.ts` fixture cleanup for children that failed with the removed "Channel operator authority changed" text.

Text-only updates (same condition): `tool-authority.runtime.participants`, `.admission`, `.retention` support, `sessions-send-followup-revalidation`, `worker-session-tool-executor`, `server.requester-pause-authority`, `local-request-context.session-tools`, node-authority run-end text.

Capture-time input removed: `operator-run-authority.worker.test.ts` (the capture no longer runs a caller check; the caller gates before capture) and `operator-access-program.worker.test.ts`.

Pre-push (local):
- `ocx test` with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 47 touched and directly related test files (the 537-file importer set is over the 150 cap; CI runs the rest). Reds: 3 text expectations and one capture-time test (updated above), 11 files invalidated by a mid-run edit (rerun: 13 files pass), and `gateway.sessions-send-provenance.e2e` cross-human phase (`collaborativeSteeringRefused`), which fails the same way on the merge base `8a52d1d0de83`.
- `pnpm tsgo:core`, `pnpm tsgo:test`, `pnpm tsgo:extensions`: clean.
- oxfmt and oxlint on changed files: clean.
- lifetime-check and session-identity ratchets: OK (allowlist pruned 6289 → 6281).
- CI round 1 OURS (4 files: requester-pause text, node-authority `permission` rows + text, session-tools text) fixed and rerun locally with 15 files that match the old texts: all pass. Round 1 MAIN-ALSO, each red on merge base `8a52d1d0de83` locally: `question.session-access`, `question.communication`, `question.own-run`, `question.recovery`, `member-profile-role-recovery`, `mcp-http.personal-authority`, `mcp-http.async-scope`, `github-publication-imported-actions`, `ui sidebar-complete-roster`.

## Evidence

One-admission E2E (isolated Gateway, real model) on head `fbea806e12bd`, `verdict.json` pass:
- R `running-turn-finishes`: pass (revoke while running → the turn finishes)
- Q `queued-input-refused-visibly`: pass (revoke while queued → refused visibly)
- S `stop-cancels`: pass (Stop → aborted)

Local review on `fbea806e12bd`: "patch is correct", no findings.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
… (R6c part 4a) (openclaw#204069)

## Problem

Authority is checked once, when work starts. A started run may finish; Stop cancels; data fences stay. After parts 1-3 (openclaw#203999, openclaw#204031, openclaw#204048), `src/auto-reply/**` still calls `operatorAuthority.assertCurrent()` mid-run in ~37 production files.

This is part 4a of the agents/sessions/auto-reply refusal sweep.

## Fix

Test for each site: can it fire when only a permission, approval or config changes while nothing about the run or data changes? Yes → authority re-check, deleted. No → Stop, run close or data fence, kept and reworded.

`operatorAuthority.assertCurrent()` re-reads the requester's source (request/ingress lifetime, held reference, caller check). Stop is not lost: every site below already checks the run's own abort signal next to it, and `resolveFollowupAbortSignal` already folds `operatorAuthority.signal` into the queued run's abort signal and the reply operation's upstream signal.

| Site | Kind | Action |
|---|---|---|
| `reply-agent-turn-preparation.ts` `assertOperatorCurrent` after the claim (×4) and the preflight-failure `beforeFreshMessageCommit` check | authority (queued start already re-admits through `prepareFollowupRunOperatorAuthority`, unchanged) | **deleted**; `operation.abortSignal` and lifecycle-generation checks stay |
| same file, the one check before the mailbox claim | queued start + data fence: a retired cron delivery fence (`createCronCompletionDeliveryFence`) rides on the queued source's `assertCurrent` | **kept** (cut less, CI round 1: without it a retired cron follow-up was claimed and left session-controller cleanup pending, `cron/service.restart-delivery.test.ts`) |
| `agent-runner-run.ts` (start + enqueue `assertCurrent`) | authority | **deleted**; lifecycle-generation check stays |
| `agent-runner-execute.ts` stalled-turn continuation | authority | **deleted**; the recorded `operatorAuthority.signal` refusal stays (now an `aborted` read, no try/catch) |
| `agent-runner-memory.ts` compaction `assertActive`, memory-flush `assertMemoryFlushCurrent` | authority | **deleted**; abort signal + `authorize()` stay |
| `agent-runner-session-activity.ts` activity commit | authority (only input of its `assertCurrent` param) | **deleted** with the param |
| `agent-runner-steer-adoption.ts`, `agent-runner-question-input.ts` | authority | **deleted**; abort signals stay |
| `followup-delivery-tts.ts` (×2), `followup-turn-execution.ts` (×3) | authority | **deleted**; `turn.operation.abortSignal` stays |
| `queue/delivery-context.ts`, `queue/enqueue.ts`, `queue/lifecycle.ts` (×2) | authority | **deleted**; cancellation/abort checks stay |
| `reply-input-admission.ts`, `reply-source-admission.ts` | authority | **deleted**; abort, lifecycle generation and controller-operation fences stay |
| `reply-source-binding.ts` | authority | **deleted**; source signal stays |
| `reply-tool-authority-inbound.ts` incoming collaborative-steering participant | authority | **deleted**; host-issuer check `assertAdmittedRunOperatorAuthority` stays |
| `reply-workspace.ts` + `get-reply.ts` plumbing | authority | **deleted** `operatorAuthority` param; preprocessing abort stays |
| `get-reply.ts` (×2: after agent scope, before reset hooks) | authority | **deleted**; preprocessing abort stays |
| `goal-continuation.ts` (×2), `goal-continuation-return.ts` (×2) | authority | **deleted**; eligibility, rearm-generation and session fences stay |

Left unchanged:
- `agents/worktrees/errors.ts` "GitHub publication worktree authority changed" (a registry data fence; reword planned: "GitHub publication worktree changed"). Cut less: its only expectation is in `gateway/github-publication.test.ts`, and the local review input scanner scans the whole touched file, including the base blob whose redaction fixture has a `user:password@` URL (trufflehog URI finding at line 403). Replacing the fixture still puts the old line in the reviewed input, so any PR that touches the file is refused until the scanner approves that synthetic value.
- Split per the ~25-file rule (this PR touches 20 production files, +11/−59): `operatorAuthority.assertCurrent` callers in `channel-run-admission`, `commands-compact`, `conversation-label-generator`, `dispatch-from-config.{gather,lifecycle,prepare-context,prepare-delivery,prepare-operation}`, `get-reply-inline-actions`, `get-reply-run-admission`, `get-reply-run-context`, `get-reply.types`, `model-selection`, `request-native-subagent`, `session-event-{context,handoff,target}` (17 files) go to part 4a-2; the `src/agents/**` callers are part 4b.

## User impact

- A requester whose access changes while their reply runs (preparation, compaction, memory flush, steering, TTS, goal continuation) sees the turn finish. The next request is admitted again.
- Queued input still re-admits at its start (`prepareFollowupRunOperatorAuthority`), so revoke-while-queued stays a visible refusal.
- Stop still cancels.
- No new refusal, prompt or wait.

## Tests

Deleted (they assert a mid-run permission refusal through `assertCurrent`):
- `agent-runner-memory.test.ts` `operator` invalidation row; `agent-runner-memory.accounting.test.ts` "rechecks live authority after delayed … accounting".
- `agent-runner.stalled-turn.test.ts` "unrecorded refusal" row (the recorded-revocation row stays).
- `agent-runner-direct-runtime-config.test.ts` "refused during preflight" and "revoked while resolving input" rows.
- `get-reply.workspace-failure.test.ts` operator-revocation half (the abort half stays).
- `agent-runner-steer-adoption.worker.test.ts` "keeps refused pre-handoff steering …" (used `assertCurrent` as the fault trigger).
- `goal-continuation.test.ts` `revoked` row; `queue/enqueue.steering.test.ts` "rechecks channel execution authority after waiting …" and "queues an unaccepted steer after an unrecorded authority refusal".
- `agent-runner-fallback-steering.test.ts` `backend-ready` + `caller revoked` row (the fingerprint rows still pass through agents-side readers, part 4b).
- `reply-agent-turn-preparation.test.ts` `revoked=true` row (operator signal abort during a mocked admission; real admissions follow it through the upstream signal) and the `assertCurrent` call-count expectation.

Pre-push (local):
- CI round 1 (`3c3c172b476d`): OURS `cron/service.restart-delivery.test.ts` teardown (fixed above by cutting less) and `server.chat-goal.test.ts` "lets an admitted owner Goal successor's tool effect finish" (69/69 pass locally on the fix head). Rerun of both plus `reply-agent-turn-preparation.test.ts`: 125/125 pass.
- `ocx test` with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 33 related test files (every direct importer test that builds an operator authority, plus the touched tests; the 382-file direct importer set is over the 150 cap, so CI runs the rest). 16 reds, all mid-run refusals through `assertCurrent`; deleted as listed above. Rerun of all 10 touched test files: 282/282 pass.
- `pnpm tsgo:core`, `pnpm tsgo:test`: clean. oxfmt and oxlint on changed files: clean.
- lifetime-check ratchet: OK (0 in changed files). session-identity ratchet: OK.

## Evidence

One-admission E2E (isolated Gateway, real model) on head `3094468004d1` (and before on `3c3c172b476d`), `verdict.json` `pass: true` both times:
- R `running-turn-finishes`: pass (revoke while running → the turn finishes; 3 tool ends after revoke)
- Q `queued-input-refused-visibly`: pass (revoke while queued → refused visibly in the transcript)
- S `stop-cancels`: pass (Stop → aborted)

Local review: "patch is correct", no findings, on `3c3c172b476d` and on `3094468004d1`.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…dbox and command (openclaw#204093)

## Problem

Authority is checked once, when work starts. A started run may finish; Stop cancels; data fences stay. After parts 1–3 (openclaw#203999, openclaw#204031, openclaw#204048), code in `src/agents/**` still calls `operatorAuthority.assertCurrent()` (the admitted run operator authority) mid-run. That call re-runs the source's check and the authority's revocation signal, so a run that admission already allowed can fail partway through.

This is part 4b of the agents/sessions/auto-reply refusal sweep: the `src/agents/{tools,sandbox,command}` callers. Part 4a (auto-reply callers) is a separate PR.

## Fix

Test for each site: can it fire when only a permission, approval or config changes, and nothing about the run or its data changes? Yes → mid-run authority re-check, deleted. Every site below passed that test. Each path keeps its own Stop signal and data fences; the table says which ones.

| Site | Kind | Action |
|---|---|---|
| `tools/gateway.ts` `readGatewayToolOperatorScopes` | authority (presentation hint; RPC admission decides) | deleted |
| `tools/sessions-operator-authority.ts` `captureSessionControlAuthority` per-source `source.assertCurrent` | authority | deleted. The host-issued check and the same-source check do not change, so they now run once at capture. Invocation Stop and its check stay |
| `tools/sessions-operator-authority.ts` `prepareSandboxSessionTools` | authority | deleted (host-issued check stays) |
| `tools/presence-tool-authority.ts` | authority | deleted. The tool request keeps its `signal` (Stop) |
| `tools/agent-step.ts` returned peer result `operatorSource.assertCurrent` | authority | deleted. `operatorSource.signal` (Stop) and the prepared session source stay |
| `tools/image-tool.ts`, `tools/pdf-tool.ts` (×3) | authority | deleted. The execution signal (tool signal + operator signal), the invocation check and the runtime claim stay |
| `tools/gateway-caller-context.ts` operator selection and `withGatewayToolOperatorContinuation` | authority | deleted. `GatewayToolOperatorSelection.assertCurrent` is now only the selected participant's check, so it is optional |
| `sandbox/docker.ts`, `sandbox/docker-backend.ts` | authority | deleted. The runtime/caller checks and the container lifecycle lease stay |
| `sandbox/context.ts` (×2), `sandbox/stream-context.ts` | authority | deleted. The workspace signal (abort + operator signal), the state owner and the host guard stay |
| `command/prepare.ts`, `maintenance.ts`, `session-preparation.ts`, `post-run.ts` (×3), `cli-compaction.ts` | authority | deleted. The abort signal, the source assertion and the lifecycle generation stay |
| `command/model-selection.ts` (×3, including two `assertCommitAllowed` session writes) | authority | deleted. The host-issued check and the model-policy checks from admission stay |

None of these sites throws its own refusal string, so the lifetime-check ratchet counts do not change. No text was reworded.

Left for part 4c (the next split, 14 production files): `admitted-run-context.ts` (5 internal reads), `bash-tools.exec-runtime.ts`, `model-fallback-runner.ts`, `model-fallback-image.ts`, `operator-run-recovery-source.ts`, `plugin-tool-execution.ts`, `plugin-native-subagent.ts`, `harness/host-source-authority.ts`, `harness/selection.ts`, `cli-runner/tool-authority.ts`, `embedded-agent-runner/compact.queued.ts`, `subagents/spawn/subagent-spawn{,-collector}.ts`, `sessions/session-controller.tool-authority.ts`.

## User impact

- When an operator's role, grant or device changes during a run, a started agent turn no longer fails in the middle of session prep, model selection, post-run delivery, CLI compaction, sandbox setup, or the image, PDF, presence, session-control or agent-step tools. The next request is admitted again.
- Stop still cancels: each path keeps its abort signal.
- No new refusal, prompt or wait.

## Tests

Deleted (they assert a mid-run permission refusal):
- `agents/tools/gateway.operator-scopes.test.ts` (whole file: revoked source throws while scopes are read).
- `agents/tools/sessions-control-authority.test.ts`: source-revocation assertions in 4 cases. The checks on unissued copies, forged sources, insufficient scopes, reassignment and profile facts stay.
- `agents/tools/sessions-create-tool.test.ts`: the revocation step of the catalog projection case.
- `agents/sandbox/docker.access-lifetime.test.ts`: "does not let a revoked queued caller discard another grant's private custody". An admitted caller's grant is revoked while it waits on the container lifecycle lock.
- `agents/tools/sessions-tool.self-archive.test.ts`: the `revoked` row (source revoked during the detached archive) and the `retired-assign` step (a later tool call in the same run after revocation). Found in CI round 1.

## Evidence

- One-admission E2E on `846944a58649` (production is unchanged after it): R `running-turn-finishes`, Q `queued-input-refused-visibly`, S `stop-cancels` all pass. Details: openclaw#204093 (comment)
- Local review: clean on each head.
- `tsgo:core`, `tsgo:test`, oxfmt/oxlint on changed files: clean. `check:changed`: all ratchets and guards pass.
- `server-methods/users-personal-file.test.ts` "live" rows fail on main too (merge base `a02826832065`, locally; ci-triage MAIN-ALSO).

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
… session events (R6c part 4a-2) (openclaw#204105)

## Problem

Authority is checked once, when work starts. A started run may finish, Stop cancels it, and data fences stay. After parts 1-3 and 4a (openclaw#203999, openclaw#204031, openclaw#204048, openclaw#204069), 17 files in `src/auto-reply/**` still call `operatorAuthority.assertCurrent()` while a run is in progress.

This is part 4a-2 of the refusal sweep for agents, sessions and auto-reply. Part 4b (`src/agents/**`) runs separately.

## Fix

The test for each site: can it fire when only a permission, approval or config changes, while nothing about the run or its data changes? If yes, it is an authority re-check, and this PR deletes it. If no, it is Stop, run close or a data fence, and this PR keeps it.

`operatorAuthority.assertCurrent()` reads the requester's source again (request or ingress lifetime, held reference, caller check). Stop still works: every site below keeps its own abort-signal, lifecycle-generation, session-data or occurrence check. Where a reply has one, the reply's upstream signal already includes `operatorAuthority.signal`.

| Site | Kind | Action |
|---|---|---|
| `dispatch-from-config.gather.ts`: `assertRequestCurrent` (session lookups ×3, progress check), check after runtime/TTS preparation | authority | **deleted**; abort signal, dispatch signal and lifecycle generation stay |
| `dispatch-from-config.lifecycle.ts` / `.prepare-operation.ts` `assertRequestCurrent`: the `replyOptions.operatorAuthority` branch | authority | **deleted**; the reserved input's own source (`sourceAdapter.authority`) is kept as the queued-start check before the claim, the same as in 4a. `internalEventExecution`, channel authority, retirement and abort checks stay |
| `dispatch-from-config.prepare-context.ts`, `.prepare-delivery.ts` | authority | **deleted**; pre-dispatch abort stays |
| `get-reply-inline-actions.ts` (before an inline tool, before commands) | authority | **deleted**; abort stays |
| `get-reply-run-admission.ts` preparation assertion | authority | **deleted** from the composition; internal-event and scheduled-automation sources (cron fence) stay |
| `get-reply-run-context.ts` scheduled path | authority | **deleted**; `scheduledAutomation.assertCurrent()` (cron run fence) and abort signals stay |
| `get-reply.types.ts` `prepareInternalGetReplyOptions` | authority | **deleted**; the host-issuer check `assertAdmittedRunOperatorAuthority` stays |
| `model-selection.ts` (entry, reset `commitGuard`, `assertSelectionCurrent`) | authority | **deleted**; host-issuer check, model-policy checks and the session-entry/selection data fence stay |
| `request-native-subagent.ts` (invocation `assertCurrent`, accepted-child `assertSourceCurrent`) | authority | **deleted**; guard, abort, state and `owner.assertOwnerCurrent` stay |
| `session-event-context.ts` (event preparation, owner successor `isCurrent`) | authority | **deleted**; the occurrence assertion and `operatorAuthority.signal` (Stop) stay |
| `session-event-handoff.ts` (`assertOwnerCurrent`, `captureSources`) | authority | **deleted**; settlement, acceptance, target, scheduled-automation, generation-lease, controller-operation and config-policy fences stay |
| `session-event-target.ts` (capture entry, `assertCaptureCurrent`) | authority | **deleted**; host-issuer check, capture/producer assertions and caller-occurrence checks stay |
| `commands-compact.ts` (entry, before acceptance) | authority | **deleted**; `rejectUnauthorizedCommand` at start, owner and current-read fences stay |
| `conversation-label-generator.ts` | authority | **deleted**; caller assertion, abort and model-policy check stay |
| `channel-run-admission.ts` `assertSourceCurrent` before admission | authority | **deleted**; caller's `assertSourceCurrent` and closed checks stay |

Left unchanged:
- `reply-agent-turn-preparation.ts` pre-claim check: the 4a cut-less site (cron delivery fence).
- `agents/worktrees/errors.ts`: parked (see openclaw#204069).
- No production authority-refusal strings remain in `src/auto-reply/**` or `src/sessions/**`. The lifetime-check ratchet reports 0 in changed files.

## User impact

- A requester whose access changes while a reply is being prepared (dispatch, model selection, inline actions, `/compact`, native subagents, session events, label generation) sees the turn finish. The next request goes through admission again.
- Queued input still goes through admission again when it starts, so a revoke while queued is still refused visibly.
- Stop still cancels.
- No new refusal, prompt or wait.

## Tests

Deleted (they assert a mid-run permission refusal through `assertCurrent`):
- `model-selection.test.ts` `authority` row of "rejects a changed … after awaiting missing-pin provider facts" (the pin/source/provider/session data rows stay).
- `commands-compact.lifecycle.test.ts` `adoption`/`operator` row of "rechecks … authority for … before effects" (CI round 1; the caller, plugin-owner, writer, invocation and session rows stay).
- `session-event-config-readmission.test.ts` "finalizes a failed-before-reply event …": only the assertion that the operator source is re-read after its policy scope closes; the failed-outcome assertions stay.

Pre-push (local):
- `ocx test` with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 61 related test files: every importer test of a changed file that builds an operator authority or tests revocation, plus the direct tests of the changed modules. The full set of 180 importers is over the 150 cap, so CI runs the rest. Reds: the two rows above (fixed; rerun 47/47 pass), and `gateway/server-methods/system-event-routing.test.ts` (3 tests). Those 3 are stale on main: they mock `captureTarget` and expect "Gateway requester authority changed" from the system-event and set-heartbeats handlers, which no longer throw it. They do not import any changed code path.
- `pnpm tsgo:core`, `pnpm tsgo:test`: clean. oxfmt and oxlint on changed files: clean.
- `pnpm check:changed`: all lanes green except the dead-export scan (`scripts/lib/docker-e2e-watchdog.mjs: parseTimeoutMs`, inherited from main; this PR does not touch it).
- Lifetime-check ratchet: OK (0 in changed files). Session-identity ratchet: OK.

## Evidence

One-admission E2E (isolated Gateway, real model) on head `ddbcdf98f7b6`, `verdict.json` `pass: true`:
- R `running-turn-finishes`: pass (revoke while running → the turn finishes)
- Q `queued-input-refused-visibly`: pass (revoke while queued → refused visibly in the transcript; 0 provider requests with the queued marker)
- S `stop-cancels`: pass (Stop → `aborted`)

Local review on `ddbcdf98f7b6`: "patch is correct", no findings.

CI round 1 (`ddbcdf98f7b6`): `commands-compact.lifecycle.test.ts` (OURS: a mid-run operator refusal row, deleted above) and `server.chat-goal.test.ts` "lets an admitted owner Goal successor's tool effect finish after ownership is revoked". That test asserts the behavior this PR keeps, and it passes locally on the head (69/69, the same as in openclaw#204069 round 1). The round-2 push (`e01a0ebc21bb`) changes one test only, so the E2E above still applies: production code is the same.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: discord Channel integration: discord channel: telegram Channel integration: telegram clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. gateway Gateway runtime security-sensitive-changed size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant