Skip to content

fix: keep unused Code Mode lookups from tainting memory - #201519

Merged
roboclaw-bot merged 2 commits into
mainfrom
openclaw/code-mode-provenance-196857
Nov 21, 2026
Merged

roboclaw-bot merged 2 commits into
mainfrom
openclaw/code-mode-provenance-196857

Conversation

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Closes #196857

What Problem This Solves

Unused Code Mode tool lookups could mark an entire turn as external content and quarantine session-memory snapshots. At the same time, the host memory-write observer missed Code Mode’s per-result provenance and could leave genuinely consumed external metadata trusted.

User Impact

Unused discovery no longer makes later owner-requested memory writes untrusted. Consumed or emitted external metadata, MCP declarations, and network tool results retain their existing provenance protections. Previously quarantined files are not reclassified; there is no migration or configuration change.

Why This Change Was Made

Code Mode returns lazy callable handles, so its guest already records when external metadata is read or serialized. Stop eagerly marking unused search hits, and forward the existing per-result provenance to the host’s memory-taint observer instead of looking only at static tool metadata. Ordinary Tool Search, execution, stored-value provenance, and memory classification policy are otherwise unchanged.

Evidence

  • Reproduced unused-search turn taint on base c5ef395. Isolated real-model Gateway testing also exposed the host observer’s missing dynamic provenance; the production-wrapper memory regression fails on consumed descriptions, emitted handles, and declarations until that observer is fixed.
  • The same memory regression passes with the fix; reading a description (even when discarded), returning a handle, and reading a declaration still produce untrusted memory.
  • Focused suites: 78 tests passed across Agent-loop, Code Mode output, Tool Search metadata, and network-error provenance suites. Changed test file: 26 tests, 16.51 seconds wall time (CI timing pending).
  • Core and affected test typechecks, targeted lint, formatting, changed-page MDX, and git diff --check passed. Full pnpm build passed (2m 58s), followed by a final pnpm build:runtime (1m 8s); it reported non-fatal Control UI asset-budget warnings in unchanged UI code.
  • An isolated Gateway with a real agent, provider model, and loopback MCP server verified both paths with zero MCP tool executions: unused discovery produced agent memory; consuming the external description produced fenced output and untrusted memory. The Gateway, sockets, and temporary state were cleaned up. Live test: 36.65 seconds wall time.
  • Local autoreview (P0–P2) of the final pre-commit snapshot against c5ef395: scoped-clean, no actionable findings. The committed patch at 5be12fe is byte-identical to that reviewed snapshot. The reviewer inspected the supplied source context but did not rerun tests.

Simplification: remove the duplicate eager observation and reuse the existing internal result-source fact. No new state, owner, public option, trust exception, or provenance mechanism. Production delta: +8/-3 lines; tests: +91/-2; docs: +7. The small production growth forwards the existing source fact into the memory observer.

Contributor credit

Reported by @Ricardodpalmeida. Fix requested and directed by @vincentkoc.

Work sessions

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

Worked on by

roboclaw-bot and others added 2 commits November 18, 2026 22:28
Worked on by:
- @vincentkoc

Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: 8916587d-3637-4ea5-bc69-68ba8b3f4238
@clawsweeper

clawsweeper Bot commented Nov 18, 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: S labels Nov 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes Code Mode discovery taint depend on metadata exposure and forwards dynamic result provenance to the memory observer.

Example: An owner turn searches for remote_metadata, leaves its handle unused, then writes memory/catalog.md in a later cell.

  • Before: The unused MCP search hit taints the transcript and can quarantine the session-memory snapshot.
  • After: Unused discovery stays untainted; reading the external description still makes subsequent memory writes untrusted.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and source-supported, but the reported shipped-entry-point verification lacks inspectable evidence.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Unused tool discovery can mark an otherwise trusted owner turn as external content and quarantine its session memory.
Reason: The maintainer-authored direction addresses a documented user problem with existing owners and preserves consumed-metadata protection; recovery of previously quarantined files remains explicitly outside scope.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides a focused repair for unnecessary memory quarantine that remains on current main, and no introduced correctness defect was found.

Priority: P2
Reviewed head: 75414f2282a883ba62ecd9acdf2753f757007344

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Publish redacted terminal output or logs from the reported Gateway run showing unused discovery producing agent memory and consumed metadata producing untrusted memory, with secrets, IPs, phone numbers, and non-public endpoints removed.
Agent review details

How this fits together

Code Mode translates guest catalog operations into host tool calls; exposure markers flow through result formatting into transcript taint and memory-write classification.

flowchart LR
  A[Guest catalog search] --> B[Lazy callable handles]
  B --> C[Metadata exposure tracking]
  C --> D[Result provenance]
  D --> E[Host turn observer]
  E --> F[Memory classification]
Loading

Technical review

Best possible solution:

Keep the existing lazy exposure tracker and shared result-provenance mechanism as the sole sources for this distinction.

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

Current-main source establishes eager catalog-hit marking and transcript taint; the PR supplies a production-wrapper memory regression and reports red/green verification, which this read-only review did not execute.

Is this the best way to solve the issue?

The patch is the smallest complete repair for the stated boundary: remove redundant eager observation, consume the existing dynamic provenance fact, and retain distinct exposure regressions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 07baab52b414.

Provenance checked

  • Code Mode eager discovery observation changes intended behavior with a stated reason (4b2b593: MCP task discovery intentionally preserved remote metadata provenance; a later refactor routed observation through the search parent-call ID.)
  • Host memory-taint observation keeps the original intent (20668ee: Tool outcomes drive sticky current-turn taint so attacker-influenced memory writes remain untrusted.)
  • Private dynamic result provenance keeps the original intent (4cb9f12: Dynamic Tool Search and Code Mode controls need per-result network provenance because their static declarations cannot describe each nested call.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3c30925 adds src/agents/agent-tools.before-tool-call.wrapper.ts:477 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3c309257bbc7; files: src/agents/agent-tools.before-tool-call.wrapper.ts)

PR surface

Source +5, Tests +89, Docs +7. Total +101 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 8 3 +5
Tests 1 91 2 +89
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 106 5 +101

Preflight source

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

Labels

Label changes:

  • add P2: Unused discovery can unnecessarily quarantine session memory in an advanced Code Mode workflow, without a demonstrated core-runtime outage.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Unused discovery can unnecessarily quarantine session memory in an advanced Code Mode workflow, without a demonstrated core-runtime outage.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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.

Reviewed November 18, 2026, 6:41 PM ET / 23:41 UTC.

@roboclaw-bot
roboclaw-bot merged commit 9bb091e into main Nov 21, 2026
138 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/code-mode-provenance-196857 branch November 21, 2026 01:56
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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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.

Code Mode catalog search taints the turn with no network call, so memory writes become permanently untrusted

1 participant