Repository navigation
fix(agents): preserve tool restrictions across session sends - #144269
pgondhi987 wants to merge 15 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 16, 2026, 3:13 AM ET / 07:13 UTC (Revision 13). ClawSweeper reviewWhat this changesPreserves a sender’s tool restrictions across delegated session turns, follow-ups, workers, and mediated CLI tools, and rejects handoffs or recovery that cannot enforce them. Merge readiness⛔ Blocked before merge - 3 items remain This PR remains necessary: current main lacks the sender-cap handoff. The recovery finding is resolved, the resume-carrier follow-up is sound, and the supplied boundary proof is sufficient. No new actionable defect was found. Priority: P0 Review scores
Verification
How this fits togetherSession sends let one OpenClaw agent request work in another session. The Gateway admits that work, assembles its permitted tools, and manages replies, cancellation, and restart recovery. flowchart TD
A[Sender's permitted tools] --> B[Capture exact tool cap]
B --> C[Gateway admission]
D[Target policy and live authority] --> C
C --> E{Can restrictions be enforced?}
E -->|Yes| F[Restricted delegated turn]
E -->|No| G[Visible rejection]
F --> H[Guarded tools and follow-ups]
Decision needed
Why: The proof establishes enforcement, but accepting interruptions to existing delegation and recovery workflows requires owner judgment. Before merge
Agent review detailsSecurityNone. PR surfaceSource +524, Tests +1583, Docs +4. Total +2111 across 52 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one exact, transient sender cap across supported adapters, with owner-approved visible rejection and recovery guidance wherever enforcement is unavailable. Do we have a high-confidence way to reproduce the issue? Yes, there is a high-confidence source-backed path: a restricted sender delegates to a broader target, while current main lacks the exact-cap handoff. Supplied boundary fixtures exercise this mechanism; this review did not execute target code. Is this the best way to solve the issue? Yes, the transient cap and existing admission owners provide a coherent repair without changing persistent target policy; the intentional unsupported-path failures still require acceptance. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 25ae7a5b5377. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
|
@clawsweeper re-review The PR now resolves the current |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review The PR now resolves the current |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review The PR now resolves the current |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
vincentkoc
left a comment
There was a problem hiding this comment.
Secops review found two fail-open authority paths; changes required.
src/agents/main-session-recovery/main-session-restart-recovery-store.tsassignsforceRestartSafeTools: truewhen transcript/provenance recovery throws. That tool set includes read, so restart can resurrect a delegated run whose source cap denied read.src/agents/embedded-agent-runner/runs.tstreats a missing operational caller instance as sufficient closure evidence when a requester cap exists. A copied cap must not survive closure without authoritative live identity.
Keep every absent, corrupt, or stale authority input fail-closed. Split this into sender cap capture/intersection, transport adoption, closure-bound active/detached authority, and restart recovery. At 52 files and multiple lifecycle boundaries, this head is not landable.
|
Split into the narrower security stack:
Both replacements credit @pgondhi987 for the original diagnosis and implementation context. The rewrite deliberately omits the broad compatibility, detached-continuation, and active-queue machinery: unsupported handoffs fail closed instead of carrying bearer-like authority or preserving restart-safe tools that may exceed the sender cap. |
What Problem This Solves
Delegated agent work could regain tools that had already been removed from the sending turn when a message crossed session, scheduled-run, worker, or mediated CLI/MCP boundaries. A receiving turn could therefore exceed the sender's current tool restrictions.
Why This Change Was Made
The sender's final exact-name tool restriction is captured in host-owned context and intersected with the receiver's own policy at admission. The restriction follows fresh turns, scheduled fallback, chained sends, direct command paths, workers, and mediated CLI/MCP grants without modifying the target session's persistent policy. Host-bound execution tools remain available at their source but are excluded from transferable session, child, and scheduled-run authority. Detached follow-ups retain both source-run and individual-request cancellation.
Active or out-of-process targets whose compatible authority cannot be proven fail closed with retry guidance. If a Gateway restart discards the process-bound exact cap, recovery pages backward through durable source provenance and stops delegated work before constructing tools instead of substituting the target's generic recovery catalog. If transcript or provenance inspection itself fails while replaying a pending final, recovery now retains the established restart-safe tool fence instead of clearing it.
User Impact
Delegated turns can no longer gain tools unavailable to their caller. Allowed delegation continues to work, receiver-side restrictions still narrow the result, and incompatible active targets return an actionable error instead of accepting an unrestricted handoff. A delegated turn interrupted by a Gateway restart now fails visibly when its exact sender cap cannot be reconstructed; direct-user and completion-only recovery retain their existing behavior. A pending-final recovery whose transcript cannot be inspected continues only with restart-safe tools. No config, schema, dependency, or protocol changes are introduced.
Evidence
Validated on Linux with Node v24.20.0 at exact head
c898d7da78c10f77ce1411ed3c315754c380a538, after mergingmainat29ed7e3b810a3b62fd9e5b5778e1db02fc8266a3.node scripts/run-vitest.mjs src/agents/main-session-recovery/main-session-restart-recovery.test.ts src/agents/tools/in-process-gateway.test.ts src/agents/cli-runner/prepare.test.ts src/agents/embedded-agent-runner/run/attempt-bundle-tools.test.ts src/gateway/server.sessions-send.test.ts src/gateway/tool-resolution.exclude.test.ts— 534/534 tests passed across recovery, CLI preparation, embedded tool policy, in-process Gateway transport, real Gateway session-send, and Gateway tool projection.readtool, read a real allowed file, persist the safe-tool marker, and leave the forbidden effect file absent. The no-failure unrestricted control reaches the same realwritesink and creates the expected file.pnpm tsgo:coreand the canonical selectedagents-otherandagents-toolstest-type graphs passed.pnpm tsgo:core, focused lint/format, and the 32-casesessions-send-tool.a2a.test.tssuite pass.mainstores task-resume authority in a process-private carrier. The mergedsessions_sendcancellation wrapper now preserves that carrier when copying a request to attach its signal. The exact failing CI file was reproduced at 3 failures before the fix and passes 6/6 after it; the four-file aggregate covering task resume, Gateway session send, requester policy, and in-process dispatch passes 65/65. Core types, the canonical Gateway test-type graph, focused lint/format, and diff checks also pass at the exact head.This recovery proof enters through the production restart-recovery store and dispatch seam, creates a real admitted run, performs real embedded tool preparation, and exercises concrete filesystem
readandwritetools. It intentionally does not claim to reconstruct a lost exact delegated cap: when provenance is unreadable, it proves the conservative restart-safe catalog prevents broader mutation authority. Successful empty or missing transcript reads retain the existing unrestricted direct-recovery contract.The prior exact-head integration proof at
ffe945cdd6be6927af39e5b67d2f110405091fberemains relevant to unchanged session-send boundaries:node scripts/run-vitest.mjs src/gateway/server.sessions-send.test.ts src/gateway/client-callsites.guard.test.ts— 24/24 passed across the full 23-case Gateway suite and the unchanged production-callsite guard.execremains available at its source but is absent after delegation; an unrelated transferablewriteremains available, and the generic-exec control produces both expected files.Sanitized observed output from that retained integration proof:
This is focused local adapter and integration proof. The command/model seams are deterministic, while admission, recovery dispatch, continuation authority, policy projection, tool preparation, exec/write implementations, node command handling, local WebSocket transport, process I/O, and filesystem sinks are real. It does not claim an external physical-node, live-provider, or external-channel test. Exact-head CI is running.
Before Merge
Maintainer acceptance is still needed for the intentional fail-closed behavior on unsupported handoffs and delegated restart recovery. The older overlapping implementation in #125844 is closed unmerged, so no consolidation action remains for this PR.