Skip to content

fix: personal memory hooks miss authenticated webchat users - #187952

Open
apps3000 wants to merge 2 commits into
openclaw:mainfrom
apps3000:fix/ui-profile-sender-hooks
Open

apps3000 wants to merge 2 commits into
openclaw:mainfrom
apps3000:fix/ui-profile-sender-hooks

Conversation

@apps3000

@apps3000 apps3000 commented Oct 29, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Fixes personal-memory hooks receiving no user identity for authenticated Control UI turns, causing integrations such as Honcho to fall back to an owner peer even when the transcript identifies a different person.

User Impact

Hooks can observe the verified initiating user for each accepted UI turn, including successive turns by different people in one shared session. This does not add command, tool, or MCP permissions. Expired personal bindings skip hook dispatch or discard returned enrichment instead of becoming anonymous owner turns.

Attribution remains per accepted initiating turn; this does not add separate authorship for every coauthor merged through steering. No configuration or data migration is required.

Why This Change Was Made

Control UI intentionally omits the legacy transport sender to preserve authority boundaries. The fix carries a live, host-bound profile observation through the existing run projections solely for hook context. Dispatch rechecks it before invoking a plugin and before accepting returned results, including cached contexts and delegated ingress. The private observer reads in the captured ingress async context, so a later agent tool context does not misclassify the original human request. Live grant checks still run on every read; plugin callbacks never run in that captured context. Existing channel senders retain precedence, and the private resolver is removed before plugin delivery.

An existing pure finalize-result merger is moved unchanged to keep the edited hook runner within the repository line-cap ratchet.

Evidence

  • Regression reproduced against the original Gateway turn preparation path: an authenticated profile was recorded, but the hook sender was undefined.
  • Eight focused test files initially passed (248 tests); the final Gateway/requester/hook bundle passed 175 tests after adding the real agent-context regressions, covering Gateway identity, prepared-run projections, CLI/embedded hook consumers, prefix stability, profile switches, delegated revocation/abort, copied bindings, cached contexts, and revocation while handlers resolve or reject.
  • Native core production typecheck and both unused-file inventories passed; the extracted helper is reachable. Diff, format, line-cap, and safety-assertion checks passed.
  • Independent source/security review and simplification pass completed; the material revocation and claiming-hook findings were fixed. The finalize-merger extraction was also compared byte for byte after dedenting. Optional autoreview/ClawSweeper tools are not installed on this contributor host.
  • Clean native build: OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build passed on Node 24.22.1, including runtime, SDK declarations, Control UI assets and native import/export checks.
  • Real isolated Gateway + real agent + real model: three authenticated Control UI protocol turns passed: person A in a private draft, A in a shared session, then B in the same shared session. A synthetic probe plugin selected the correct personal marker for each model answer; both lookup and agent_end received the correct initiating profile. The fixture used native trusted-proxy authentication, device signatures, explicit roles, matching build admission and provider-scoped plugin activation. This is protocol-level proof with a synthetic memory plugin, not a live Honcho storage migration or visual browser test.
  • Final scoped messaging typecheck, native lint on all 15 changed TypeScript files, format, safety assertions, test-line allocation and line-cap gates passed.
  • The optional aggregate smart check reported an unresolved unused export (sanitizeVerboseQuery in src/daemon/schtasks.integration-observation.test-support.ts) outside the touched files. It is not claimed as a pass or as baseline-proven pre-existing; production/full-tree unused-file inventories and the scoped checks above passed.

Current-main refresh (2026-10-30)

Merged current main 315380c4 without rewriting the original contribution; the PR head is f9ed2281. The conflict resolution preserves both the native transferred-requester profile APIs and this PR's hook observation context.

Validation at the refreshed head: 222 tests across five affected files passed, together with the messaging typecheck, focused lint of all 15 changed TypeScript files, formatting and ratchet checks. The earlier real Gateway/model proof remains evidence for 70a2f514; it has not been repeated at this merge head. Current-head CI gate and security-sensitive-review checks pass at f9ed2281; upstream review/merge remains pending.

Carry the host-bound initiating profile into agent hook observations without
changing transport sender, command, tool, or MCP authority. Recheck the original
requester at each hook boundary and discard personal enrichment or claims that
outlive their source.

Cover shared-session speaker changes, revoked and delegated sources, cached
contexts, and asynchronous result acceptance through the native hook consumers.
Extract the unchanged finalize merge solely to satisfy the existing line cap.
@clawsweeper

clawsweeper Bot commented Oct 29, 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 agents Agent runtime and tooling size: L labels Oct 29, 2026
@apps3000
apps3000 marked this pull request as ready for review October 29, 2026 23:43
@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. 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: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 Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 70a2f514aa0e57a0ff157dcea4ee3d364ee0fd1a, but the PR head is now f9ed2281da0b0f3deb691c4c8ad316c3abb45989. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-10-30T00:00:27.986Z sha 70a2f51 :: needs real behavior proof before merge. :: [P2] Preserve terminal cleanup when the personal requester expires

@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 1, 2026
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]>

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

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant