Skip to content

refactor(agents): remove captured tool source execution guards - #202522

Merged
obviyus merged 5 commits into
mainfrom
refactor/delete-tool-source-guard
Nov 20, 2026
Merged

obviyus merged 5 commits into
mainfrom
refactor/delete-tool-source-guard

Conversation

@obviyus

@obviyus obviyus commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Tool execution captured caller authority and reasserted it after asynchronous preparation and during already-started file, process, plugin, spawn, fetch, and media work. This contradicts the repository's “check authority one time, when work starts” rule. Scoped authority-simplification work requested by Ayaan.

Fix

  • Delete captureAgentToolSourceExecutionGuard, its guard-only plugin async context, and its ratchet entry.
  • Remove 24 production capture calls plus two calls to the now-deleted adapter capture wrapper.
  • Keep tool entry admission with the existing bound-tool owner and keep deferred media admission at actual execution start.
  • Unwrap guard-only execution scopes. Preserve filesystem containment, worker/session data fences, explicit cancellation, and borrowed-handle rollback through the existing fs-safe write owner.

Behavior

An admitted tool invocation can finish after its source authority changes. New work still enters through existing admission owners; explicit cancellation and data/ownership fences remain in force.

Removed obsolete authority-only rejection expectations and retained cancellation, input custody, provenance, and worker-generation coverage. Explicit cancellation regressions cover host write/apply_patch rollback preparation, native workspace writes, and memory append provenance preparation.

Production delta, excluding tests and test support: +582 / -885 (net -303). Most added lines are indentation changes from unwrapping scopes. No new helper, hook, schema, configuration, or error type.

Evidence

  • git grep captureAgentToolSourceExecutionGuard: no references remain.
  • pnpm exec oxfmt --write <touched files>: passed.
  • pnpm exec oxlint <touched files>: passed.
  • No local tests or typechecks run, as requested. GitHub CI is the runtime/typecheck proof.
  • Simplified against existing owners; no replacement captured authority helper.
  • Addressed failures from CI run 44756051205: removed stale mid-flight refusal and dispatch-shape assertions; preserved explicit Stop, fork cleanup, parent-reset fences, queued channel recovery admission, credential revocation, and later-invocation coverage. Media preflight now rechecks its existing resource owner's open state after reference loading, before task handoff. Lowered the remaining session-identity allowance from two to one.

Related work

Approved overlap with #202513 includes the single ratchet entry, guard-only changes in both src/gateway/server.agent-input-authority*.test.ts files, and the specifically requested CI repair to src/gateway/operator-run-recovery.channel.test.ts (retains queued recovery refusal instead of in-flight I/O revocation). No skipped capture call sites.

- Admit tools through their existing entry owners instead of capturing and rechecking authority during an invocation.
- Remove guard-only plugin context, file mutation scopes, and stale mid-flight revocation expectations while retaining cancellation, recovery, and data fences.
@clawsweeper

clawsweeper Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

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

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: XL labels Nov 20, 2026
- Remove authority rechecks after durable observation, polling, and stdin writes.
- Retain action-start admission and selected-process identity/scope fences.
- Restore host write and mkdir abort propagation without restoring source-authority assertions.
- Preserve signal-only cancellation at preparation, replay, launch, and deferred-media boundaries previously covered by the deleted guard.
- Restore cancellation regressions for ordinary host writes, apply_patch commits, workspace native writes, and memory appends.
@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 20, 2026
@clawsweeper

clawsweeper Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR removes captured authority rechecks from admitted tool work while retaining entry admission, cancellation, and data fences.

Example: A write to notes.txt is admitted before its source authority retires during preparation.

  • Before: The write rejects when it rechecks the retired authority.
  • After: The admitted write may finish; explicit cancellation still prevents mutation.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The direction is worthwhile, but the submitted revision is not merge-ready.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 3 actionable review findings remain.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: An admitted tool operation can fail because its source authority changes during asynchronous work.
Reason: The maintainer-authored direction matches root policy and removes redundant machinery while preserving existing admission owners.

Merge readiness

⛔ Needs changes before merge - 3 items remain

Keep open: this maintainer-authored simplification follows the repository’s authority policy, but the test cutover is incomplete and introduces deterministic CI failures.

Priority: P2
Reviewed head: 22fe6d0428558fbf2d73ad4e5b756174ad333b93

Before merge

  • [P2] Migrate the remaining consumers of removed authority guards (P2) - The production cutover leaves consumer suites asserting the removed mechanism. For example, agent-tools.delegated-authority.test.ts waits for writeHostFile’s second authority preparation and now fails because the write settles; plugin tool-factory-context.test.ts still requires the deleted invocation scope, and node-host tests still require the removed source-bound dispatchAuthority. Exact-head CI also reports old mid-call refusal expectations in exec, spawn, media, and recovered-channel suites. Update or remove those obsolete cases together, preserving their distinct cancellation and next-request admission coverage rather than restoring the removed guards.
  • [P2] Align the edit cancellation assertion with its surviving owner (P2) - For kind=edit and authority=aborted, removing the source scope means the post-planning assertFileToolNotAborted check now throws Operation aborted. This changed test still expects Planning cancelled, so the cancellation case fails deterministically in exact-head CI. Assert the surviving cancellation contract while retaining the unchanged-file and zero-mutation assertions.
  • [P2] Update the worker-fence assertion after replacing its source (P2) - Passing source directly changes which retained data fence rejects the reset case. CI now reports Cloud worker transcript identity is no longer current (source callback: mismatched lifecycleRevision), while the same test still requires the old worker-turn-authority message at line 275. Align the assertion with the replacement fence and keep the checks that the parent lifecycle changes and no child row is created.

Findings

  • [P2] [P2] Migrate the remaining consumers of removed authority guards — src/agents/host-file-write.ts:32-34
  • [P2] [P2] Align the edit cancellation assertion with its surviving owner — src/agents/sessions/tools/file-tool-planning.test.ts:92-93
  • [P2] [P2] Update the worker-fence assertion after replacing its source — src/gateway/worker-environments/placement-turn-authority.test.ts:250

Tests

  • Low-value test src/agents/memory-write-provenance.test.ts: Remove the replacement write/remove success group: it checks filesystem results using a pass-through observer but would still pass if the provenance wrapper bypassed that observer entirely.
  • Missing end-to-end proof: Provide redacted Gateway or CLI evidence that admitted work finishes after source retirement, a subsequent invocation is refused, and explicit cancellation prevents mutation, together with base-fail/head-pass regression results.
Agent review details

How this fits together

The agent tool adapter and bound-tool owners admit model-requested operations, which then reach filesystem, process, plugin, spawn, fetch, and media implementations and return tool results.

flowchart TD
  A[Model tool call] --> B[Adapter and bound tool admission]
  B --> C[Preparation and hooks]
  C --> D[Tool implementation]
  D --> E[Filesystem process or transport]
  D --> F[Deferred media admission]
  F --> E
  E --> G[Tool result]
Loading

Technical review

Best possible solution:

Complete the test migration around the existing admission owners, retaining cancellation, next-invocation refusal, and data-fence coverage without restoring captured mid-call authority checks.

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

Current-main source shows captured authority being reasserted within admitted operations, and exact-head CI supplies concrete failing consumer cases; no local reproduction was run.

Is this the best way to solve the issue?

Removing the redundant captures and scopes is the smallest coherent implementation using existing owners, but the affected consumer tests must migrate with it.

Full review comments:

  • [P2] [P2] Migrate the remaining consumers of removed authority guards — src/agents/host-file-write.ts:32-34
    The production cutover leaves consumer suites asserting the removed mechanism. For example, agent-tools.delegated-authority.test.ts waits for writeHostFile’s second authority preparation and now fails because the write settles; plugin tool-factory-context.test.ts still requires the deleted invocation scope, and node-host tests still require the removed source-bound dispatchAuthority. Exact-head CI also reports old mid-call refusal expectations in exec, spawn, media, and recovered-channel suites. Update or remove those obsolete cases together, preserving their distinct cancellation and next-request admission coverage rather than restoring the removed guards.
    Confidence: 0.99
  • [P2] [P2] Align the edit cancellation assertion with its surviving owner — src/agents/sessions/tools/file-tool-planning.test.ts:92-93
    For kind=edit and authority=aborted, removing the source scope means the post-planning assertFileToolNotAborted check now throws Operation aborted. This changed test still expects Planning cancelled, so the cancellation case fails deterministically in exact-head CI. Assert the surviving cancellation contract while retaining the unchanged-file and zero-mutation assertions.
    Confidence: 1
  • [P2] [P2] Update the worker-fence assertion after replacing its source — src/gateway/worker-environments/placement-turn-authority.test.ts:250
    Passing source directly changes which retained data fence rejects the reset case. CI now reports Cloud worker transcript identity is no longer current (source callback: mismatched lifecycleRevision), while the same test still requires the old worker-turn-authority message at line 275. Align the assertion with the replacement fence and keep the checks that the parent lifecycle changes and no child row is created.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Tool execution budget and captured operational authority changes intended behavior with a stated reason (76bf977: Bounded update repair propagated requester and budget currentness to tool effects; this commit extended the existing guard rather than establishing its original introduction.)
  • Plugin invocation source context changes intended behavior with a stated reason (08f4a19: The source context captured the invoking caller separately from factory-time authority; later fix: plugin tools reject active callers that need prepared source facts #196576 prepared those facts so valid plugin calls could pass.)
  • Final host-file authority preparation changes intended behavior with a stated reason (b1a2aa2: Move generation-backed authority preparation off the Gateway thread while retaining final mutation checks; the PR deliberately removes the authority recheck and retains cancellation and rollback.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -308, Tests -562, Other -1. Total -871 across 45 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 26 575 883 -308
Tests 18 132 694 -562
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 45 707 1578 -871

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: Useful internal authority cleanup needs focused test repairs before merging; no urgent production outage is established.
  • add merge-risk: 🚨 compatibility: Plugin invocation authority behavior deliberately changes for operations already in progress; that tradeoff is accepted by the maintainer-authored direction and root policy.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Useful internal authority cleanup needs focused test repairs before merging; no urgent production outage is established.
  • merge-risk: 🚨 compatibility: Plugin invocation authority behavior deliberately changes for operations already in progress; that tradeoff is accepted by the maintainer-authored direction and root policy.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 20, 2026, 10:02 AM ET / 15:02 UTC.

- Retire obsolete mid-flight authority refusal expectations while retaining queued admission checks, cancellation cleanup, process credential revocation, and parent reset fences.
- Check the existing media resource owner after asynchronous reference preflight before handing work to a task.
- Shrink the session-identity allowlist to the remaining source-owner marker.
- Check the invocation abort signal immediately before closing stdin after an awaited write.
- Preserve signal-only cancellation before a provenance callback commits its filesystem write.
@obviyus
obviyus merged commit c23cb9f into main Nov 20, 2026
153 of 154 checks passed
@obviyus
obviyus deleted the refactor/delete-tool-source-guard branch November 20, 2026 15:44
steipete added a commit that referenced this pull request Nov 20, 2026
…202607)

Split Linux retired-tree removal into bounded passes with a serialized quiet interval and react to fresh or ongoing 500 ms btrfs commits. Preserve pending-path custody and the reservation low watermark across resumption. Remove unused spawn-test fixtures left by #202522.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…law#202522)

## Problem

Tool execution captured caller authority and reasserted it after asynchronous preparation and during already-started file, process, plugin, spawn, fetch, and media work. This contradicts the repository's “check authority one time, when work starts” rule. Scoped authority-simplification work requested by Ayaan.

## Fix

- Delete `captureAgentToolSourceExecutionGuard`, its guard-only plugin async context, and its ratchet entry.
- Remove 24 production capture calls plus two calls to the now-deleted adapter capture wrapper.
- Keep tool entry admission with the existing bound-tool owner and keep deferred media admission at actual execution start.
- Unwrap guard-only execution scopes. Preserve filesystem containment, worker/session data fences, explicit cancellation, and borrowed-handle rollback through the existing fs-safe write owner.

## Behavior

An admitted tool invocation can finish after its source authority changes. New work still enters through existing admission owners; explicit cancellation and data/ownership fences remain in force.

Removed obsolete authority-only rejection expectations and retained cancellation, input custody, provenance, and worker-generation coverage. Explicit cancellation regressions cover host write/apply_patch rollback preparation, native workspace writes, and memory append provenance preparation.

Production delta, excluding tests and test support: **+582 / -885 (net -303)**. Most added lines are indentation changes from unwrapping scopes. No new helper, hook, schema, configuration, or error type.

## Evidence

- `git grep captureAgentToolSourceExecutionGuard`: no references remain.
- `pnpm exec oxfmt --write <touched files>`: passed.
- `pnpm exec oxlint <touched files>`: passed.
- No local tests or typechecks run, as requested. GitHub CI is the runtime/typecheck proof.
- Simplified against existing owners; no replacement captured authority helper.
- Addressed failures from CI run 44756051205: removed stale mid-flight refusal and dispatch-shape assertions; preserved explicit Stop, fork cleanup, parent-reset fences, queued channel recovery admission, credential revocation, and later-invocation coverage. Media preflight now rechecks its existing resource owner's open state after reference loading, before task handoff. Lowered the remaining session-identity allowance from two to one.

## Related work

Approved overlap with openclaw#202513 includes the single ratchet entry, guard-only changes in both `src/gateway/server.agent-input-authority*.test.ts` files, and the specifically requested CI repair to `src/gateway/operator-run-recovery.channel.test.ts` (retains queued recovery refusal instead of in-flight I/O revocation). No skipped capture call sites.

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

Split Linux retired-tree removal into bounded passes with a serialized quiet interval and react to fresh or ongoing 500 ms btrfs commits. Preserve pending-path custody and the reservation low watermark across resumption. Remove unused spawn-test fixtures left by openclaw#202522.
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
Release adaptation: extract the independent mixed-requester repair and its queue regression. Stable already strips display/owner flags but copies requester origin and the private owner capability. The wider saved-requester cutover needs the newer fixed-request and Cron occurrence authorities and the durable queue owner; do not replace the stable custody or restart contract.

Companions: #203468 and #203521 are separate selected start-grant repairs. #201334, #201377, #200533 and #202318 are missing full-cutover prerequisites; #203516, #202522 and #202520 are later distinct lifetime refactors, not needed by the isolated mixed-requester repair.

(cherry picked from commit 3ad2cce)

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

Labels

agents Agent runtime and tooling commands Command implementations gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant