Skip to content

fix(plugins): expose verified Control UI requester identity to tools - #189600

Merged
roboclaw-bot merged 14 commits into
mainfrom
openclaw/quiet-shell-2
Nov 29, 2026
Merged

roboclaw-bot merged 14 commits into
mainfrom
openclaw/quiet-shell-2

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #166721

What Problem This Solves

A signed-in Control UI user can be allowed to run a plugin tool, yet the plugin cannot tell whose account to use. A browser chat intentionally has no channel sender ID. The personal MCP sign-in fix in #204250 does not expose a person to ordinary plugin factories.

User Impact

A plugin factory can read context.requesterProfile?.id to identify the person who started a verified, direct Control UI turn. It is attribution, not permission. A tab disconnect does not change who started the turn. Existing owner permissions, transport sender IDs, resource policies, and MCP credential checks keep their meanings. No migration or configuration change is required.

Why This Change Was Made

The prepared run already captures the browser requester for personal MCP. The plugin factory now consumes an immutable ID from that same capture when the admitted canonical person matches. It gets no live identity assertion, socket reference, or new permission. The existing invocation guard remains responsible for a plugin's active invocation. This removes the earlier proposal's duplicate lifetime checks and session-ID pins.

Evidence

On 1bfcee9a6f12cb682dff122bf9466358ac26c016, the isolated AWS run built the runtime and passed the standalone Gateway test: a signed-in user read a room, their tab disconnected during draft preparation, and the disk-loaded plugin persisted the unsent draft under that same person's ID. A member without owner permission had no model or room-service calls. The test took 11.56 seconds (62.93 seconds for the suite). All 12 adjacent personal-MCP tests passed (31.37 seconds for the suite). The model and room service were deterministic local fixtures, not live external accounts. AWS lease cbx_d8d73e614d0d was released.

Exact-head CI succeeded, including the previous session-identity ratchet and docs lanes. Local AutoReview P0–P2 could read the full frozen candidate against 1d87cbfd5105f477c62fad58bfa0cd9aa2da6e3e, but its read-only sandbox could not launch either installed Codex entrypoint. No local reviewer verdict is claimed.

Credit

Thanks to @PollyBot13 for the report and causal investigation, @jonathanlindsay for the contract and use case, @Canvinus and @apps3000 for related MCP and hook work, and @TheAngryPit for the original profile and native-identity work. @RomneyDa and @daniel-lxs integrated the branch with main. @VACInc requested the admission-compatible repair. These credits are not approvals.

Co-authored-by: TheAngryPit [email protected]

Work sessions

Linked for team reference; these sessions aren’t public.

Worked on by

roboclaw-bot and others added 2 commits October 31, 2026 16:46
Co-authored-by: TheAngryPit <[email protected]>
Worked on by:
- @TheAngryPit

Co-authored-by: TheAngryPit <[email protected]>
OpenClaw-Publication: 9962a297-adbf-4d12-91b1-d1e4e515951a
@clawsweeper

clawsweeper Bot commented Oct 31, 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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: 1bfcee9a6f12cb682dff122bf9466358ac26c016

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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:feature Preliminary submission classification; full source review pending. labels Oct 31, 2026
@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR exposes the verified initiating Control UI person's ID to plugin tool factories without changing transport sender identity or permissions.

Example: A Control UI turn from ada-profile reads a room and prepares an unsent draft.

  • Before: The plugin factory cannot identify Ada through its public context and withholds its personal tools.
  • After: The factory receives requesterProfile.id equal to ada-profile, which remains attribution after Ada's tab disconnects.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, useful patch with no identified defects and green exact-head CI; independently inspectable behavioral evidence is limited to source and the reported fixture scenario.
Proof confidence 🦐 gold shrimp (3/6) This PR is exempt from the contributor proof gate; its body reports an exact-head standalone Gateway read and unsent-draft run across disconnect, supported by the inspected regression, but the linked run artifact was inaccessible and CI log retrieval was blocked by the artifact host allowlist.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Personal plugin tools disappear for signed-in Control UI users because their factories cannot identify whose account to use.
Reason: The narrow contract repairs the motivating Control UI factory flow with maintainer-authored direction; additional backend-client and hook use cases remain separate capabilities.

Merge readiness

✅ Ready for maintainer review

This maintainer-authored PR provides a useful plugin identity contract that current main still lacks. The previous disconnect finding is resolved, and no introduced correctness or security defect was found.

Reviewed head: 1bfcee9a6f12cb682dff122bf9466358ac26c016

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway admission supplies the verified person to the existing prepared-run requester capture; plugin context construction projects its immutable ID to tool factories, while existing invocation guards govern execution.

flowchart LR
  A[Authenticated Control UI] --> B[Gateway admission]
  B --> C[Prepared run requester]
  C --> D[Plugin factory context]
  D --> E[Personal plugin tools]
  E --> F[Existing invocation guard]
  F --> G[Plugin service request]
Loading

Technical review

Best possible solution:

Expose immutable initiating-person attribution from the existing prepared requester capture and retain the existing invocation and cancellation boundaries.

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

Current main captures verified requester identity for personal MCP but omits it from ordinary plugin factory contexts, matching the linked report's missing-identity failure; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The focused projection uses the existing verified requester owner, preserves transport identity, and resolves the prior socket-dependent refusal without introducing another authority check.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3f9c2bb09b59.

Provenance checked

  • Prepared requester capture keeps the original intent (f00839d: Let verified Gateway users use personal MCP accounts without rewriting transport sender IDs.)
  • Plugin invocation lifetime keeps the original intent (fix: owner-gated plugin calls fail after the parent yields #150295: Preserve explicitly opted-in plugin invocation authority across exact-parent continuations.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • RoboClaw: Raw commit f00839d adds src/agents/agent-bundle-mcp-webchat-requester.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f00839db8eed; files: src/agents/agent-bundle-mcp-webchat-requester.ts)
  • Peter Steinberger: Raw commit 579c50d adds src/agents/openclaw-tools.plugin-context.ts:63 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 579c50dd6092; files: src/agents/openclaw-tools.plugin-context.ts)
  • Ayaan Zaidi: Raw commit def6349 adds src/agents/openclaw-tools.plugin-context.ts:123 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: def63496ca8f; files: src/agents/openclaw-tools.plugin-context.ts)

PR surface

Source +13, Tests +396, Docs +2. Total +411 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 13 0 +13
Tests 2 396 0 +396
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 411 0 +411

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 test growth Production +13 lines; tests +396 lines The production change extends existing owners; most test growth exercises authenticated plugin loading and disconnect behavior through a standalone Gateway.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166721
Summary: This PR addresses the canonical issue's Control UI plugin-factory identity gap; MCP account selection and hook device attribution have separate owners.

Members:

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • merge-risk: 🚨 compatibility: This adds a public optional Plugin SDK context field; the maintainer-authored contract preserves existing sender semantics and requires no consumer migration.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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-10-31T17:47:31.771Z sha ba43c98 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-31T20:28:06.053Z sha ea72a46 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-31T20:48:49.712Z sha 3971b5a :: needs maintainer review before merge. :: none
  • reviewed 2026-10-31T21:25:20.498Z sha b316ade :: needs maintainer review before merge. :: none
  • reviewed 2026-10-31T21:43:56.330Z sha 1da24df :: needs maintainer review before merge. :: none
  • reviewed 2026-10-31T21:51:17.043Z sha 1da24df :: needs maintainer review before merge. :: none
  • reviewed 2026-11-05T05:32:56.948Z sha dbe22b7 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-28T08:21:33.058Z sha 539d4f4 :: needs changes before merge. :: [P2] Preserve admitted requester identity across a browser disconnect

Reviewed November 29, 2026, 10:45 AM ET / 15:45 UTC (Revision 9).

Worked on by:
- @TheAngryPit

Co-authored-by: TheAngryPit <[email protected]>
OpenClaw-Publication: b9a27579-1e1d-49ac-a913-5ce79a803354
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 31, 2026
Worked on by:
- @TheAngryPit

Co-authored-by: TheAngryPit <[email protected]>
OpenClaw-Publication: 432ea4a8-985d-46d9-b0b3-d04c17ccef76
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 31, 2026
roboclaw-bot and others added 2 commits November 7, 2026 00:16
Co-authored-by: TheAngryPit <[email protected]>
Worked on by:
- @TheAngryPit

Co-authored-by: TheAngryPit <[email protected]>
OpenClaw-Publication: 26564f2b-d0cb-4398-818e-8e57a73a02ce
obviyus added a commit that referenced this pull request Nov 18, 2026
…rn (#200664)

Related: #189600, #187952, #177713

## What Problem This Solves

A plugin hook can't tell which paired device sent a turn. The gateway already knows: every `chat.send` from a paired operator device runs with `ApprovalReviewerDeviceId` set from the connection's verified device (`client.connect.device.id`), and exec approvals are bound to it. But neither the agent hook context nor the tool requester context exposes it. What hooks do see, `senderId`, names the kind of client (for example `openclaw-ios`), not the device, so two phones running the same app look identical to a plugin. A plugin that wants to allow or refuse a turn based on which paired device sent it has no field to read.

## User Impact

Plugins get the verified device id for turns a paired device sends:

- agent hooks (`before_agent_run`, `before_prompt_build`, `agent_end`, …): `ctx.requesterDeviceId`
- tool hooks (`before_tool_call`, …): `ctx.requester.deviceId`

Both are optional and read-only. Both are set only from the authenticated connection, never from request params (`chat.send` still rejects unknown properties), and only for user-triggered turns. A device-less client (shared token, no device identity) gets neither field. Nothing changes for plugins that don't read them.

## Why This Change Was Made

The id already exists on the run (`approvalReviewerDeviceId`, threaded into the embedded attempt for approval binding). This change copies it onto the two hook contexts at the points where they're built. It doesn't add a new source or a new trust decision:

- `src/plugins/hook-agent-context.types.ts` / `hook-agent-context.ts`: `requesterDeviceId?` on `PluginHookAgentContext`, set by `buildAgentHookContextIdentityFields` from `approvalReviewerDeviceId` under the same `trigger === "user"` (or unset) rule that already governs `senderId` and `chatId`.
- `src/agents/harness/hook-context.ts`: passes the attempt's `requesterDeviceId` through.
- `extensions/codex/src/app-server/run-attempt-context.ts`: the Codex app-server runtime builds its own agent hook context, so it sets `requesterDeviceId` from the attempt's `approvalReviewerDeviceId` too. The shared builder still applies the user-trigger rule.
- `src/agents/cli-runner/prepare-hook-context.ts`: CLI backend turns build their `before_prompt_build` context separately, so it takes `requesterDeviceId` from the shared identity projection (same user-trigger rule). The CLI's other hooks already used that projection.
- `src/plugins/hook-tool-context.types.ts` / `src/agents/harness/host-requester.ts`: `readonly deviceId?` on the tool requester, set from `attempt.approvalReviewerDeviceId`.
- Docs: `docs/plugins/hooks/tool-policy.md` and `docs/plugins/hooks/prompt-and-session.md`.
- Tests: `src/plugins/hook-agent-context.test.ts`, `extensions/codex/src/app-server/run-attempt.auth-context.test.ts` (the Codex prompt and compaction hooks carry the id on a user turn and drop it on cron), a case in `src/agents/cli-runner/prepare.test.ts` (the CLI prompt-build hook receives it), and new `src/agents/harness/host-requester.test.ts`. `prepare-mcp.test-support.ts`'s grant-transfer case now expects `deviceId` on the tool requester.

**How this relates to #189600.** That PR gives tool factories `toolContext.requesterProfile`, the verified Gateway *profile* (the person) behind an admitted Control UI turn, with a liveness check. This one gives hooks the verified *device* behind any paired device's turn, phones and native apps included, which have no profile and no Control UI session. They answer different questions (which person, which device) at different layers (tool factory, hooks), they touch none of the same files, and either can land first. If maintainers would rather have one requester-identity object, `deviceId` fits next to `requesterProfile` without changing this PR's meaning.

Accepted edge cases:
- Only user-triggered turns carry the id, the same as `senderId`. Cron, heartbeat and other system-triggered runs don't.
- A run a plugin starts with `api.runtime.subagent.run` carries the id only when it's started inside the paired device's gateway-method request. That's when the in-process `agent` dispatch uses the device's connection. A run started from the plugin's own detached context runs as the plugin and carries none, which is correct: no device asked for it.
- The id is the device that sent the turn. It isn't a person; for that, see #189600.

## Evidence

**Real gateway with a real model.** Source build of this PR's head (80af2ee). The model was `openai/gpt-5.4-mini`, which runs on the Codex app-server runtime. Clients were OpenClaw's own `GatewayClient`, and a probe plugin logged every hook's context. Device ids are cut to 8 characters:

| Case | `before_prompt_build` / `agent_end` | `before_tool_call` (every tool the model called) |
|---|---|---|
| a: paired device `openclaw-ios`/ui sends `chat.send` | `requesterDeviceId c74f633c…`, `senderId openclaw-ios` | `requester.deviceId c74f633c…` |
| c: second paired device, same client id and display name | `requesterDeviceId 03d163a…` (its own) | `requester.deviceId 03d163a…` |
| d: device-less `cli` (shared token) | no `requesterDeviceId`, `senderId cli` | no `requester.deviceId`, including on `device_probe_tool` |

This run found a gap in this PR's first head (9449852). On the Codex runtime, tool hooks had the id but `before_prompt_build` and `agent_end` didn't, because that runtime builds its own agent hook context. The second commit fixes it. With the first commit's tree restored, the extended Codex test fails (`expected … to match object … requesterDeviceId: 'device-a'`).

The stub-model runs below use the embedded runtime (`openai-completions` provider) and cover the request-param and pairing cases.

Real gateway, source build of this change (6e198d5, before the rebase) against its parent on main (5fb2315), with a probe plugin that logs both hook contexts, OpenClaw's own `GatewayClient` and a local OpenAI-compatible stub model. No provider keys were set, and device ids are cut to 8 characters:

| Case | This head | Base (5fb2315) |
|---|---|---|
| Paired device (`openclaw-ios`/ui) sends `chat.send` | `before_agent_run`: `requesterDeviceId bc313985…`; `before_tool_call` (`dispatch_action` and the inner plugin tool): `requester.deviceId bc313985…` | `senderId openclaw-ios` only; no device id anywhere |
| Same device adds `requesterDeviceId` or `approvalReviewerDeviceId` to `chat.send` | `INVALID_REQUEST … unexpected property` (closed schema), no run | same |
| Second device with the same client id and display name | sees its own id (`cc3b699f…`), never the first's | n/a |
| Device-less client (`cli`, shared token) | no `requesterDeviceId`, no `requester.deviceId` | same |

`grep -rl requesterDeviceId dist` finds nothing in the base build.

The same change, backported onto 2026.11.4, was also run with a plugin whose gateway method starts `subagent.run` inside the device's request. The id was on every hook of the run, including hooks that fired after the device's socket had closed, and the run finished normally.

Checks on this PR's head (abe48fb, on main bb45ba9):
- Tests: 19 test files that touch the requester device or hook contexts (hook-agent-context, host-requester, Codex run-attempt.auth-context, native-hook-relay and dynamic-tools, CLI prepare, tool-authority and reliability, embedded attempt tool context, before-tool-call approval policy, plugin tool context, reply authority and others) pass, except one Codex `dynamic-tools` case ("bounds high-cardinality validation errors") that fails the same way on main bb45ba9. The new hook-agent-context, Codex and CLI assertions each fail with main's production line.
- `pnpm tsgo:core` and `pnpm tsgo:extensions` pass.
- oxlint and oxfmt are clean on the changed files, `git diff --check` is clean, and `check:test-lines-ratchet` passes (+49 net test lines, within the 400 allowance).
- The local Codex autoreview (`--mode branch --engine codex --max-priority P2`) found nothing on the first commit.
- On the change before the rebase (6e198d5), every `lint:tmp:*` script, `check:max-lines-ratchet`, `check:assertion-safety`, `check:test-timeout-race-ratchet` and `config:docs:check`/`config:schema:check` also passed.
- Plugin SDK API diff: additive optional fields only (`PluginHookAgentContext.requesterDeviceId`, `PluginHookToolRequesterContext.deviceId`).

Not run: the full test suite locally (CI covers it), the CLI runner path with a real model, and a real phone app.


## Maintainer fix

**Bug found in review:** steering from device B into device A's active run kept reporting device A to hooks. A device allowlist then authorized B's input as A.

**Fix:**
- `src/plugins/hook-requester-device.ts` records the device of every human input accepted into a run. Hook dispatch withholds the device unless all input came from that device. A missing device is acceptable; a wrong device is not.
- Talk steering (`talk.client.steer`) carries the verified caller device, so a client that steers its own run keeps its device.
- Sync hooks (`tool_result_persist`, `before_message_write`) carry no device and are not projected.
- Pure hook-selection helpers moved to `src/plugins/hook-registration-select.ts` to keep `hooks.ts` within the line cap.
- Docs: steering caveat and a device allowlist example.

**Real Gateway proof** (isolated Gateway, real model, two paired devices A and B, probe plugin logging the device each hook sees):

| Scenario | Device the hook sees |
|---|---|
| `chat.send` from A | A |
| B steers into A's run, before fix | A (wrong) |
| B steers into A's run, after fix | none |
| A steers its own run | A |
| Collect from A and B | separate runs, each its own device |
| Restart resume | none |
| Revoke A mid-run | run cancelled, `agent_end` shows A |
| Subagent / `sessions_send` / `tools.invoke` from B | none |
| Allowlist plugin (allow A only) | A's run reaches `session_status`; B's run is blocked at `dispatch_action` |

Checked from source only: retries and fallback reuse the same runId and input; compaction keeps the runId; cron and side questions carry no device; MCP HTTP grants carry the device and runId.

Regression tests (red before, green after): `src/auto-reply/reply/message-injection-requester-device.test.ts`, `src/agents/cli-runner/prepare-hook-context.test.ts`, `src/talk/agent-run-control.test.ts`.

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

Related: openclaw#189600, openclaw#187952, openclaw#177713

## What Problem This Solves

A plugin hook can't tell which paired device sent a turn. The gateway already knows: every `chat.send` from a paired operator device runs with `ApprovalReviewerDeviceId` set from the connection's verified device (`client.connect.device.id`), and exec approvals are bound to it. But neither the agent hook context nor the tool requester context exposes it. What hooks do see, `senderId`, names the kind of client (for example `openclaw-ios`), not the device, so two phones running the same app look identical to a plugin. A plugin that wants to allow or refuse a turn based on which paired device sent it has no field to read.

## User Impact

Plugins get the verified device id for turns a paired device sends:

- agent hooks (`before_agent_run`, `before_prompt_build`, `agent_end`, …): `ctx.requesterDeviceId`
- tool hooks (`before_tool_call`, …): `ctx.requester.deviceId`

Both are optional and read-only. Both are set only from the authenticated connection, never from request params (`chat.send` still rejects unknown properties), and only for user-triggered turns. A device-less client (shared token, no device identity) gets neither field. Nothing changes for plugins that don't read them.

## Why This Change Was Made

The id already exists on the run (`approvalReviewerDeviceId`, threaded into the embedded attempt for approval binding). This change copies it onto the two hook contexts at the points where they're built. It doesn't add a new source or a new trust decision:

- `src/plugins/hook-agent-context.types.ts` / `hook-agent-context.ts`: `requesterDeviceId?` on `PluginHookAgentContext`, set by `buildAgentHookContextIdentityFields` from `approvalReviewerDeviceId` under the same `trigger === "user"` (or unset) rule that already governs `senderId` and `chatId`.
- `src/agents/harness/hook-context.ts`: passes the attempt's `requesterDeviceId` through.
- `extensions/codex/src/app-server/run-attempt-context.ts`: the Codex app-server runtime builds its own agent hook context, so it sets `requesterDeviceId` from the attempt's `approvalReviewerDeviceId` too. The shared builder still applies the user-trigger rule.
- `src/agents/cli-runner/prepare-hook-context.ts`: CLI backend turns build their `before_prompt_build` context separately, so it takes `requesterDeviceId` from the shared identity projection (same user-trigger rule). The CLI's other hooks already used that projection.
- `src/plugins/hook-tool-context.types.ts` / `src/agents/harness/host-requester.ts`: `readonly deviceId?` on the tool requester, set from `attempt.approvalReviewerDeviceId`.
- Docs: `docs/plugins/hooks/tool-policy.md` and `docs/plugins/hooks/prompt-and-session.md`.
- Tests: `src/plugins/hook-agent-context.test.ts`, `extensions/codex/src/app-server/run-attempt.auth-context.test.ts` (the Codex prompt and compaction hooks carry the id on a user turn and drop it on cron), a case in `src/agents/cli-runner/prepare.test.ts` (the CLI prompt-build hook receives it), and new `src/agents/harness/host-requester.test.ts`. `prepare-mcp.test-support.ts`'s grant-transfer case now expects `deviceId` on the tool requester.

**How this relates to openclaw#189600.** That PR gives tool factories `toolContext.requesterProfile`, the verified Gateway *profile* (the person) behind an admitted Control UI turn, with a liveness check. This one gives hooks the verified *device* behind any paired device's turn, phones and native apps included, which have no profile and no Control UI session. They answer different questions (which person, which device) at different layers (tool factory, hooks), they touch none of the same files, and either can land first. If maintainers would rather have one requester-identity object, `deviceId` fits next to `requesterProfile` without changing this PR's meaning.

Accepted edge cases:
- Only user-triggered turns carry the id, the same as `senderId`. Cron, heartbeat and other system-triggered runs don't.
- A run a plugin starts with `api.runtime.subagent.run` carries the id only when it's started inside the paired device's gateway-method request. That's when the in-process `agent` dispatch uses the device's connection. A run started from the plugin's own detached context runs as the plugin and carries none, which is correct: no device asked for it.
- The id is the device that sent the turn. It isn't a person; for that, see openclaw#189600.

## Evidence

**Real gateway with a real model.** Source build of this PR's head (80af2ee). The model was `openai/gpt-5.4-mini`, which runs on the Codex app-server runtime. Clients were OpenClaw's own `GatewayClient`, and a probe plugin logged every hook's context. Device ids are cut to 8 characters:

| Case | `before_prompt_build` / `agent_end` | `before_tool_call` (every tool the model called) |
|---|---|---|
| a: paired device `openclaw-ios`/ui sends `chat.send` | `requesterDeviceId c74f633c…`, `senderId openclaw-ios` | `requester.deviceId c74f633c…` |
| c: second paired device, same client id and display name | `requesterDeviceId 03d163a…` (its own) | `requester.deviceId 03d163a…` |
| d: device-less `cli` (shared token) | no `requesterDeviceId`, `senderId cli` | no `requester.deviceId`, including on `device_probe_tool` |

This run found a gap in this PR's first head (9449852). On the Codex runtime, tool hooks had the id but `before_prompt_build` and `agent_end` didn't, because that runtime builds its own agent hook context. The second commit fixes it. With the first commit's tree restored, the extended Codex test fails (`expected … to match object … requesterDeviceId: 'device-a'`).

The stub-model runs below use the embedded runtime (`openai-completions` provider) and cover the request-param and pairing cases.

Real gateway, source build of this change (6e198d5, before the rebase) against its parent on main (30c2ded), with a probe plugin that logs both hook contexts, OpenClaw's own `GatewayClient` and a local OpenAI-compatible stub model. No provider keys were set, and device ids are cut to 8 characters:

| Case | This head | Base (30c2ded) |
|---|---|---|
| Paired device (`openclaw-ios`/ui) sends `chat.send` | `before_agent_run`: `requesterDeviceId bc313985…`; `before_tool_call` (`dispatch_action` and the inner plugin tool): `requester.deviceId bc313985…` | `senderId openclaw-ios` only; no device id anywhere |
| Same device adds `requesterDeviceId` or `approvalReviewerDeviceId` to `chat.send` | `INVALID_REQUEST … unexpected property` (closed schema), no run | same |
| Second device with the same client id and display name | sees its own id (`cc3b699f…`), never the first's | n/a |
| Device-less client (`cli`, shared token) | no `requesterDeviceId`, no `requester.deviceId` | same |

`grep -rl requesterDeviceId dist` finds nothing in the base build.

The same change, backported onto 2026.11.4, was also run with a plugin whose gateway method starts `subagent.run` inside the device's request. The id was on every hook of the run, including hooks that fired after the device's socket had closed, and the run finished normally.

Checks on this PR's head (abe48fb, on main d4684da):
- Tests: 19 test files that touch the requester device or hook contexts (hook-agent-context, host-requester, Codex run-attempt.auth-context, native-hook-relay and dynamic-tools, CLI prepare, tool-authority and reliability, embedded attempt tool context, before-tool-call approval policy, plugin tool context, reply authority and others) pass, except one Codex `dynamic-tools` case ("bounds high-cardinality validation errors") that fails the same way on main d4684da. The new hook-agent-context, Codex and CLI assertions each fail with main's production line.
- `pnpm tsgo:core` and `pnpm tsgo:extensions` pass.
- oxlint and oxfmt are clean on the changed files, `git diff --check` is clean, and `check:test-lines-ratchet` passes (+49 net test lines, within the 400 allowance).
- The local Codex autoreview (`--mode branch --engine codex --max-priority P2`) found nothing on the first commit.
- On the change before the rebase (6e198d5), every `lint:tmp:*` script, `check:max-lines-ratchet`, `check:assertion-safety`, `check:test-timeout-race-ratchet` and `config:docs:check`/`config:schema:check` also passed.
- Plugin SDK API diff: additive optional fields only (`PluginHookAgentContext.requesterDeviceId`, `PluginHookToolRequesterContext.deviceId`).

Not run: the full test suite locally (CI covers it), the CLI runner path with a real model, and a real phone app.


## Maintainer fix

**Bug found in review:** steering from device B into device A's active run kept reporting device A to hooks. A device allowlist then authorized B's input as A.

**Fix:**
- `src/plugins/hook-requester-device.ts` records the device of every human input accepted into a run. Hook dispatch withholds the device unless all input came from that device. A missing device is acceptable; a wrong device is not.
- Talk steering (`talk.client.steer`) carries the verified caller device, so a client that steers its own run keeps its device.
- Sync hooks (`tool_result_persist`, `before_message_write`) carry no device and are not projected.
- Pure hook-selection helpers moved to `src/plugins/hook-registration-select.ts` to keep `hooks.ts` within the line cap.
- Docs: steering caveat and a device allowlist example.

**Real Gateway proof** (isolated Gateway, real model, two paired devices A and B, probe plugin logging the device each hook sees):

| Scenario | Device the hook sees |
|---|---|
| `chat.send` from A | A |
| B steers into A's run, before fix | A (wrong) |
| B steers into A's run, after fix | none |
| A steers its own run | A |
| Collect from A and B | separate runs, each its own device |
| Restart resume | none |
| Revoke A mid-run | run cancelled, `agent_end` shows A |
| Subagent / `sessions_send` / `tools.invoke` from B | none |
| Allowlist plugin (allow A only) | A's run reaches `session_status`; B's run is blocked at `dispatch_action` |

Checked from source only: retries and fallback reuse the same runId and input; compaction keeps the runId; cron and side questions carry no device; MCP HTTP grants carry the device and runId.

Regression tests (red before, green after): `src/auto-reply/reply/message-injection-requester-device.test.ts`, `src/agents/cli-runner/prepare-hook-context.test.ts`, `src/talk/agent-run-control.test.ts`.

Co-authored-by: Ayaan Zaidi <[email protected]>
@daniel-lxs

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 28, 2026
Reuse the verified identity captured for the admitted direct browser turn. Plugin factories receive attribution, not a second authorization callback. Leave transport senders, MCP credential selection, and the existing cancellation boundary unchanged.

Co-authored-by: VACInc <[email protected]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 29, 2026
@roboclaw-bot
roboclaw-bot merged commit a98d835 into main Nov 29, 2026
146 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/quiet-shell-2 branch November 29, 2026 15:55
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…penclaw#189600)

Expose the verified initiating Control UI profile to plugin factories as attribution, independent of sender or owner permission. Preserve the admitted requester after a tab disconnects and keep the existing invocation and personal MCP checks.

Co-authored-by: TheAngryPit <[email protected]>
Co-authored-by: VACInc <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawtributors PR from a clawtributor docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants