Skip to content

fix(engine): redact tool_result output in chat-grounding (#8869) - #9105

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
RealDiligent:fix/critical-issue-chat-grounding-toolresult-redact-8869
Jul 26, 2026
Merged

fix(engine): redact tool_result output in chat-grounding (#8869)#9105
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
RealDiligent:fix/critical-issue-chat-grounding-toolresult-redact-8869

Conversation

@RealDiligent

Copy link
Copy Markdown
Contributor

Problem

Closes #8869.

packages/loopover-engine/src/miner/chat-grounding.ts documents a redaction invariant: every outgoing chunk is checked against PUBLIC_FIELD_BLOCKLIST and redacted. foldAssistantMessage honors it (redactBlockedText(block.text)), but foldToolResultMessage forwarded block.content — an MCP tool's own output — verbatim, with no redaction. A blocklisted field (wallet, payout, trust score, …) in a tool's result therefore leaked straight into the public-facing chat-grounding stream.

Fix

Scan the tool_result content against the same PUBLIC_FIELD_BLOCKLIST before yielding, and on a hit replace the whole output with CHAT_REDACTED_TEXT — matching redactBlockedText's established replace-not-filter policy. The scan handles every shape a tool result takes: a plain string, an SDK content-block array, or an object where the blocked term appears as a key (a payout field) or nested in a value. Clean output of any shape passes through unchanged.

Test

test/unit/chat-grounding-engine.test.ts (the codecov-visible vitest that imports the engine source) adds a case driving runChatGrounding with blocked tool_result content in each shape — string, content-block array, and nested object key — asserting each is replaced with the sentinel, while clean string / array / primitive outputs pass through verbatim. 100% patch coverage (statements + branches) on the changed file. The existing clean-{} pass-through test is unaffected.

@RealDiligent
RealDiligent requested a review from JSONbored as a code owner July 26, 2026 17:47
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

foldAssistantMessage runs every outgoing text chunk through the
PUBLIC_FIELD_BLOCKLIST backstop, but foldToolResultMessage forwarded an MCP
tool's own output verbatim -- so a blocklisted field in a tool's result
leaked into the public-facing chat-grounding stream unredacted.

Scan the tool_result content (string, content-block array, or object where
the term can appear as a key or value) against the same blocklist and, on a
hit, replace the whole output with the redaction sentinel -- matching
redactBlockedText's replace-not-filter policy.
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.88%. Comparing base (9df67ed) to head (13c1b21).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9105      +/-   ##
==========================================
- Coverage   93.88%   93.88%   -0.01%     
==========================================
  Files         810      810              
  Lines       80600    80606       +6     
  Branches    24454    24458       +4     
==========================================
+ Hits        75675    75677       +2     
  Misses       3560     3560              
- Partials     1365     1369       +4     
Flag Coverage Δ
backend 95.17% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ckages/loopover-engine/src/miner/chat-grounding.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 26, 2026
@loopover-orb

loopover-orb Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-26 18:04:46 UTC

2 files · 1 AI reviewer · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This closes #8869 by adding a `toolResultContentIsBlocked` scan that recursively checks a tool_result's string/array/object content against `PUBLIC_FIELD_BLOCKLIST` and, on a hit, replaces the whole output with `CHAT_REDACTED_TEXT` before yielding — matching the existing replace-not-filter policy `redactBlockedText` already applies to assistant text. The recursive traversal correctly handles the three real shapes an MCP tool_result can take (string, SDK content-block array, nested object with a blocked key or value) and the new vitest cases exercise all three plus clean pass-through for each shape. This is a narrow, well-targeted fix directly tied to the linked issue with no scope creep.

Nits — 3 non-blocking
  • chat-grounding.ts: `toolResultContentIsBlocked` recurses into arbitrary values/keys but doesn't guard against cyclic structures or pathological depth — unlikely from an MCP tool's own JSON output, but worth a one-line comment noting the assumption if it isn't already covered elsewhere.
  • test/unit/chat-grounding-engine.test.ts: the new test's helper `toolResultOutput` duplicates a decent amount of `runChatGrounding` boilerplate already present in `queryYielding`/`collect` above it — could be trimmed by reusing `queryYielding` directly, but it's a minor readability point only.
  • Consider whether `toolResultContentIsBlocked` should also be exported and unit-tested directly (like `containsBlockedTerm`) rather than only indirectly through `runChatGrounding`, for a faster failure signal if the recursion logic regresses.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8869
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 295 registered-repo PR(s), 124 merged, 37 issue(s).
Contributor context ✅ Confirmed Gittensor contributor RealDiligent; Gittensor profile; 295 PR(s), 37 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff adds a toolResultContentIsBlocked scan covering strings, arrays, and nested object keys/values, applies it in foldToolResultMessage before yielding (replacing with CHAT_REDACTED_TEXT on a hit), matching foldAssistantMessage's redaction policy, and adds a test asserting blocked tool_result content across shapes is redacted while clean content passes through.

Review context
  • Author: RealDiligent
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, Ruby, TypeScript, Svelte, Cuda, JavaScript, Markdown, MDX
  • Official Gittensor activity: 295 PR(s), 37 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 5e8346f into JSONbored:main Jul 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(engine): chat-grounding tool_result events bypass the privacy redaction backstop

1 participant