Skip to content

fix(auto-reply): exec completions keep the requester's current sender and DM tool policy - #190472

Open
amittell wants to merge 15 commits into
openclaw:mainfrom
amittell:fix/177510-completion-turn-reauthorize
Open

amittell wants to merge 15 commits into
openclaw:mainfrom
amittell:fix/177510-completion-turn-reauthorize

Conversation

@amittell

@amittell amittell commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #177510

What Problem This Solves

Fixes: a background command's completion turn loses exec and process when the sender who started it is allowed only by their own toolsBySender entry and the "*" entry denies those tools.

User Impact

User impact: with a toolsBySender wildcard deny, a sender allowed by their own entry can let a background command finish its task on the completion turn, without sending another message. Guests stay denied, and changing that sender's entry, or denying the tool for the conversation they wrote in (a Telegram DM entry under channels.telegram.direct.<chat>, including toolsBySender keyed on their id, username or name, or a Discord guild or channel entry under channels.discord.guilds.<guild>), before the completion runs takes the tool away.

Why This Change Was Made

A completion turn is built without a sender, so requester policy fell to the "*" entry. #185476 restored the sender only for command owners (commands.ownerAllowFrom); a sender allowed only through toolsBySender was never restored.

My first revisions restored too little. Review found four real gaps, all fixed:

  • Without the conversation id, resolveRequesterConversationToolPolicy skips the channel's security.resolveDirectToolPolicy, so an unchanged sender entry escaped a DM-level deny. fix: background command completions lose the owner's owner-only tools #185476's owner completions had the same gap.
  • Without the sender's username and name, Telegram's resolveTelegramDirectToolPolicy missed a DM toolsBySender entry keyed username: or name:, fell back to the DM's unrestricted tools, and the requester's global id entry then allowed exec.
  • Without the requester's group space and channel name, a completion in a Discord guild channel resolved group policy with no guild, so resolveDiscordGuildKey found no guild entry, a guild or channel deny added after launch was missed, and the requester's global id entry allowed exec.
  • combineSessionEventTargetsForHost compared only command-owner requesters, so targets from two toolsBySender-only requesters could share a batch that restores only the first one.

What the PR does now:

  • The session-event target keeps the requester's channel, account, sender id, E164, username, display name, group space (a Discord guild), group channel name, chat type and conversation id, taken from the host-owned tool caller. The group id comes from the completion's own route, which is the requester's conversation.
  • The completion turn restores SenderId, SenderE164, SenderUsername, SenderName, GroupSpace, GroupChannel and ChatId, but only on the requester's own channel account and only when the turn has the requester's conversation type. A completion routed to another chat stays senderless and gets the "*" policy.
  • The restore grants nothing by itself: a non-owner's senderIsOwner stays false, and owner-only effects still recheck at use.
  • A batch refuses targets whose retained requester differs in any of those fields.
  • Only exec completions and node system.run events retain a requester. Subagent announces, cron, heartbeats, session-state notices and adopted durable processes do not, so their authority is unchanged.
  • Behavior change for fix: background command completions lose the owner's owner-only tools #185476: an owner's sender is restored only when the chat types match; before, a matching channel and account was enough. Where they differ, the owner-effect check now fails closed.

Evidence

Merged with main (head 283e19cf875, main eee7a1bd526, macOS arm64, Node 26.12.1, OPENCLAW_VITEST_RUNTIME=node). The branch was 3,114 commits behind. 9038986bf5e resolves three conflicts:

  • session-event-context.ts: main's command-owner restore (now const { authority, requester } = commandOwner, with channelPrincipal), then this PR's retained-requester restore of SenderId, SenderE164, SenderName, SenderUsername, GroupSpace, GroupChannel and ChatId under the same channel, account and chat-type match. Main's own SenderId/SenderE164 restore is dropped; the retained requester covers it.
  • session-event-target.ts: main's ownerContinuation flag, which main now also sets for an operator source, then this PR's retainedRequester capture.
  • mock-openai-owner-completion.ts: main's answeredAfter helper with this PR's latest(...) lookups.

Main's #204105 (cb1d8cdea3e) dropped the mid-run operator re-checks in session events: a completion turn's authority is decided when it starts, and a revocation applies to the next start. 283e19cf875 aligns the two "revoked after admission" rows of session-event-completion-reauthorize.test.ts with that. The admitted completion now keeps the exec it was given and runs it; before, its tool host was retired before the call (agent harness host capability is no longer active). The guest row, the guild rows and every "before admission" row are unchanged. A revocation between launch and the completion's start still takes the tool away, which the QA flow checks.

Main also reworded the refusal: a denied tool now reads exec is outside the tools this run allows. Do not retry exec. where this description quotes exec is not available in this turn and Unknown tool id: exec.

  • QA Lab exec-completion-requester-sender-policy (host runner, mock-openai, qa-channel): passes 1/1. The allowed sender's completion runs exec (ran: true, same Gateway pid). The guest gets exec is outside the tools this run allows. Do not retry exec. at launch. Revoking the third sender's entry after launch leaves its completion with the same refusal and no marker. With main's session-event-context.ts and session-event-target.ts it fails: allowed requester's completion did not run exec: {"job":"allowed-8d47450a","launched":true,"ran":false,...}.
  • fix: background command completions lose the owner's owner-only tools #185476's exec-completion-owner-authority fails at "guest completion is refused" on this merge and on bare main eee7a1bd526 alike. The guest's completion is refused and nothing is persisted, but the refusal now reads automations is outside the tools this run allows. Do not retry automations., which the scenario's accepted list (needs the owner's authority, Unknown tool id: automations) predates. The owner step passes on both. The failure comes from main: the scenario predates main's own refusal wording.
  • The 9 session-event* test files: 171 passed, 0 failed (session-event-completion-reauthorize 13, session-event-handoff 22). With main's session-event-context.ts and session-event-target.ts and the rest of this head kept, session-event-completion-reauthorize.test.ts fails 5 of 13. Main offers no exec to the allowed owner's completion in a Telegram DM, in a Discord guild channel or in either after-admission row (outcome: "absent"), and in "command owner, DM revoked before admission" it offers and runs exec. session-event-handoff.test.ts fails 1 of 22 there: "batches retained owner authority only for the same requester" batches the guest's event with the 4 events the test keeps apart (otherGuest, otherGuild, ownerElsewhere, renamed).
  • Static checks on the merge, with --base eee7a1bd526 where a check takes one: tsgo:core, tsgo:extensions and check:test-types 0 errors; oxlint and oxfmt --check clean on the changed files; the line-cap, assertion-safety and mock-export ratchets, the conflict-marker check and the PR wrapper inventory test (eager-import-closure.test.ts) pass. check-test-lines-ratchet: net +301, allocation 301.

Everything below is from the pre-merge heads.

Head 6fbcf9eae1e (main 586f576 merged in), macOS arm64. Correction: the QA Lab flow and the test files in this section ran on the local default runtime, which since #172625 is OpenClaw's pinned Bun, not Node 26.12.1 as this line said. Node re-run under "Also on this head".

Real Gateway (QA Lab flow exec-completion-requester-sender-policy: Gateway child, qa-channel, real exec and config.patch; only the model is scripted). node scripts/run-node.mjs qa suite --provider-mode mock-openai --scenario exec-completion-requester-sender-policy --concurrency 1 --fast, run at 58bf6c5:

  • This branch: pass. The allowed sender's completion runs exec and writes its marker. The guest gets exec is not available in this turn. Do not retry exec. at launch. Revoking the third sender's entry after launch (same Gateway pid) leaves its completion with Unknown tool id: exec and no marker.
  • Same flow with main's session-event-target.ts and session-event-context.ts: fail, allowed requester's completion did not run exec: {"launched":true,"ran":false,..."completionOutput":"exec is not available in this turn. Do not retry exec."}.
  • fix: background command completions lose the owner's owner-only tools #185476's exec-completion-owner-authority still passes in the same run.

Completion-side exec through the real Telegram and Discord plugins (session-event-completion-reauthorize.test.ts): the managed tool host has shell tools; DM policy resolves through telegramPlugin.security (resolveTelegramDirectToolPolicy) and guild policy through discordPlugin.groups.resolveToolPolicy (resolveDiscordGroupToolPolicy). The completion runs printf ran > <marker> through exec. 13/13 pass.

  • Telegram DM rows: allowed; guest; sender revoked before admission; DM .tools revoked; DM toolsBySender["username:alice"] revoked; DM toolsBySender["name:Alice"] revoked; command owner with DM revoked; DM revoked with the completion routed to another chat; sender or DM revoked after admission (the tool host is retired before the call: agent harness host capability is no longer active).
  • Discord guild channel rows (guild 200001, channel ops): allowed; guilds["200001"].tools.deny added after launch; guilds["200001"].channels.ops.tools.deny added after launch.
  • Source of c4925913532: both Discord revocation rows fail, with exec offered and run. With GroupSpace restored but not GroupChannel, the channel row still fails.
  • Source of 176614364929: the username and name rows fail. Source of my first revision: the three DM rows that existed then failed. Main's source: the allowed row fails (exec not offered), which is [Bug]: exec-completion wake loses exec under toolsBySender wildcard deny #177510.

Batching (session-event-handoff.test.ts): otherGuest, ownerElsewhere, a same-id requester with another username (renamed) and the same requester in another guild (otherGuild) combined before; now they are refused. The file passes 24/24.

Also on this head:

  • Re-run on Node 26.12.1 (OPENCLAW_VITEST_RUNTIME=node), merged onto main 3855c896edd: session-event-completion-reauthorize.test.ts 13 passed, session-event-handoff.test.ts 24 passed.
  • Related suites: 16 files, 250 tests pass.
  • pnpm tsgo:all exit 0 (33 stages, 0 error TS); oxlint and oxfmt clean.
  • Ratchets OK against 586f576: line-cap, max-lines, assertion-safety, mock-exports, test-lines, timeout-race.
  • Test cost (pnpm test <file> --maxWorkers=1, Bun, the local default, macOS arm64, two runs each): session-event-completion-reauthorize.test.ts 64.7 s (cold worker cache, 21.9 s of it compiling) and 31.1 s wall, 23.1 s and 21.9 s of tests; session-event-handoff.test.ts 15.1 s and 15.3 s wall, 9.0 s and 9.1 s of tests. CI run 42429583841, Bun: session-event-completion-reauthorize.test.ts 54.1 s Vitest duration, 31.2 s of tests (checks-node-changed-compact-large-14); session-event-handoff.test.ts 17.0 s Vitest duration, 9.5 s of tests (checks-node-changed-compact-large-12).
  • Over 30 s: session-event-completion-reauthorize.test.ts is new in this PR and runs 21.9 s of tests locally and 31.2 s in CI: 13 rows at about 1.5 s each locally (2.0 s in CI), the first carrying one-time setup (3.3 s locally, 6.5 s in CI). It pins that a background exec completion "runs completion-side exec only under the requester's current sender and conversation policy". Exec runs for the owner and in the Discord guild channel. It is not offered to a guest, or after a revocation by sender id, DM, DM username, DM display name, guild or guild channel. A revocation after admission fails the call with "agent harness host capability is no longer active". Only model inference is mocked; admission, tool policy and exec are real. No cheaper layer proves it: the rows vary the sender id, username, display name, chat, guild and channel captured at handoff, and each has to reach the decision; the real Telegram and Discord plugins own the conversation policy; and the after-admission rows depend on config publication retiring the live tool host.
  • Test lines: net +301, recorded in config/test-lines-allocations/completion-requester-policy.txt.
  • CI on 176614364929 (run 41584998941): checks-fast-baseline-ratchets reported Test lines: 6421452; ceiling: 6420618; over by: 834; net delta: +236. The 834 was main's own overage at the time (main went over at 2a32ab046f2, fix(qa): accept direct settled Codex handoff wakes #191638; fix(ci): unblock allocated tests after inherited budget debt #191696 later raised the baseline by 834, and main was 10 over at f5f27c3ef6e). This PR's growth is allocated exactly.

Live Telegram DM (2026-11-10, a throwaway bot, macOS arm64, Node 26.12.1): one isolated Gateway built from main 9a5df3d60f1 with this PR's head and four of my other PR heads merged in (no file touched by two of them), on the real Telegram Bot API, with QA Lab's scripted mock provider (head ee3411e1a70). tools.toolsBySender gives my id {} and "*" denies exec, process, nodes and gateway; each leg starts a 30 s background exec whose completion turn runs exec once more to write a marker.

  • Allowed (my entry is {}): the launch and completion markers were both written.
  • My own entry narrowed after launch (tools.toolsBySender["id:<my id>"].deny: [exec, process], applied with openclaw config patch 1.96 s after the launch marker): no completion marker, and the completion turn's exec got Unknown tool id: exec.
  • Not run live: the DM-level deny and a main-side control.

Not shown end to end:

  • A live Discord transport, and the DM-level revocation rows on live Telegram (see below). The DM and guild rows above use the real plugins' policy code in process, with real admission and a real exec, but no Bot API traffic.
  • On a live Gateway, a channels.telegram.direct change made while a background exec runs is deferred until that exec completes (the Gateway logs deferring until 1 background exec session(s) complete), so a DM deny added mid-run does not reach that run's completion turn. This is existing reload behavior (src/gateway/server-reload-active-work.ts), which this PR does not change; the DM rows are proven by the unit test. I did not measure whether a channels.discord.guilds change is deferred the same way.
  • Batching through a product path. The only caller, session-state notices, does not retain a requester, so the batch check is proven by the unit test only.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 15:45
@clawsweeper

clawsweeper Bot commented Nov 1, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T15:57:48.804893Z 2f35518 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Batching can conflate distinct requesters and bypass one requester's revocation, while the current tests do not exercise completion-side shell dispatch through the real execution gate.

2 open issues
What changed in this PR

This PR addresses #177510 by retaining the originating requester's identity for background completions, allowing current toolsBySender policy to apply even when the requester is not a command owner.

Changes:

  • Capture host-trusted requester identity independently of command-owner status.
  • Project that identity onto completion turns only within the same channel and account, without granting command-owner authority.
  • Add authorized, guest, and revoked-requester regression cases and register their database-worker test route.
File Description
test/​vitest/​vitest.database-worker-core-paths.mjs Registers the new regression test on the database-worker route.
src/​auto-reply/​reply/​session-event-target.ts Retains and exposes the originating requester's identity.
src/​auto-reply/​reply/​session-event-context.ts Projects retained identity for current sender-policy evaluation.
src/​auto-reply/​reply/​session-event-completion-reauthorize.test.ts Adds completion policy and tool-surface regression cases.

Review effort: Balanced

@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 1, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f35518aa9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

Preserve the initiating sender and conversation context so background command completions receive the requester's current tool policy.

Example: Telegram sender 100001 has an unrestricted toolsBySender entry while the wildcard denies exec.

  • Before: The background command finishes, but its senderless completion loses exec and cannot finish the task.
  • After: The completion retains sender 100001 and its conversation policy, allowing exec unless that policy denies it when the completion starts.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A worthwhile, focused repair with product-path evidence and no definite introduced defect; required current-head CI remains approval-blocked.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied live Telegram and isolated Gateway evidence exercises background launch, completion-side exec and sender revocation; real plugin-policy integration tests cover DM and guild restrictions, with current integration results recorded in the latest comment.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A sender permitted to run background commands loses exec on the automatic completion and must send another message to finish the task.
Reason: The reported failure has an established policy contract and product-path evidence, and the repair adds no configuration or public API.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR fixes a concrete sender-policy failure that remains on current main; no introduced blocking defect was found.

Reviewed head: c5e043dad063db739558d3bb00a3c1601e765316

Before merge

  • Await maintainer action - Approve the action-required workflows for c5e043d and require successful CI before merging.

Findings

None.

Agent review details

How this fits together

The session-event owner captures host-trusted requester facts at command launch and supplies them to ordinary reply admission when the command finishes.

flowchart TD
  A[Sender request] --> B[Background exec]
  B --> C[Captured session target]
  C --> D[Completion context]
  D --> E[Current tool policy admission]
  E --> F[Completion tools and reply]
Loading

Technical review

Best possible solution:

Land the focused requester-context repair through the existing session-event owner once required current-head CI succeeds.

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

Current-main source exposes the senderless wildcard-policy path, and the contributor supplies a failing-main/passing-fix Gateway comparison; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change repairs lost context at the existing capture and completion owners, preserves ordinary policy admission, and addresses the earlier conversation, username, guild and batching findings.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Owner requester restoration keeps the original intent (aa8b35b: Restore owner-only tools to owner-started background completions while keeping guest completions restricted.)
  • Authority after completion admission keeps the original intent (cb1d8cd: Decide authority when the completion starts and let an admitted turn finish despite later revocation.)
  • Shared QA completion planner keeps the original intent (aa8b35b: Exercise background completion through a real Gateway and tool effect with scripted inference.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current-main failure remains: Current main restores sender identity only inside the command-owner branch. The PR independently retains non-owner requester facts; the inspected main files are unchanged from the pinned base. (src/auto-reply/reply/session-event-context.ts:348, 8b5220ef0b5c)
  • Requester and conversation restoration: The introduced restoration supplies sender ID, E164, username, display name, guild, channel name and native conversation ID under channel, account and conversation-type matching. (src/auto-reply/reply/session-event-context.ts:384, c5e043dad063)
  • Prior findings addressed: The reviewed tests exercise real Telegram and Discord policy resolvers and completion-side exec; batch compatibility now compares retained requesters, including conversation, username and guild differences. (src/auto-reply/reply/session-event-completion-reauthorize.test.ts:102, c5e043dad063)
  • Supplied product-path proof: The full PR body reports a live Telegram Gateway run where the allowed completion writes its marker and sender revocation prevents it, plus a Gateway QA comparison failing with main's production files and passing with the fix. The latest comment reports passing affected suites after integration. Live Discord and live Telegram DM-level revocation are explicitly outside that evidence. (c5e043dad063)
  • Feature provenance: Merged fix: background command completions lose the owner's owner-only tools #185476 intentionally restored owner-only completion capabilities through the existing session-event owner; this PR extends sender-policy context without granting non-owners owner authority. (src/auto-reply/reply/session-event-context.ts:350, aa8b35bb20fd)
  • Current-head CI has not run: The CI workflow for the reviewed head concluded action_required; openclaw/ci-gate is consequently red. This is an approval-blocked, never-run gate rather than an established diff-caused test failure. (c5e043dad063)

Likely related people:

  • Ayaan Zaidi: Raw commit 6ef7508 adds src/auto-reply/reply/session-event-context.ts:318 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6ef75084bd2d; files: src/auto-reply/reply/session-event-context.ts)
  • Peter Steinberger: Raw commit 3d2f7ca adds src/auto-reply/reply/session-event-context.ts:115 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3d2f7ca06b26; files: src/auto-reply/reply/session-event-context.ts)
  • Enes Kartal: Raw commit 21a85ac adds src/auto-reply/reply/session-event-context.ts:302 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 21a85accdc07; files: src/auto-reply/reply/session-event-context.ts)

PR surface

Source +102, Tests +302, Docs 0, Other +135. Total +539 across 11 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 142 40 +102
Tests 4 315 13 +302
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 135 0 +135
Total 11 593 54 +539

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:

No label changes.

Label justifications:

  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (8 earlier review cycles)
  • reviewed 2026-11-01T16:41:58.007Z sha 2f35518aa9193df9b2dc0d90f5b1a6fe882df5e7 :: needs real behavior proof before merge. :: [P1] Preserve conversation scope before restoring sender permissions
  • reviewed 2026-11-03T05:45:11.826Z sha 176614364929a72b6afe0d0a6f288c35a2f93d77 :: needs real behavior proof before merge. :: [P1] Preserve username and name when retaining the requester
  • reviewed 2026-11-03T20:16:20.813Z sha c4925913532529cf36b5c7f45ec955e0af0ea35f :: needs real behavior proof before merge. :: [P1] Preserve guild policy context before restoring group sender access
  • reviewed 2026-11-05T03:09:54.392Z sha 6fbcf9eae1e3f235154239054fccaac73013e462 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-05T03:17:22.880Z sha 6fbcf9eae1e3f235154239054fccaac73013e462 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-08T03:34:57.021Z sha ee3411e :: needs maintainer review before merge. :: none
  • reviewed 2026-11-11T19:36:43.634Z sha ee3411e :: needs maintainer review before merge. :: none
  • reviewed 2026-11-25T01:59:53.395Z sha 283e19c :: blocked before merge. :: none

Reviewed November 27, 2026, 1:32 PM ET / 18:32 UTC (Revision 9).

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: qa-lab size: L and removed size: M labels Nov 3, 2026
@amittell amittell changed the title fix(auto-reply): reauthorize exec completions against the originating requester's current sender policy fix(auto-reply): exec completions keep the requester's current sender and DM tool policy Nov 3, 2026
@amittell

amittell commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 3, 2026
@amittell
amittell force-pushed the fix/177510-completion-turn-reauthorize branch from f5356b0 to f2eb9ab Compare November 7, 2026 23:18
The original completion-requester-policy.txt allocation (301) exactly
covers this PR's net test-line growth against the rebased base. The
extra 25-line allocation was computed against the pre-rebase ceiling
and would exceed the allowed credit.
@amittell

amittell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Rebased onto main d44c9ad92 as ee3411e1a. The old head was 1996 commits behind and checks-fast-baseline-ratchets failed on the test-lines ratchet against the old merge base.

Ratchet. completion-requester-policy.txt (301) already covers the PR's net test-line growth (314 added, 13 removed); no new allocation needed.

CI is green at ee3411e1a (openclaw/ci-gate pass). Clean rebase, the diff under it is unchanged, and no proof items were open on the last review.

@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. 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 8, 2026
amittell added a commit to amittell/openclaw that referenced this pull request Nov 11, 2026
A branch-native equivalent of upstream openclaw#190472 (head ee3411e,
"exec completions keep the requester's current sender and DM tool
policy", issue openclaw#177510). Upstream's fix builds on openclaw#157806
(fd2a6ca, requester identity on the tool caller) and openclaw#185476
(aa8b35b, completion requester retention); neither is on this
branch. Drop this commit when a release that carries upstream's fix is
carried.

The defect here: a background exec's completion turn is built with no
sender (session-event-context.ts), and ordinary turns apply sender policy
(conversation-capability-profile.ts, senderPolicyMode "always"), so the
toolsBySender "*" entry applies and a sender allowed exec only by their
own entry loses it on the completion turn. Reproduced before the fix
(see proof); with "*" not denying exec the same test runs exec, so the
refusal is that sender policy.

What it captures, and where:
- At exec construction, from the host-owned run context and never from
  tool arguments: createOpenClawCodingTools passes
  resolveExecCompletionRequester(options) (new
  src/agents/exec-completion-requester.ts) into the exec defaults: the
  turn's sender id, E164, name, username, chat type, group space and
  group channel. A senderless turn captures nothing.
- runExecProcess keeps it on the process session as a start-time notify
  fact, cleared at settlement with the others. prepareExecExitNotification
  passes it, with that exec's own notify route, to
  captureSessionEventTargetForHost, which keeps a frozen copy with the
  target.
- buildSessionEventContext restores SenderId, SenderE164, SenderName,
  SenderUsername, GroupSpace and GroupChannel only when the completion's
  route exactly matches the captured route and the turn has the
  requester's chat type (set only on the session's own conversation).
  Anywhere else the turn stays senderless and gets the "*" policy.
- It never widens. The completion still runs inside the starting turn's
  captured tool surface (toolsAllow), which already carries that DM's own
  policy; the restored sender's current toolsBySender entry and group
  policy can only narrow it. Event turns never derive owner authority
  from identity (command-auth.ts), so completion turns stay non-owner.
  combineSessionEventTargetsForHost refuses to batch targets whose
  requesters differ.

Differences from upstream:
- Owner tools: upstream, with openclaw#185476, lets an owner's completion keep
  owner-only tools while they remain an owner. Here a completion turn is
  never an owner turn (as before this commit).
- DM policy: upstream re-resolves the DM's current policy; here the DM
  restriction is the one in force at launch (through the captured tool
  surface), so a DM deny added mid-run is not applied. Upstream notes a
  live Gateway defers channels.telegram.direct changes until background
  execs finish. Sender and group policy are current.
- Only Gateway/sandbox exec through runExecProcess; node system.run
  completions are not covered. No QA Lab scenario (upstream's needs
  main's mock-openai owner-completion fixtures).

Line cap: bash-tools.exec-runtime.ts is over its cap, so applyShellPath
moves unchanged to bash-tools.exec-path-prepend.ts, next to the other
exec PATH helpers.

Proof (M4, Node 26.12.1):
- New session-event-exec-requester.test.ts (8 rows). Only the model is
  synthetic: real exec, completion admission, tool host and policy, and
  the real Discord plugin's guild policy (without its gateway-started
  binding adapter). Three rows launch a real background exec through
  createOpenClawCodingTools; the rest capture as exec now does. 8/8 pass:
  the requester's own DM runs exec and keeps the DM's read deny; a
  command-owner requester runs exec and stays non-owner; a command
  started in another chat, a different sender, no captured sender, the
  requester's entry revoked before completion and a guild deny added
  before completion all leave exec absent; the Discord guild channel
  runs exec. session-event-handoff.test.ts adds the batch refusal.
- Reproduction before the fix: the requester's DM row fails with exec
  not offered; with "*" not denying exec it passes.
- Red-before (production files reverted, tests kept): 4 fail, the three
  rows that run exec and the batch refusal; the five denial rows pass.
- Mutation: with the owner guard removed the owner row fails
  (owner true); with GroupSpace/GroupChannel not restored the guild-deny
  row fails (exec runs).
- Every test file importing a touched module (172 files): 2590 passed,
  8 skipped, 0 failed.
- check-line-cap-ratchet and check-test-mock-exports (base v2026.11.2),
  run-oxlint on the 16 touched .ts files, tsgo:core, tsgo:test:src,
  oxfmt --check and format:docs:check: exit 0.
@amittell

Copy link
Copy Markdown
Contributor Author

Could a maintainer remove triage: needs-pr-context? Barnacle added it on Nov 1, when the body had no "What Problem This Solves" or "Evidence" section. Both sections have been in the body since Nov 3, and "PR context and evidence" has passed on every head since then, including ee3411e1a70 (run 42754515265). Barnacle can't remove it itself: every auto-response run since Nov 3 logs Skipping Barnacle #190472: protected-label.

@amittell

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. 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 11, 2026
# Conflicts:
#	extensions/qa-lab/src/providers/mock-openai/mock-openai-owner-completion.ts
#	src/auto-reply/reply/session-event-context.ts
#	src/auto-reply/reply/session-event-target.ts
…the next start

Main's openclaw#202513 and openclaw#204105 decide operator and owner authority once, when a
run starts, and drop the mid-run re-checks; a started run may finish. The two
"revoked after admission" rows asserted the old behaviour (the admitted turn's
tool host retired before the call). On this merge the completion keeps the
exec it was admitted with and runs it, as main intends. Every "before
admission" row, the guild rows and the guest row are unchanged and still pass.
@amittell

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Merged main eee7a1bd526 as 9038986bf5e. Three files conflicted. The two session-event files keep main's command-owner changes and add the retained requester after them; the qa-lab mock keeps main's answeredAfter helper. Main's #204105 now fixes a completion turn's authority when it starts, so 283e19cf875 changes the two "revoked after admission" rows to expect the admitted turn to keep exec. Revoking before the completion starts still removes it. The QA flow passes 1/1 and the 9 session-event* files pass 171 of 171. With main's two production files the QA flow fails, the new reauthorize test fails 5 of 13 (4 allowed rows lose exec, and the command owner whose DM entry was revoked keeps it), and the handoff test fails 1 of 22. Details at the top of Evidence.

@clawsweeper

clawsweeper Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 25, 2026
# Conflicts:
#	docs/gateway/background-process.md
#	src/auto-reply/reply/session-event-context.ts
#	src/auto-reply/reply/session-event-target.ts
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 27, 2026
@amittell

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Merged main 6deafbdf9dc as c5e043dad06. Main renamed the scheduled requester (#205346: requesterOwner -> scheduledRequester) and dropped ownerContinuation (#206665). The resolution keeps main's names and adds this PR's retainedRequester beside them in the target scope, the buildSessionEventContext imports, and the batching key in combineSessionEventTargetsForHost. In background-process.md it keeps this PR's sentence on sender and conversation policy and main's new closing sentence from #205015 (after a restart, durable outcomes run as the requester who started the command).

Main's #204785 now hands exec completions the target's operator authority, so an owner grant takes the first branch, which does not restore the requester. With a temporary log line on the merged tree, all 13 completion turns in session-event-completion-reauthorize.test.ts arrive with no operator grant and restore the requester (100001, or 100002 for the guest), as before the merge.

17 test files, 181 tests pass: the PR's two, plus every test that imports session-event-context.js or session-event-target.js. tsgo:core, tsgo:core:test and tsgo:extensions pass with 0 errors (an injected TS2322 in session-event-context.ts fails tsgo:core), and oxlint is clean on the PR's files.

@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

This branch has not been deployed

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

Labels

docs Improvements or additions to documentation extensions: qa-lab gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: exec-completion wake loses exec under toolsBySender wildcard deny

2 participants