Skip to content

fix(agents): keep sender-scoped tools in delegated runs - #110345

Merged
joshavant merged 7 commits into
mainfrom
fix/109025-delegated-tool-policy
Jul 21, 2026
Merged

joshavant merged 7 commits into
mainfrom
fix/109025-delegated-tool-policy

Conversation

@joshavant

@joshavant joshavant commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #109025

Alternative implementation to #109055.

AI-assisted: yes. I understand the authorization lineage and tool-policy changes in this PR.

What Problem This Solves

Fixes an issue where users with an exact toolsBySender override could successfully use tools in the inbound parent run, but a spawned sender-less subagent would re-resolve the wildcard sender rule and silently lose filesystem/runtime tools.

The same context loss could affect trusted internal completion fallback, and separate tool-discovery consumers could otherwise disagree about the effective requester policy.

Why This Change Was Made

This change centralizes requester tool-policy resolution. External requests resolve current global/group/sender policy normally. Verified internal descendants consume the stored effective requester projection, then intersect it with current agent, sandbox, profile, and subagent restrictions.

Delegation is accepted only from persisted spawned lineage or the private subagent-completion handoff with matching provenance. A new external sender targeting an existing child re-resolves sender policy, forged child-shaped keys fail closed, empty inherited projections remain meaningful, and the same rule now feeds conversation tools, Gateway/node tool resolution, web search, skill dispatch, compaction, and the Codex dynamic-tool surface.

Unlike a spawn-only propagation path, this also covers requester-agent fallback without copying or synthesizing public sender identity.

User Impact

Delegated agents retain the tool authority of the external request that created them, subject to all ordinary child restrictions. Anonymous or newly external requests do not inherit that authority.

Evidence

  • Live A/B on Blacksmith Testbox tbx_01kxshsbhgk1z0jt6ytw8rcc47, real Gateway + qa-channel + openai/gpt-5.4: Actions run
    • Fix commit 859fdd3b7f1: scenario issue-109025-sender-policy-live passed; the parent wrote its proof, spawned a real child, and the child read the unpredictable marker.
    • Exact pre-fix parent 75e4103c57382ddbf16aab1aed8a6e72cfb39951: the same scenario failed with parentProof=PARENT_OK, childTools={}, and no marker returned (reproduced issue 109025).
  • Full changed-surface gate passed on Testbox: typecheck, lint, formatting, import cycles, dependency and plugin-boundary guards. Actions run
  • Focused Vitest coverage passed for requester policy, conversation capability profile, subagent announce delivery, Gateway plugin dispatch, Gateway tool resolution, skill dispatch, Codex dynamic tools, and embedded attempt tooling.
  • $autoreview --mode uncommitted completed cleanly with no accepted/actionable findings.

Authorization boundary review

Maintainer decision: senderless authenticated operator calls to a valid persisted child session are trusted resumptions inside the Gateway trusted-operator domain.

  • Persisted lineage is authority-bearing only when the stored child envelope includes spawnedBy plus valid subagent metadata. Lineage and inherited-tool mutations through sessions.patch require operator.admin.
  • The inherited sender projection is a spawn-time snapshot. Later toolsBySender edits are intentionally non-retroactive for that child, while current global, agent, provider, sandbox, and subagent restrictions continue to apply.
  • A new external channel turn targeting an existing child re-resolves current sender policy. Sender identity and external_user provenance each independently force that path.
  • Completion continuation additionally requires private in-process client metadata, inter_session + subagent_announce provenance, a source session, and a matching persisted lineage chain.
  • Resolution records current-request, persisted-child, or completion-handoff for diagnostics.

Direct sibling Codex inspection completed at openai/codex@e98765c212d: thread_processor.rs validates and passes the client-supplied dynamic-tool list into thread startup, while dynamic_tools.rs relays tool responses. Codex does not reconstruct OpenClaw sender policy; OpenClaw owns authorization before supplying dynamicTools.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling extensions: qa-lab extensions: codex size: XL maintainer Maintainer-authored PR labels Jul 18, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 20, 2026, 2:45 AM ET / 06:45 UTC.

Summary
The branch centralizes requester-scoped tool-policy resolution so verified delegated children and private completion handoffs retain the spawning request’s effective sender policy while external turns re-resolve current sender policy.

PR surface: Source +269, Tests +613, Docs +1, Other +273. Total +1156 across 43 files.

Reproducibility: yes. the supplied configuration, delegated-run sequence, and live pre-fix versus post-fix Gateway evidence form a high-confidence reproduction path; this read-only review did not independently execute it against current main.

Review metrics: 1 noteworthy metric.

  • Persisted authorization metadata: 1 immutable session field added. completionOwnerSessionKey participates in durable completion authorization and therefore needs explicit upgrade and security-boundary review.

Stored data model
Persistent data-model change detected: serialized state: packages/gateway-protocol/src/schema/sessions.ts, serialized state: src/agents/conversation-capability-profile.test.ts, serialized state: src/agents/requester-tool-policy.ts, serialized state: src/config/sessions/types.ts, serialized state: src/gateway/sessions-patch.test.ts, serialized state: src/gateway/sessions-patch.ts, and 3 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #109025
Summary: This PR is the viable candidate fix for the canonical sender-scoped subagent authorization bug; the earlier alternative PR was closed unmerged, and the reply-session PR concerns a distinct failure mode.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Obtain explicit authorization-owner approval for the trusted operator-resume and non-retroactive sender-policy snapshot semantics.

Risk before merge

  • [P1] Merging intentionally makes a stored spawn-time requester-policy projection authority-bearing for validated child and completion paths; maintainers must explicitly accept the non-retroactive policy-snapshot semantics for authenticated operator resumes.
  • [P1] The new immutable completion-owner session metadata is persisted state used in authorization decisions, so fresh and upgraded session behavior needs owner review even though the branch includes focused tests and live proof.

Maintainer options:

  1. Confirm trusted-resume semantics before merge (recommended)
    Have an authorization owner explicitly approve the persisted child-policy snapshot, its non-retroactive behavior, and the external-turn re-resolution boundary.
  2. Adopt a live-policy model instead
    If current toolsBySender edits must affect existing children immediately, redesign the continuation contract around a validated current requester identity rather than a stored projection.

Next step before merge

  • [P2] No narrow mechanical repair is indicated; the remaining merge blocker is a maintainer decision on the intended authorization and upgrade contract.

Maintainer decision needed

  • Question: Should authenticated operator resumes of a persisted child session retain the spawn-time requester sender-policy snapshot, including after later toolsBySender edits, when the stored lineage and completion provenance validate?
  • Rationale: The branch makes a deliberate authorization and compatibility choice rather than a purely mechanical bug repair: persisted child metadata becomes a source of effective tool authority for senderless internal continuations.
  • Likely owner: nicknmorty — The available context ties this contributor to the real completion-handoff behavior and its authorization-sensitive diagnostic boundary, though repository ownership could not be established from the supplied history.
  • Options:
    • Approve the documented snapshot contract: Accept the validated persisted-child and completion-handoff model, with external sender turns continuing to re-resolve current sender policy.
    • Pause for authorization-owner decision (recommended): Do not merge until an owner explicitly confirms whether trusted operator resumes may retain the non-retroactive sender-policy snapshot.
    • Require live-policy re-resolution: Change internal resumes to re-resolve current policy, accepting that senderless continuations need a different authorized identity model.

Security
Needs attention: No concrete bypass is established by the supplied evidence, but the diff deliberately changes a persisted authorization boundary and needs explicit owner acceptance before merge.

Review details

Best possible solution:

Keep one canonical requester-policy resolver, retain external-turn re-resolution and strict lineage/provenance validation, and merge only after an authorization owner explicitly accepts the trusted operator-resume and policy-snapshot contract.

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

Yes, the supplied configuration, delegated-run sequence, and live pre-fix versus post-fix Gateway evidence form a high-confidence reproduction path; this read-only review did not independently execute it against current main.

Is this the best way to solve the issue?

Yes, centralizing requester-policy resolution is the most maintainable shape because the same effective policy feeds conversation, Gateway, skill, web-search, compaction, and Codex tool surfaces; the remaining question is whether the persisted trusted-resume contract is the intended product boundary.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against e2e394e1ab80.

Label changes

Label changes:

  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (linked_artifact): The PR supplies a real Gateway plus qa-channel live A/B with an unpredictable child-read marker, and a separate stable-release report corroborates the completion-handoff symptom.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: The patch addresses a reproducible delegated-agent workflow failure that strips tools from configured users' child or completion runs.
  • merge-risk: 🚨 compatibility: Existing children intentionally retain a spawn-time sender-policy snapshot after later toolsBySender changes, altering upgrade-time policy behavior.
  • merge-risk: 🚨 security-boundary: Persisted lineage and a private handoff flag decide when senderless runs may consume inherited tool authority.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (linked_artifact): The PR supplies a real Gateway plus qa-channel live A/B with an unpredictable child-read marker, and a separate stable-release report corroborates the completion-handoff symptom.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies a real Gateway plus qa-channel live A/B with an unpredictable child-read marker, and a separate stable-release report corroborates the completion-handoff symptom.
Evidence reviewed

PR surface:

Source +269, Tests +613, Docs +1, Other +273. Total +1156 across 43 files.

View PR surface stats
Area Files Added Removed Net
Source 30 443 174 +269
Tests 10 613 0 +613
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 2 273 0 +273
Total 43 1330 174 +1156

Security concerns:

  • [medium] Confirm trusted-resume authorization boundary — src/agents/requester-tool-policy.ts:1
    Persisted child lineage and completion-owner metadata now decide when a senderless continuation may use the spawning requester's policy snapshot; this is intentional but requires an explicit authorization-owner decision.
    Confidence: 0.9

What I checked:

  • Canonical requester-policy resolution: The new resolver distinguishes current-request, persisted-child, and completion-handoff sources, replacing separate sender-policy resolution paths with a common decision surface. (src/agents/requester-tool-policy.ts:1, 9e4269bd8812)
  • Trusted handoff gate: The Gateway derives the trusted-handoff flag only from internal client metadata plus inter-session subagent-announce provenance before passing it into the agent run. (src/gateway/server-methods/agent-run-execution-phase.ts:276, 9e4269bd8812)
  • Persisted authorization metadata: The branch adds an immutable completion-owner session key to session patching, which makes the completion routing and authority relationship durable across runs. (src/gateway/sessions-patch.ts:205, 9e4269bd8812)
  • Real behavior proof: The PR body supplies a live Gateway plus qa-channel A/B: the pre-fix parent lost tools in the delegated run, while the patched run completed a child filesystem read. A related stable-release field report independently describes the same completion-handoff symptom. (9e4269bd8812)
  • Related canonical bug: The PR is an implementation candidate for the still-open report describing exact toolsBySender overrides being replaced by the wildcard policy in senderless subagent and completion runs. (src/agents/conversation-capability-profile.ts:1, 9e4269bd8812)

Likely related people:

  • nicknmorty: Provided detailed stable-release field evidence for the inactive-requester completion path and connected it to the requester-policy problem rather than the distinct reply-session initialization issue. (role: related diagnostic contributor; confidence: low; files: src/agents/subagent-announce-delivery.ts, src/agents/conversation-capability-profile.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (5 earlier review cycles)
  • reviewed 2026-07-18T02:55:33.515Z sha 859fdd3 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T07:56:27.410Z sha 7420e61 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T08:41:21.631Z sha a5700be :: needs maintainer review before merge. :: none
  • reviewed 2026-07-20T02:01:40.390Z sha 832dd6a :: needs maintainer review before merge. :: none
  • reviewed 2026-07-20T03:07:03.686Z sha 16e72d2 :: needs maintainer review before merge. :: none

@nicknmorty

Copy link
Copy Markdown
Contributor

Additional live field confirmation for #109025 on stable OpenClaw 2026.7.1 (2d2ddc4), headless Linux Gateway, Telegram group topic.

  • Configuration shape: the owner's exact toolsBySender entry is unrestricted; the wildcard entry denies exec, process, nodes, and gateway.
  • Direct owner-authored turns consistently cataloged 37 tools.
  • When a background child completed after the requester turn had ended, the resulting announce:v1 requester-agent continuation cataloged only 32–33 tools. Attempts to call openclaw:core:exec then returned Unknown tool id.
  • The next direct human message immediately restored the 37-tool catalog in the same session and on the same model. Six distinct user-observed episodes followed this pattern during the working period.
  • Source/log correlation matches the reported root: sendSubagentAnnounceDirectly dispatches the internal agent continuation with subagent_announce provenance but without the original sender identity, so sender-policy resolution falls through to the wildcard rule before the provider request is made.
  • This was especially visible with an Anthropic Fable parent because that workflow was explicitly delegation-heavy and then resumed with exec for QA/commit work. In the last 60 Developer root transcripts, all 65 actual sessions_spawn calls came from Fable and none from GPT; the recent GPT turns therefore did not exercise the same completion path and normally used Codex-native bash rather than OpenClaw exec.

This confirms the inactive-requester completion-fallback half of #109025 on the current stable release and supports the cross-surface requester-policy approach in this PR. It is distinct from the reply-session initialization/CAS wedge tracked by #101920.

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Jul 20, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 20, 2026
@joshavant
joshavant force-pushed the fix/109025-delegated-tool-policy branch from 832dd6a to 16e72d2 Compare July 20, 2026 03:02
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Jul 20, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 20, 2026
@joshavant
joshavant force-pushed the fix/109025-delegated-tool-policy branch from 9e4269b to 7f6c2a6 Compare July 20, 2026 20:59
@joshavant
joshavant merged commit 3372088 into main Jul 21, 2026
118 checks passed
@joshavant
joshavant deleted the fix/109025-delegated-tool-policy branch July 21, 2026 00:42
@joshavant

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 21, 2026
)

* fix(agents): preserve requester policy across delegation

* fix(agents): keep policy types internal

* test(codex): cover delegated policy forwarding

* fix(agents): harden delegated policy contract

* fix(agents): preserve split-owner completion policy

* fix: version delegated requester snapshots

* fix: refresh delegated policy protocol artifacts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation extensions: codex extensions: qa-lab gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

[Bug]: Subagent loses sender-scoped tool authorization

3 participants