Skip to content

fix(agents): private CLI completions lose delivery under restrictive profiles - #158502

Closed
aspalagin wants to merge 3 commits into
openclaw:mainfrom
aspalagin:fix/cli-private-completion-message-tool
Closed

aspalagin wants to merge 3 commits into
openclaw:mainfrom
aspalagin:fix/cli-private-completion-message-tool

Conversation

@aspalagin

@aspalagin aspalagin commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Related: #121661

What Problem This Solves

Fixes: a private subagent result can fail to reach the user when the requester uses a restrictive tool profile such as coding, or a CLI backend that does not retain the full requester tool surface.

User Impact

User impact: a verified private completion can relay its result to the requesting conversation through message, while its final answer stays private. Explicit tool denies, frozen policies, channel action gates, and grant revocation remain authoritative.

An additional completion messaging grant is restricted to sends in the original channel, account, conversation, and thread, and cannot become general messaging authority for spawned children or cron jobs. Existing requester permissions are preserved.

Why This Change Was Made

Current main already restores the normal Claude CLI requester tool surface. The remaining repair uses the explicit privateCompletion flag, carries source restriction independently of automatic final-reply delivery, and keeps the admitted completion allowance through the actual Gateway tool projection. The same policy merge helper preserves explicit denies and frozen allowlists at both stages.

The earlier destination-scope rationale in this PR was incorrect. This revision uses the existing source-reply guard for the additional grant. It also follows the current media contract: #176594 permits source-conversation photos and attachments through normal media validation; this PR does not restore the obsolete text-only restriction.

Integrated main at 650091daacdc10aa374e82a6327e8beffe136072 to resolve the stale branch conflicts and preserve current runtime selection and requester-tool retention.

Evidence

At bed203a26ff9c7aac301f0bff632b97d23895318 (tree 30b8d9d69f3d1a9983b45bc4f12f445b877763dc):

  • Production typecheck passed (tsconfig.core.json).
  • Focused typecheck of all four changed test entrypoints, extending the repository root-test configuration, passed. It caught and fixed the current-main MCP startup API change.
  • Type-aware lint passed for changed production files, tests/support, and the CI inventory; formatting, git diff --check, and the line-cap ratchet passed.
  • The test-line ratchet still reports 51 inherited lines over budget. At the integrated base the measured total is 6,551,687 and the effective ceiling is 6,551,636. This change adds exactly 663 test/support lines and a separate 663-line allocation, preserving that pre-existing difference. No shared baseline increase is included.

The complete Gateway → private parent completion → CLI runner → minted MCP grant → message tool → Telegram transport fixture passed 5/5 in CI job 128116367053. Only model decisions and external Bot API responses are synthetic. CI checked merge 328504c21532c5402858ade03a23c749cf1aa84e, combining this head with main 9651d6347b1ab99453e8e6b5105d10d7800d82dc.

Scenario Verified result
Ordinary private completion Exactly one send containing the child result
Coding profile Exactly one allowed send; other chat/thread and non-send probes rejected
Explicit operator deny No completion message tool or child-result send
Disabled Telegram send action Tool error and zero child-result sends
Revoked grant HTTP 401 and zero child-result sends

The five reported case durations total 122.7 seconds. This expensive composition stays in the release-only tier except for changed-file CI because admission-only tests miss authority lost between projection and dispatch.

The CLI attempt suite, including the new private/coding/other-CLI cases, and MCP grant-context suite also passed. CI lint and all five core test-type stripes passed.

Full CI is red on an unrelated current-main defect: production type checking and some asset-building jobs cannot resolve extensions/deep-research/browser/client.js. The browser directory has identical filenames and blob SHAs in main 9651d634 and the tested merge; both lack that module. This PR does not change those files.

The CI baseline-ratchet job also confirms the same inherited test-line debt on main 9651d634: total 6,552,688, ceiling 6,552,637, over by 51, PR net delta +663. The separate allocation covers exactly the PR's +663; all other ratchets passed.

Local runtime attempts did not start tests: the worker compiler exceeded a 3 GiB cgroup limit, including a retry with a smaller Node heap; a narrow unit selection needed the same compiler and was stopped. The CI run supplies current-head GREEN proof. A fresh full-flow RED control, a real Gemini process, and Telegram Test Server were not run; the older-head live trace is not treated as evidence for this implementation.
Independent Codex source review covered the production and regression changes against 650091daacdc: no actionable findings. This was an independent source review, not an autoreview or ClawSweeper execution. The existing private-delivery owner cases cover suppression of nonempty private final text; the new integration fixture itself returns NO_REPLY.

Simplification retained the existing runtime-selection and policy owners and removed unused photo/document assertions. Against the integrated base: production +38 net lines, regression tests/support +663. The exact 663-line test allocation is justified by the end-to-end authority boundary: admission-only tests miss a grant lost during CLI projection. The expensive integration is release-only except when selected by changed-file CI; the shared test baseline is unchanged.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 agents Agent runtime and tooling size: M labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Preserve a source-bound message allowance for verified private CLI completions under restrictive tool profiles.

Example: A Claude CLI requester using the coding profile receives a private child result for Telegram chat 555000111.

  • Before: The completion lacks message authority and cannot relay the result.
  • After: The completion can send the result to chat 555000111 while its final answer remains private.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful repair with the earlier findings addressed, but an introduced native-session reset blocks correctness and current-head behavior remains unproven.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A private child finishes, but a requester using a restrictive CLI tool profile cannot send its result back to the requesting conversation.
Reason: The remaining delivery failure is concrete and is not covered by the earlier requester-tool restoration.

Merge readiness

⛔ Blocked before merge - 6 items remain

This PR addresses a remaining delivery failure and repairs both previous findings, but its completion-only catalog expansion introduces a CLI session-continuity regression.

Priority: P1
Reviewed head: bed203a26ff9c7aac301f0bff632b97d23895318

Before merge

  • Add real behavior proof - Authority-chain proof required: No runtime result is supplied for bed203a. Demonstrate coding-profile private delivery through Gateway → CLI → minted MCP grant → message → transport, rejection of another conversation/thread and non-send actions, and zero effects after revocation or requester-lineage reassignment. Establish that child and automation creation cannot inherit the additional message authority. The retained fixture is useful source coverage but has not run on this revision; the contributor explicitly excludes earlier-head traces. Provide redacted logs or terminal output, removing IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Keep the message catalog stable across private completion turns (P1) - With tools.profile=coding and ordinary automatic delivery, the requester catalog excludes message. A private completion sets sourceReplyOnly and completionMessageAllow, and this map adds message even to the session-scope catalog used by resolveTurnToolSurface. CLI preparation hashes those projected names; resolveCliSessionReuse then invalidates the existing native binding when the completion adds message, and again when the next ordinary turn removes it. This recreates the parent-context/plan loss fixed in fix(agents): keep CLI completion tool catalogs stable #176892. Keep a stable definition surface across these turns and apply the additional source-bound authority through the existing execution gate; cover native-session reuse, not only successful sending.
  • Resolve security review attention item - No concrete authorization bypass was found, but the expanded grant needs final-effect containment evidence and the enforced current-head maintainer approval.
  • Resolve merge risk - The contributor must establish that the added messaging allowance remains contained at final effects, including after requester-lineage reassignment and through child or automation creation.
  • Await maintainer action - A maintainer must approve the final current revision through the enforced security-sensitive review gate.
  • Explain or restore the original intent of Stable CLI completion catalogs - 335b425: Different completion catalogs invalidated native sessions and lost the parent plan; definitions must stay stable while execution authority changes.

Findings

  • [P1] Keep the message catalog stable across private completion turns — src/gateway/tool-resolution.ts:662-665

Provenance

  • Stable CLI completion catalogs changes intended behavior without addressing why it exists (335b425: Different completion catalogs invalidated native sessions and lost the parent plan; definitions must stay stable while execution authority changes.)

Tests

  • Low-value test src/agents/cli-runner/mcp-grant-context.test.ts: Remove the added field-copy test: it asserts the helper's projection directly, while the retained Gateway/MCP fixture covers loss of source authority at the actual boundary.
  • Missing end-to-end proof: Supply current-head restrictive-profile delivery and forbidden-effect evidence, plus ordinary → private completion → ordinary native-session continuity and a regression shown red on the base and green on the repair.
Agent review details

How this fits together

The command attempt verifies a child-completion handoff, projects requester policy into a CLI MCP grant, and exposes message execution through the Gateway to the channel transport.

flowchart LR
  A[Private child result] --> B[Verified requester handoff]
  B --> C[Command tool policy]
  C --> D[CLI MCP grant]
  D --> E[Gateway tool projection]
  E --> F[Source reply guard]
  F --> G[Telegram transport]
Loading

Technical review

Best possible solution:

Keep the existing completion and message-policy owners, but expose a stable session catalog and gate the additional source-bound message permission at execution.

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

Current-main source shows private automatic completions missing the message allowance under coding; no current-head runtime reproduction is supplied.

Is this the best way to solve the issue?

Reusing the existing source guard and policy merger is appropriate, but changing the completion catalog violates the established CLI continuity contract.

Full review comments:

  • [P1] Keep the message catalog stable across private completion turns — src/gateway/tool-resolution.ts:662-665
    With tools.profile=coding and ordinary automatic delivery, the requester catalog excludes message. A private completion sets sourceReplyOnly and completionMessageAllow, and this map adds message even to the session-scope catalog used by resolveTurnToolSurface. CLI preparation hashes those projected names; resolveCliSessionReuse then invalidates the existing native binding when the completion adds message, and again when the next ordinary turn removes it. This recreates the parent-context/plan loss fixed in fix(agents): keep CLI completion tool catalogs stable #176892. Keep a stable definition surface across these turns and apply the additional source-bound authority through the existing execution gate; cover native-session reuse, not only successful sending.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Preserve continuity and verify containment (recommended)
    The contributor should keep the catalog identical across ordinary and private completion turns, retain execution-time source restrictions, and demonstrate allowed and forbidden final effects.
  2. Pause the allowance expansion
    Keep the existing bounded requester restoration until the source-bound allowance can preserve native continuity and demonstrate containment.

Provenance checked

  • Bounded CLI requester-tool restoration keeps the original intent (72f5840: Restore verified automatic Claude CLI completion tools through MCP while preserving captured requester authority.)
  • Completion source media keeps the original intent (7f73804: Permit photos and attachments through normal media validation while retaining channel, account, conversation, thread, and send-action locks.)
  • Shared allowance merger keeps the original intent (3b1460a: Share policy projection across runtimes; later frozen-template handling preserves immutable allowlists.)

Testing

Proof path: none.

Security

Needs attention: No concrete authorization bypass was found, but the expanded grant needs final-effect containment evidence and the enforced current-head maintainer approval.

Evidence

What I checked:

PR surface

Source +38, Tests +664, Docs +7, Other +2. Total +711 across 15 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 6 72 34 +38
Tests 6 667 3 +664
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 2 2 0 +2
Total 15 748 37 +711

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.

Review metrics

Metric Value Why it matters
Production versus regression growth Production +38 net lines; tests/support +663 net lines Production reuses existing owners; the larger fixture exercises grant projection through the Gateway and real Telegram transport client rather than admission alone.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Private delegated results can disappear, and the introduced catalog change can reset the requester's native CLI session.
  • merge-risk: 🚨 session-state: Adding message only on completion changes the tool hash used to retain native conversation continuity.
  • merge-risk: 🚨 security-boundary: The patch extends restrictive allowlists with authority that must remain limited to the original source and must not become descendant authority.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-26T00:58:38.753Z sha 904ddf78bd9116fc8242c6225f2cca5acac30498 :: blocked before merge. :: none
  • reviewed 2026-09-30T08:45:29.267Z sha dd2ed04 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-01T08:43:03.481Z sha 5b18b47 :: needs real behavior proof before merge. :: [P1] Preserve the source-reply restriction on private CLI grants | [P2] Carry the completion allowance through CLI policy projection

Reviewed November 6, 2026, 2:54 PM ET / 19:54 UTC (Revision 4).

A completionTarget "parent" handoff runs with delivery disabled, so the
requester's final reply stays internal and any user-facing update has to
go through the message tool. CLI requesters never retain their tool
surface on a completion handoff and ran tool-free, so the result could
not reach the user.

Grant the same policy-checked message capability used by
message-tool-only handoffs to trusted private completions on CLI
runtimes. Announce delivery, embedded runtimes, and policy denies are
unchanged.

The grant needs the CLI runtime decision earlier in runAgentAttempt; the
unchanged selection moves into attempt-cli-runtime.ts so the over-cap
attempt-execution.ts does not grow.
@aspalagin
aspalagin force-pushed the fix/cli-private-completion-message-tool branch from 904ddf7 to dd2ed04 Compare September 30, 2026 08:37
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Sep 30, 2026
…ndary

Drive a hidden child with completionTarget "parent" through the real
Gateway, CLI runner, MCP loopback grant, message tool, and Telegram
transport. A protocol child stands in for Claude and calls the MCP
endpoint the runner generated; a fixture Bot API records the final sends.

An allowed private completion lists exactly `message` and sends once to
the requester chat. An operator deny runs the turn without MCP, a
disabled Telegram send action returns a tool error, and a grant revoked
between listing and calling gets HTTP 401; none of them reaches Telegram.

The test needs the host SQLite broker and is release-only, so CI runs it
when it changes instead of on every pull request.
Integrate current main, retain existing requester permissions, and carry a source-bound completion message allowance through CLI projection. Keep the extra grant out of child and cron inheritance.
@aspalagin aspalagin changed the title fix(agents): private subagent results are lost when the requester runs on a CLI backend fix(agents): private CLI completions lose delivery under restrictive profiles Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated to bed203a26ff9c7aac301f0bff632b97d23895318 on current main. The additional private CLI message grant now carries the existing source restriction through coding-profile projection and cannot be inherited by children or cron. The PR body describes the current requester/media contracts, passing local static checks, the inherited 51-line test-budget debt, and runtime proof still pending in CI.

@clawsweeper

clawsweeper Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

This external contributor PR changes sensitive security components. A maintainer must review these changes before merging.

Current SHA: bed203a26ff9c7aac301f0bff632b97d23895318

These sensitive security changes were made:

  • src/agents/conversation-tool-policy-pipeline.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

After reviewing the changes, post a new PR comment containing only approval commands, each on its own line:

/allow-security-sensitive-change

A later push requires a fresh approval comment.

@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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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 6, 2026
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the detailed work and the field data in #121661. I'm closing this PR without merging, because the user-facing loss does not reproduce on current main.

I ran this end to end on main (77a0a8426513). The setup was a Telegram Test Server DM, an isolated Gateway, and the claude-cli runtime with real Claude Code (Haiku 5.5). I also set tools.profile: "coding", the restrictive case this PR targets. The user asked the agent to spawn a subagent with completionTarget: "parent", yield, and report the result. The subagent registry recorded completionTarget: "parent". In two runs, the DM received The subagent returned exactly: PLUM-42 (78 s and 116 s). There was no tool-free completion turn and no lost result.

The loss reported in the issue (CLI completion turns ran tool-free, so private results never arrived) was fixed by #162374, which keeps the requester's tools on Claude CLI completion turns. The case that remains is a private completion without a yield, where the requester's own profile has no message tool. This applies to every runtime, not only CLI backends. It also widens messaging authority beyond the configured profile, so it would need its own product decision and a real report. It should not be added as a CLI-only grant.

@obviyus obviyus closed this Nov 13, 2026
@aspalagin

Copy link
Copy Markdown
Contributor Author

Thanks, @obviyus, for taking the time to test this end to end and for the clear explanation. The distinction between restoring the requester’s existing tools and granting additional messaging authority makes sense. With #162374 addressing the original tool-free completion issue, closing this PR is the right call. I appreciate the careful verification and scope clarification!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts security-review-required security-sensitive-changed size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants