Skip to content

fix: let input policy hooks inspect prepared images - #196337

Merged
joshavant merged 3 commits into
mainfrom
security/multimodal-input-gate
Nov 10, 2026
Merged

joshavant merged 3 commits into
mainfrom
security/multimodal-input-gate

Conversation

@joshavant

@joshavant joshavant commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Input policy plugins cannot inspect images loaded from local prompt references before an agent turn reaches the model.

User Impact

Plugins using before_agent_run can inspect the prepared current-turn images on embedded, CLI, and Gateway worker runs. Allowed turns submit the inspected bytes, including during CLI recovery; blocked turns stop before inference and input persistence.

Image preparation now performs I/O before the policy decision. The hook's optional images field is absent on older hosts; paired-node CLI images and runners without this hook remain unsupported. No configuration migration is required.

Why This Change Was Made

Prepare images through the existing media owners before calling the gate, give hooks an isolated event copy, and reuse the prepared snapshot for submission and retries. Gateway worker gates use Gateway-owned images, and legacy worker input persistence waits for approval.

This removes post-gate image reloading from the policy-enabled CLI flow and the early legacy-worker persistence path. Production TypeScript changes total +135/-117 lines (net +18); regression tests and fixtures total +240/-78 (net +162). The hook event and CLI fixture now live in existing sibling modules, preserving the public export and test coverage while keeping oversized owners from growing.

Evidence

  • Red/green regression: both vision-enabled prompt-path block/allow cases fail on the original prompt-phase implementation because the hook receives no images, then pass with this change.
  • 212 distinct focused tests across ten files passed during implementation and CI repair: embedded prompt phase (25), hook lifecycle gates (8), CLI reliability (63), worker execution (34), worker admission (12), CLI reply/cron (21), CLI cancellation (14), CLI helpers (12), and CLI session adapter (9), and CLI context-engine lifecycle (14). The CI repair reran 112 CLI consumer tests; after fixture extraction, all 63 reliability and eight hook-gate tests passed again.
  • Static checks passed: core and affected test-graph typechecks, targeted lint, formatting, diff checks, and test-line allocation.
  • AWS product proof passed: full build, including all 162 public SDK subpaths, followed by a real isolated built Gateway/CLI/embedded runner using a synthetic HTTP model provider. The allowed case deletes the image source and mutates the hook copy before submission. Task-owned remote resources were released.
  • Local autoreview: Codex reviewed the initial implementation against base a8d7470fbdcc8c9558dda60a9571697d3976f3f9, snapshot tree 09b7e72e3d9415cc797fd674c3a0525de5347f6a, at P0–P2. Result: scoped-clean, no actionable findings. A fresh P0–P2 autoreview also covered the complete follow-up against beb3731dd31387238b365c5d009f0198321a99f6, tree 9015305e18dd6b472463557731637c5e30a378cd: scoped-clean, no actionable findings. Reviewers did not execute tests; the test results above were run separately.

Sanitized output from the Gateway proof:

{
  "blockedProviderRequests": 0,
  "allowedImageSnapshotMatches": true,
  "sourceDeletedDuringGate": true,
  "hookMutationIsolated": true
}

CI and review follow-up

The first CI run found two branch-related failures. The follow-up preserves the existing undefined execution-options argument for control/isolated paths and reduces the stale assertion allowance from two to one. Both failing CLI cases were reproduced locally before repair and passed afterward.

The first hosted review also requested file-size cleanup. The event type and unchanged CLI fixture were moved into existing sibling modules; strict local line-cap, assertion-safety, and test-line ratchets now pass. No limits or test assertions were weakened.

One concurrent local run hit timeout/unknown recovery failures after over two seconds in fixtures with a one-second retry budget. The unchanged fixture move was verified byte-for-byte apart from export keywords. All four retry cases passed in isolation, followed by all 63 reliability cases in their original order after other checks finished. Load sensitivity remains; these passing reruns are not claimed as a timing fix.

The second hosted review, covering 72d54e273aaa8569a4d256c2b3cbfe973cff5de8, resolved all prior findings and reported no actionable defects. The second CI run found one unused test import left by the fixture move. The mechanical correction removes that import and reduces the exact test-line allocation to 162. Focused CI-mode oxlint checked the affected test with all 293 rules and returned no diagnostics; formatting, the test-line ratchet, and diff checks passed. That run finished with the build and all test shards passing; the unused import was its only substantive failure. The correction is in d72e49c195307b355fc82383d4254158c288e0eb; the final-head CI run completed successfully, including build-artifact checks and openclaw/ci-gate. The final hosted review covers that exact commit and reports no actionable findings; it is ready for maintainer review. Live external-model and Windows-native behavior were not exercised. The AWS build covered the initial implementation and emitted existing Control UI size-budget warnings; the follow-up changes CLI option defaults, type placement, and test structure, with final-head build-artifact checks passing in CI.

@clawsweeper

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

@joshavant
joshavant marked this pull request as ready for review November 10, 2026 00:19
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Nov 10, 2026
@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets input-policy hooks inspect prepared images and reuses those bytes for approved submissions and CLI recovery.

Example: A user sends “Inspect ./picture.png” to a vision-capable agent.

  • Before: The policy hook receives text and history before the image is loaded, so it cannot inspect the image.
  • After: The hook receives the prepared PNG; blocking prevents inference, while approval submits the inspected bytes even if the source file disappears.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused implementation with supplied product-entry proof and meaningful regressions; exact-head CI is still pending, and no stored format or migration changes are introduced.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied terminal output from an isolated built Gateway with a synthetic HTTP model provider exercises image-policy rejection and approved snapshot submission, reporting zero blocked provider requests and matching bytes after source deletion and hook mutation; focused regressions additionally cover CLI recovery and modern/legacy worker admission.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Policy plugins cannot inspect prompt-local images before deciding whether an agent may read them.
Reason: The optional hook extension provides concrete policy value, and collaborator authorship supplies the direction decision for the documented pre-admission I/O tradeoff.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR adds useful image-policy coverage that current main lacks, and no actionable introduced defect remains.

Priority: P2
Reviewed head: d72e49c195307b355fc82383d4254158c288e0eb

Before merge

None.

Findings

None.

Agent review details

How this fits together

Embedded, CLI, and Gateway worker runners prepare user input, invoke plugin admission policy, and then persist approved input and dispatch it to the model.

flowchart TD
  A[User prompt and attachments] --> B[Existing image preparation owners]
  B --> C[Run-owned image snapshot]
  C --> D[Input policy hook with detached copy]
  D --> E[Blocked replacement transcript]
  D --> F[Approved input persistence]
  F --> G[Model submission and CLI recovery]
Loading

Technical review

Best possible solution:

Extend the existing admission hook with a detached image snapshot and reuse that snapshot through approved submission and recovery.

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

Current-main source shows the missing image field and pre-image gate ordering; supplied red/green cases exercise ./picture.png, but this read-only review did not rerun them.

Is this the best way to solve the issue?

The patch uses existing media and admission owners, removes post-gate reloading, and preserves independent transport contracts without adding a competing policy path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9387dfe9910b.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit c81d86e adds src/agents/harness/before-agent-run.ts:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c81d86e82f60; files: src/agents/harness/before-agent-run.ts)
  • Jesse Merhi: Raw commit 1c42c77 adds src/plugins/hook-types.ts:837 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1c42c774339c; files: src/plugins/hook-types.ts)
  • Vito Cappello: Raw commit 9474e55 adds src/agents/cli-runner/helpers.ts:395 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 9474e5507699; files: src/agents/cli-runner/helpers.ts)

PR surface

Source +18, Tests +162, Docs +6, Other +2. Total +188 across 19 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 10 135 117 +18
Tests 6 240 78 +162
Docs 1 9 3 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 2 3 1 +2
Total 19 387 199 +188

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus regression code Production +135/-117; tests and fixtures +240/-78. The small production increase carries image snapshots through existing owners; regression growth covers distinct inference, recovery, mutation-isolation, and worker-persistence boundaries.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a useful, bounded extension for image-aware policy plugins without an established urgent regression.
  • merge-risk: 🚨 compatibility: The public hook gains an optional images field and image preparation moves before admission; the maintainer-authored direction explicitly accepts that ordering change and documents older-host behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • 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 (2 earlier review cycles)
  • reviewed 2026-11-10T00:36:03.864Z sha beb3731 :: needs changes before merge. :: [P2] Update the executor-call assertions for the new options argument | [P2] Keep the expanded files within the existing line-cap ratchets | [P2] Shrink the assertion baseline after removing the CLI cast
  • reviewed 2026-11-10T00:51:04.842Z sha 72d54e2 :: needs maintainer review before merge. :: none

Reviewed November 9, 2026, 8:05 PM ET / November 10, 2026, 01:05 UTC (Revision 3).

@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 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-environment 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@joshavant
joshavant merged commit d7aaafe into main Nov 10, 2026
156 of 157 checks passed
@joshavant
joshavant deleted the security/multimodal-input-gate branch November 10, 2026 01:55
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 10, 2026
* fix: let input policy hooks inspect prepared images

* fix: preserve CLI execution defaults and satisfy ratchets

* test: remove unused CLI fixture import
obviyus added a commit that referenced this pull request Nov 10, 2026
d7aaafe (#196337) deferred legacy worker input persistence until after the policy gate and dropped the missing-admission check with the early persistence path. Input that the runtime already persisted without a readable canonical anchor then acquired credentials, started a tunnel and launched from the stale leaf. Restore the fail-closed check before credentials for already-persisted input; unpersisted input is still admitted after the gate.

Update the detached-context fixtures for the intended ordering: unpersisted input reads its prefix through the transcript open, so the authority-change probes hook that read.

Co-authored-by: obviyus <[email protected]>
obviyus added a commit that referenced this pull request Nov 11, 2026
d7aaafe (#196337) deferred legacy worker input persistence until after the policy gate and dropped the missing-admission check with the early persistence path. Input that the runtime already persisted without a readable canonical anchor then acquired credentials, started a tunnel and launched from the stale leaf. Restore the fail-closed check before credentials for already-persisted input; unpersisted input is still admitted after the gate.

Update the detached-context fixtures for the intended ordering: unpersisted input reads its prefix through the transcript open, so the authority-change probes hook that read.

Co-authored-by: obviyus <[email protected]>
obviyus added a commit that referenced this pull request Nov 11, 2026
…tests broken on main (#196702)

* test(gateway): expect participation refusal after retained sharing facts

Since d53921a (#194129), a broad sessions catalog notification no longer invalidates retained sharing facts; the commit guard rereads membership and refuses the fork with SESSION_PARTICIPATION_REQUIRED, matching the writer-fault variant. The fork still fails with SessionMutationAuthorizationChangedError and leaves storage unchanged.

Co-authored-by: obviyus <[email protected]>

* fix(gateway): reject worker turns with persisted input but no admission

d7aaafe (#196337) deferred legacy worker input persistence until after the policy gate and dropped the missing-admission check with the early persistence path. Input that the runtime already persisted without a readable canonical anchor then acquired credentials, started a tunnel and launched from the stale leaf. Restore the fail-closed check before credentials for already-persisted input; unpersisted input is still admitted after the gate.

Update the detached-context fixtures for the intended ordering: unpersisted input reads its prefix through the transcript open, so the authority-change probes hook that read.

Co-authored-by: obviyus <[email protected]>

* test(qa): prove worker turn admission and authority on the paired-node path

Add a QA script scenario that dispatches a managed-worktree session to a
proof-owned paired-node worker through an isolated Gateway and exercises the
production credential, transport and launch path:

- chat.send and qa-channel turns with a readable admission launch once, reach
  the mock model once and commit their reply;
- cancelling the run or reclaiming the placement while the launch frame is held
  on the node makes the Gateway cancel the launch before the node handles it:
  no worker process starts, the model sees no request and no worker transcript
  or live event is acknowledged.

Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: obviyus <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…tests broken on main (openclaw#196702)

* test(gateway): expect participation refusal after retained sharing facts

Since 4d6df47 (openclaw#194129), a broad sessions catalog notification no longer invalidates retained sharing facts; the commit guard rereads membership and refuses the fork with SESSION_PARTICIPATION_REQUIRED, matching the writer-fault variant. The fork still fails with SessionMutationAuthorizationChangedError and leaves storage unchanged.

Co-authored-by: obviyus <[email protected]>

* fix(gateway): reject worker turns with persisted input but no admission

1acafee (openclaw#196337) deferred legacy worker input persistence until after the policy gate and dropped the missing-admission check with the early persistence path. Input that the runtime already persisted without a readable canonical anchor then acquired credentials, started a tunnel and launched from the stale leaf. Restore the fail-closed check before credentials for already-persisted input; unpersisted input is still admitted after the gate.

Update the detached-context fixtures for the intended ordering: unpersisted input reads its prefix through the transcript open, so the authority-change probes hook that read.

Co-authored-by: obviyus <[email protected]>

* test(qa): prove worker turn admission and authority on the paired-node path

Add a QA script scenario that dispatches a managed-worktree session to a
proof-owned paired-node worker through an isolated Gateway and exercises the
production credential, transport and launch path:

- chat.send and qa-channel turns with a readable admission launch once, reach
  the mock model once and commit their reply;
- cancelling the run or reclaiming the placement while the launch frame is held
  on the node makes the Gateway cancel the launch before the node handles it:
  no worker process starts, the model sees no request and no worker transcript
  or live event is acknowledged.

Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: obviyus <[email protected]>
roboclaw-bot added a commit that referenced this pull request Nov 11, 2026
#197210)

Fresh recorder input is persisted only after image-aware policy admission from #196337. Bootstrap and assembly therefore have no fence yet; retain final admission, exact candidate receipt and after-turn settlement assertions. Three affected-file tests pass.

Co-authored-by: obviyus <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
openclaw#197210)

Fresh recorder input is persisted only after image-aware policy admission from openclaw#196337. Bootstrap and assembly therefore have no fence yet; retain final admission, exact candidate receipt and after-turn settlement assertions. Three affected-file tests pass.

Co-authored-by: obviyus <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 12, 2026
Expose the exact prepared image snapshot to input policy hooks across embedded, CLI, and Gateway worker runners. Reuse CLI prepared input across retries and isolate hook mutations from submitted input.

Release adaptation: retain the existing hook type owner and runtime generation scope. Include the required missing-admission refusal from #196702, selected-branch recorder hydration from #196487, and deferred context-admission assertions from #197210. Do not import unrelated session rewind, prompt continuity, or cold-start owners.

Selected source commits:
(cherry picked from commit d7aaafe)
(partial companion from commit e212ede)
(partial companion from commit ebf6c06)
(partial companion from commit eafa247)

Co-authored-by: obviyus <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Nov 13, 2026
Refresh the complete v2026.11.3..09aa644
history: 99 in-range PRs, 35 issues, and direct-commit editorial coverage.
Preserve all 62 prior contribution records and original main PR credits.
Include typed Telegram callbacks, worker-heartbeat lease renewal, and the
narrow large-store startup adaptations without claiming post-ready recovery.

Source product: 09aa644
Source tree: f10a88c
Main metadata: 3577724
Notes tooling: 514a224

Release provenance: 3768440 -> openclaw#194840, openclaw#179219, openclaw#196984, openclaw#196337
Release provenance: 00275d2 -> openclaw#194362
Release provenance: 66f0339 -> openclaw#186998
Release provenance: 915956a -> openclaw#186998

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: RomneyDa <[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 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

1 participant