Skip to content

fix: preserve source code in tool results - #127697

Merged
obviyus merged 15 commits into
mainfrom
fix/redact-tool-payload-source-127640
Aug 22, 2026
Merged

obviyus merged 15 commits into
mainfrom
fix/redact-tool-payload-source-127640

Conversation

@jalehman

@jalehman jalehman commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #127640

AI-assisted. I reviewed the implementation and understand the changed redaction boundary.

Problem

Broad diagnostic redaction also rewrote model-visible tool results. Ordinary source expressions such as API_TOKEN = computeToken() became API_TOKEN = ***, so later reads and edits operated on text that never existed in the file.

Root cause and fix

redactToolPayloadText served two incompatible boundaries:

  • logs, diagnostics, errors, and non-tool transcript fields need broad best-effort masking;
  • model-visible tool results need source fidelity.

Model-visible text now masks registered secret values and recognizable credential forms instead of inferring secrecy from ordinary key names. Compact shell assignments, raw JSON source, YAML/TOML/config text, and normal source expressions remain faithful. Structured tool-result fields and payment-credential JSON retain their explicit masking rules.

The read tool applies broad assignment masking only to direct .env-family reads, where the filename is authoritative and the file is a credential store. .envrc and general config files remain source-shaped. Generic exec and plugin output deliberately receive no provenance/taint system: an opaque, unregistered value is not treated as secret merely because it appears beside api_key, token, or a similar identifier. Register actual secrets; recognizable formats and registered values remain masked across producers.

This is the selected security/product boundary. Restoring broad generic masking would reproduce the bug; provenance plumbing would provide porous hygiene rather than a security boundary because arbitrary shell transforms erase origin.

User impact

Agents can read, persist, replay, and edit the same source/config text that exists on disk. Direct .env reads, registered secrets, authorization headers, URL credentials, known token forms, structured sensitive fields, and payment credentials remain masked.

Evidence

Final exact head: a444d12b13b9eb15fc5964c06dbfe5d0eeea7927

  • Owner regression against prior head 2de631bab0716c28a53f5dcefe7cefb6404a08a7: failed because settings.yaml returned api_key: unquot…7890 instead of the stored text.
  • Provider replay regression against prior head 662e2896a7076a8afa3668ac06571b94c94da4f0: failed because JSON source {"token":"timeObserverToken"} became {"token":"***"} inside a structured resource string.
  • Final focused Vitest proof: 613 tests passed across 4 shards, covering provider replay, Anthropic/Mistral serialization, transcript redaction, generic model-visible masking, structured tool-result text, coding-tool boundaries, session guards, subscriptions, and node-worker output.
  • pnpm tsgo: passed.
  • pnpm check:test-types: passed (core, extensions, root).
  • Targeted Oxfmt and Oxlint: passed for all changed files.
  • pnpm docs:list: passed.
  • pnpm docs:check-links: 6,532 internal links checked, 0 broken.
  • git diff --check: passed.
  • Distill: removed config-extension classification, compact-env special patterns, a redundant array copy, and the duplicate JSON string reparse; retained one .env owner rule and the distinct payment-data rule.
  • Greybeard: one path regex per direct read measured ~25 ns/read. Removing the provider JSON parse/stringify reduced 100,000 JSON-shaped string projections from 42.54 ms to 0.71 ms.

Gate status

  • Exact-head CI run 32560606608: every attributable lint, typecheck, security, Windows, and changed-path shard passed. build-artifacts alone remained red after one retry because the Control UI gzip output measured 27-37 bytes above its budget. This PR has no UI diff: HEAD:ui and green main SHA 6e7349be4d8fffb2e677cf7b6a3b13a201b6a11e:ui are the identical tree 690b6a308947850ae145ecfba6af731e3a2e54d5; main passed at 345,042 bytes while identical PR input varied from 345,070 to 345,080 bytes. Unrelated CI variance; no UI budget change belongs in this PR.
  • Exact-head local ClawSweeper: passed on a444d12b13b9eb15fc5964c06dbfe5d0eeea7927 with zero findings, zero security concerns, no maintainer decision, and zero Rank-up moves.
  • Telegram E2E: passed last on a444d12b13b9eb15fc5964c06dbfe5d0eeea7927 through the changed path. A real-user DM triggered the read tool against settings.yaml; the second provider request contained the exact tool result api_key: timeObserverToken, not a masked rewrite. The recording captured SUT typing start/cancel and the final OPENCLAW_TOOL_RESULT_OK reply. Both provider turns completed, the workspace assertion passed byte-for-byte, and temporary SUT state was removed.

@clawsweeper

clawsweeper Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@jalehman
jalehman marked this pull request as ready for review August 22, 2026 00:00
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 22, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 22, 2026
@clawsweeper

clawsweeper Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 22, 2026, 3:23 AM ET / 07:23 UTC.

ClawSweeper review

What this changes

The PR preserves ordinary source and configuration text in model-visible tool results while retaining masking for registered secrets, recognizable credentials, structured sensitive fields, and direct .env reads.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This PR remains necessary: current main still broadly redacts model-visible tool results. The final head cleanly separates source-preserving model context from broader diagnostic redaction, with the security boundary explicitly accepted in discussion; no actionable patch defect was found.

Priority: P1
Reviewed head: 1f9e47ef45a7d4020cefb0401359314a1806e925

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a cohesive, well-covered owner-boundary repair with no actionable review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body also records exact-head focused validation and a redacted Telegram run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body also records exact-head focused validation and a redacted Telegram run.
Evidence reviewed 7 items Current main still has the bug: Current main routes all tool-result strings through broad tool-payload redaction, rather than the PR's model-visible policy, so it has not superseded this branch.
Owner-boundary split: The PR adds a dedicated model-visible policy that omits ambiguous assignment patterns while retaining the full default patterns for structured sensitive fields and diagnostics.
Producer and persistence coverage: Tool completion sanitizes results before emission, direct .env reads receive broad redaction at the read owner, and normalized read details derive from sanitized content.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/logging/redact.test.ts src/agents/transcript-redact.test.ts src/llm/ai-transport-host.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs src/logging/redact.test.ts src/agents/transcript-redact.test.ts src/llm/ai-transport-host.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127697-Q88RV4/target$ node scripts/run-vitest.mjs src/logging/redact.test.ts src/agents/transcript-redact.test.
ts src/llm/ai-transport-host.test.ts
node scripts/run-vitest.mjs src/logging/redact.test.ts src/agents/transcript-redact.test.ts src/llm/ai-transport-host.test.ts
[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127697-Q88RV4/target

 ✓  unit  src/llm/ai-transport-host.test.ts (3 tests) 285ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
   Start at  07:24:43
   Duration  4.15s (transform 2.84s, setup 770ms, import 2.80s, tests 285ms, environment 0ms)

[test] starting test/vitest/vitest.logging.config.ts



































Assertions:

  • PASS expect_output: Test Files

How this fits together

Tool and read results enter agent context, persisted transcripts, and provider request payloads, while logs and diagnostics use separate output paths. This change narrows only the model-visible path so source text stays usable by later agent edits.

flowchart LR
  A[Tool and read output] --> B[Model-visible redaction]
  B --> C[Session transcript]
  C --> D[Provider request payload]
  A --> E[Diagnostic redaction]
  E --> F[Logs and error output]
Loading

Before merge

  • Resolve merge risk (P1) - Merging intentionally leaves opaque, unregistered values in generic model-visible text unmasked; the recorded maintainer decision accepts this boundary and requires actual secrets to be registered at their owner boundary.
  • Complete next step (P2) - No repair lane is needed: this protected maintainer PR has no discrete review defect and remains in normal merge/CI handling.
Agent review details

Security

None.

PR surface

Source +129, Tests +345, Docs +18. Total +492 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 8 206 77 +129
Tests 10 353 8 +345
Docs 2 18 0 +18
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 20 577 85 +492

Review metrics

Metric Value Why it matters
Production versus test LOC production +129; docs +18; tests +345 The production growth is justified by separating model, transcript, provider, and direct-read redaction owners, with focused regressions covering each boundary.

Stored data model

Persistent data-model change detected: serialized state: packages/ai/src/providers/mistral.test.ts, serialized state: packages/ai/src/providers/tool-result-text.ts, serialized state: src/agents/session-tool-result-guard.test.ts, serialized state: src/node-host/node-worker-output.test.ts, unknown-data-model-change: src/agents/session-tool-result-guard.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #127640
Summary: This PR is the concrete candidate fix for the linked model-context source-corruption report.

Members:

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

Merge-risk options

Maintainer options:

  1. Land under the recorded boundary (recommended)
    Accept the documented policy that generic opaque values need registration while recognized credentials and diagnostic surfaces remain masked.

Technical review

Best possible solution:

Keep one explicit model-visible redaction policy, retain broad redaction for diagnostics and non-tool transcript fields, and preserve direct .env handling at the read-tool owner.

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

Yes—source inspection establishes the prior broad assignment patterns and the final head's separate model-visible path; this read-only review did not execute the regression.

Is this the best way to solve the issue?

Yes—the split is the narrowest maintainable fix because the producer, transcript, and provider paths now share a source-fidelity policy while diagnostics retain broad masking.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ff6db34233df.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body also records exact-head focused validation and a redacted Telegram run.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, 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:

  • P1: Silent source corruption in tool context can cause subsequent coding-tool edits to fail.
  • merge-risk: 🚨 security-boundary: The PR deliberately changes what generic tool output is masked before it becomes model context.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body also records exact-head focused validation and a redacted Telegram run.

Evidence

What I checked:

  • Current main still has the bug: Current main routes all tool-result strings through broad tool-payload redaction, rather than the PR's model-visible policy, so it has not superseded this branch. (src/agents/embedded-agent-tool-results.ts:251, ff6db34233df)
  • Owner-boundary split: The PR adds a dedicated model-visible policy that omits ambiguous assignment patterns while retaining the full default patterns for structured sensitive fields and diagnostics. (src/logging/redact.ts:930, 1f9e47ef45a7)
  • Producer and persistence coverage: Tool completion sanitizes results before emission, direct .env reads receive broad redaction at the read owner, and normalized read details derive from sanitized content. (src/agents/agent-tools.read.ts:1061, 1f9e47ef45a7)
  • Provider serialization coverage: Structured provider tool-result blocks use the host's model-visible redactor before JSON projection; the added integration coverage exercises Anthropic and OpenAI-compatible payload construction. (packages/ai/src/providers/tool-result-text.ts:57, 1f9e47ef45a7)
  • Documented security decision: The recorded maintainer decision accepts opaque unregistered values in generic model-visible output while retaining registered, recognizable, structured, and direct-.env masking.
  • Main-only and release check: The PR head is not an ancestor of current main and no local release tag contains it, so the change is neither merged nor shipped. (1f9e47ef45a7)

Likely related people:

  • obviyus: The PR commits and recorded policy decision connect this person to the final model-visible redaction boundary. (role: current boundary contributor; confidence: high; commits: e43de351044f, 76152ee101d6, 1f9e47ef45a7; files: src/logging/redact.ts, src/agents/transcript-redact.ts, src/llm/ai-transport-host.ts)
  • RomneyDa: PR history attributes the initial model-visible redaction-policy split to this contributor. (role: boundary-split contributor; confidence: medium; commits: dcd08362c5d8; files: src/logging/redact.ts, src/agents/embedded-agent-tool-results.ts)
  • Peter Steinberger: Recent history on the broad redaction seam includes repeated maintenance by this contributor, including the current-main implementation predating this PR. (role: pre-existing redaction owner; confidence: medium; commits: f59392fdf5e6, 0d29baae01ad; files: src/logging/redact.ts, src/agents/embedded-agent-tool-results.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-22T02:25:33.019Z sha 628c60e :: found issues before merge. :: [P1] Keep broad masking for diagnostic callers
  • reviewed 2026-08-22T03:01:01.055Z sha dcd0836 :: found issues before merge. :: [P1] Keep broad redaction for non-tool transcript messages
  • reviewed 2026-08-22T03:54:13.184Z sha ddacbad :: found issues before merge. :: [P1] Preserve redaction for unquoted structured credential values
  • reviewed 2026-08-22T04:41:37.110Z sha fc8c660 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T05:00:52.078Z sha fc8c660 :: found issues before merge. :: [P1] Retain masking for unquoted configuration credentials
  • reviewed 2026-08-22T05:47:44.638Z sha 2de631b :: found issues before merge. :: [P1] Keep masking unproven generic tool output
  • reviewed 2026-08-22T05:58:00.572Z sha 2de631b :: found issues before merge. :: [P1] Keep masking unproven generic tool output
  • reviewed 2026-08-22T06:59:21.473Z sha 1f9e47e :: needs maintainer review before merge. :: none

@jalehman jalehman changed the title fix: preserve source code in tool results [AI] fix: preserve source code in tool results Aug 22, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 22, 2026
@RomneyDa

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 22, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Aug 22, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 22, 2026
@obviyus

obviyus commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Maintainer decision: accept the documented model-visible redaction boundary.

Opaque, unregistered values in workspace/tool output are not secrets merely because they appear beside api_key, token, password, or a similar identifier. Registered secret values, recognizable credential forms, direct .env reads, typed structured sensitive fields, payment credential JSON, logs, diagnostics, errors, and non-tool transcript fields retain their applicable masking.

Do not add provenance/taint plumbing or restore broad key-name masking for generic tool output. Either would preserve a porous heuristic while reintroducing source corruption. The supported remedy for an opaque actual secret is registration at its owner boundary.

This resolves the security/product choice raised by the exact-head local review for 662e2896a7076a8afa3668ac06571b94c94da4f0.

@obviyus

obviyus commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

ClawSweeper Rank-up move — intentional skip: this PR is BEHIND but MERGEABLE at exact head 76152ee101d6ac99781854f2843d4c382b90c4e1. The OpenClaw fast lane treats BEHIND as advisory and rebases only CONFLICTING branches. This repair also has an explicit no-force-push constraint. Exact-head CI is running; no base rewrite is warranted.

@obviyus

obviyus commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Exact-head CI run 32558132659 completed for 1f9e47ef45a7d4020cefb0401359314a1806e925.

The repaired redaction owner-boundary test now passes in the full Node shard. Three remaining failures are unrelated to this PR:

  • check-lint-core-5: ui/src/components/markdown.test.ts exceeds the current-main line limit.
  • build-artifacts: current Control UI startup gzip is 21 bytes over its ratchet.
  • checks-node-changed-extensions-config-21: nondeterministic process/closed / process/exited ordering in extensions/codex/src/node-exec-server.test.ts.

This PR changes neither ui/** nor extensions/codex/**; git diff origin/main...HEAD -- ui extensions/codex is empty. Per fast-lane policy these failures are recorded, not patched into this focused repair.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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. labels Aug 22, 2026
@obviyus
obviyus enabled auto-merge (squash) August 22, 2026 08:00
@obviyus
obviyus merged commit 0ab6578 into main Aug 22, 2026
412 of 416 checks passed
@obviyus
obviyus deleted the fix/redact-tool-payload-source-127640 branch August 22, 2026 08:00
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 23, 2026
Preserve opaque source strings across tool-result replay while retaining masking for direct .env reads, registered or recognizable secrets, structured sensitive fields, and payment data.
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 maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. 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

3 participants