Skip to content

refactor(agents): drop mid-run operator re-checks in agent tools, sandbox and command - #204093

Merged
obviyus merged 2 commits into
mainfrom
refactor/agents-assert-current
Nov 23, 2026
Merged

obviyus merged 2 commits into
mainfrom
refactor/agents-assert-current

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–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: refactor(agents): drop mid-run operator re-checks in agent tools, sandbox and command #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).

…dbox and command

Admission already decided the run's operator authority. Delete the mid-run
`operatorAuthority.assertCurrent` reads in src/agents/{tools,sandbox,command};
each path keeps its abort signal (Stop) and its data fences.

Delete tests that asserted a mid-run source revocation refusal.

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 complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@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: 2e726da6d2113a62ffa8dffc263cb16fb1a06eab
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/sandbox/context.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/docker-backend.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/docker.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/stream-context.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • 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.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 23, 2026
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Evidence on head 846944a58649:

  • One-admission E2E (isolated Gateway, real model gpt-5.5): verdict.json pass.
    • R running-turn-finishes: pass (revoke while running → turn finishes, 3 tool ends after revoke)
    • Q queued-input-refused-visibly: pass (revoke while queued → visible refusal, no provider request)
    • S stop-cancels: pass (Stop → aborted)
  • Local review: "patch is correct", no findings.
  • Pre-push: ocx test on 88 directly related test files (the 364-file direct importer set is over the 150 cap; CI runs the rest), with OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1. Reds: 4 files that assert a mid-run source revocation refusal (deleted or trimmed, listed below), plus github-publication-imported-actions and users-personal-file "live" rows, which also fail on main.
  • pnpm tsgo:core, pnpm tsgo:test: clean. oxfmt/oxlint on changed files: clean. pnpm check:changed: every ratchet and guard passed. Two items failed in files this PR does not touch: the full-tree Knip export in scripts/lib/docker-e2e-watchdog.mjs, and a whole-core oxlint pass that timed out after 15 min at host load ~60, with errors only in src/gateway/update-run-watcher*.

Tests deleted (they assert a mid-run permission refusal):

  • agents/tools/gateway.operator-scopes.test.ts: whole file. It asserts that a revoked source throws while scopes are read.
  • agents/tools/sessions-control-authority.test.ts: source-revocation assertions in 4 cases (capture, ambient client, prepare, prepared-action fence). 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". It revokes the grant of an admitted caller while that caller waits on the container lifecycle lock.
verdict.json (checks)
{
  "pass": true,
  "prefix": "HEAD",
  "models": [
    null,
    "gpt-5.5-2026-04-23"
  ],
  "checks": [
    {
      "id": "R.running-turn-finishes",
      "pass": true,
      "detail": {
        "state": "final",
        "toolEnds": 3,
        "toolEndsAfterRevoke": 3
      }
    },
    {
      "id": "Q.queued-input-refused-visibly",
      "pass": true,
      "detail": {
        "accepted": true,
        "providerRequestsWithQueuedMarker": 0,
        "visibleRefusalInTranscript": true
      }
    },
    {
      "id": "S.stop-cancels",
      "pass": true,
      "detail": {
        "abort": {
          "ok": true,
          "aborted": true,
          "runIds": [
            "934d7d20-d9a5-449b-a301-17d0445016fb"
          ]
        },
        "state": "aborted",
        "requestsWithStopMarker": 1
      }
    }
  ]
}

results.jsonl: 28 event rows from the same run.

@clawsweeper

clawsweeper Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR removes repeated operator-authority checks from agent tools, sandbox preparation, and command execution while retaining existing cancellation and target checks.

Example: Alice’s operator permissions change after her agent turn starts.

  • Before: A later source-authority check can interrupt the already-admitted turn.
  • After: The changed callers let that turn continue under its admitted authority, while subsequent requests undergo admission again.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and no actionable introduced defect was found, but behavioral evidence lacks changed-path attribution and exact-head CI remains incomplete with an unverified failure comparison.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An already-admitted agent turn can fail when the operator’s permissions change during execution.
Reason: The maintainer-authored direction matches explicit repository policy and earlier merged work, and the patch removes redundant machinery.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR advances the repository’s admission-once policy, and current main still contains the targeted checks; no concrete introduced correctness defect was established.

Priority: P2
Reviewed head: 846944a58649821300deca6a72fd579b537ed0db

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Attach redacted events identifying at least one changed tool, sandbox, or command boundary exercised after the permission change; the posted verdict omits those events and does not show a base-failing regression.
Agent review details

How this fits together

Gateway admission supplies host-issued operator authority to agent execution; tools, sandbox provisioning, and command lifecycle code consume that authority to perform work and publish results.

flowchart TD
  A[Operator request] --> B[Gateway admission]
  B --> C[Admitted agent run]
  C --> D[Tools and sandbox]
  C --> E[Command lifecycle]
  F[Stop and target checks] --> D
  F --> E
  D --> G[Effects and results]
  E --> G
Loading

Technical review

Best possible solution:

Keep admission authoritative at request start and remove redundant caller rechecks while preserving existing Stop, lifecycle, and target owners.

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

The base directly reevaluates operator source predicates during admitted execution, so a subsequently throwing source reaches the reported interruption path; no independent reproduction was run during this read-only review.

Is this the best way to solve the issue?

The deletion-focused approach uses existing admission and cancellation owners, and the removed assertions correspond to behavior intentionally superseded by the admission-once policy.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Model selection and image/PDF source checks changes intended behavior with a stated reason (6b4ebc0: Role-based model enforcement introduced source checks alongside model-policy checks; this PR removes repeated source checks while retaining model authorization.)
  • Docker and Podman preparation source checks changes intended behavior with a stated reason (08f5fb8: The earlier Guest-work repair retained original access through container and process lifetimes; this PR follows the newer started-work policy while keeping container custody and cancellation mechanisms.)
  • Session-control and selected-requester checks changes intended behavior with a stated reason (unknown: History spans requester isolation, continuation custody, writer refactors, and the recent refusal sweep; the exact first introduction of every removed check was not established, and older-content searches encountered unavailable objects.)
  • Command preparation and compaction source checks changes intended behavior with a stated reason (unknown: Earlier compaction and worker-mutation refactors carried source authority through preparation, completion, and writes; the current change explicitly replaces repeated permission evaluation with the admitted decision while retaining cancellation and lifecycle predicates.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit e6b910b adds src/agents/tools/sessions-operator-authority.ts:41 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e6b910beb732; files: src/agents/tools/sessions-operator-authority.ts)
  • Shakker: Raw commit 08f5fb8 adds src/agents/sandbox/docker.ts:475 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 08f5fb80f301; files: src/agents/sandbox/docker.ts)

PR surface

Source -45, Tests -71. Total -116 across 21 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 17 21 66 -45
Tests 4 9 80 -71
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 30 146 -116

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Permission changes can interrupt admitted agent work, but the affected circumstances have limited blast radius.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Permission changes can interrupt admitted agent work, but the affected circumstances have limited blast radius.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

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

Workflow

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

Reviewed November 23, 2026, 9:43 AM ET / 14:43 UTC.

…elf-archive

The run's operator source is admitted once; a revoke during the detached
archive or between tool calls in the same run no longer refuses.

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

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: the only red on head 2e726da6d211 is not caused by this PR.

# PR #204093 head 2e726da6d211; main run 45184109257
checks-node-changed-compact-large-22	src/gateway/server-methods/users-personal-file.test.ts	MAIN-ALSO
  • src/gateway/server-methods/users-personal-file.test.ts "carries authenticated … owner ingress through the chat tool: live" fails the same way on the merge base 6c8c6dd946b7 locally: it expects no longer active, gets Operator execution ended. Reconnect to the Gateway, then resend your message. This PR does not touch the file, and it is outside this PR's area.
  • openclaw/ci-gate only aggregates that job.

@obviyus
obviyus merged commit 5c2145e into main Nov 23, 2026
133 of 136 checks passed
@obviyus
obviyus deleted the refactor/agents-assert-current branch November 23, 2026 15:11
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 5c2145e. Admitted runs no longer re-check the operator authority mid-run in agent tools, sandbox setup and command prep/post-run: a role or grant change after admission lets the turn finish, and the next request is admitted again. Stop still cancels (each path keeps its abort signal). Proof: one-admission E2E R/Q/S pass, local review clean, CI red only on the main-also users-personal-file rows. The remaining 14 production files (admitted-run-context, harness, subagents spawn, cli-runner, embedded runner, model fallback, plugin-native subagent, sessions tool-authority) are the next split.

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. security-sensitive-changed size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant