Skip to content

Conversation

hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Oct 16, 2025

Before
image
image

After
image
image
image

This PR prevents file contents returned by read_file and mention expansions from being stored in ui_messages.json.\n\n- Sanitizes UI-persisted messages at append/update/overwrite/save/load\n- Redacts api_req_started request so file payloads never land in clineMessages

Fixes #8690
Fixes #5601
Fixes #8594


Important

Redacts file contents from UI storage in Task.ts by sanitizing messages, ensuring sensitive data is not stored in ui_messages.json.

This description was created by Ellipsis for 0377592. You can customize this summary. It will automatically update as commits are pushed.

…storing file contents in clineMessages (Fixes #8690)
@hannesrudolph hannesrudolph requested review from Copilot and removed request for Copilot October 16, 2025 23:20
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 16, 2025
Copy link

roomote bot commented Oct 16, 2025

Code Review Complete

I've completed a thorough review of this PR and found no issues that need to be addressed.

Summary

The implementation correctly prevents file contents from being stored in ui_messages.json while maintaining full content in apiConversationHistory. The sanitization approach is well-designed:

✅ Sanitization methods properly redact file payload XML tags
✅ Applied at all persistence points (append/update/overwrite/save/load)
✅ Handles both direct message text and JSON-wrapped requests
✅ Test updates appropriately verify AI responses instead of redacted content
✅ No breaking changes or regressions introduced

The PR successfully addresses issue #8690 and is ready to merge.

@dosubot dosubot bot added the bug Something isn't working label Oct 16, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 16, 2025
@Copilot Copilot AI review requested due to automatic review settings October 17, 2025 00:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR redacts file contents from UI-persisted messages to prevent sensitive data from being stored in ui_messages.json, while preserving full content for the API conversation history.

  • Adds sanitization helpers and applies them at append/update/overwrite/save/load of UI messages
  • Redacts file payloads in api_req_started request formatting
  • Updates e2e tests to validate via AI response rather than clineMessages

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
src/core/task/Task.ts Introduces message sanitization and read_file redaction for UI-persisted messages and api_req_started formatting.
apps/vscode-e2e/src/suite/tools/read-file.test.ts Updates tests to reflect redaction; removes direct content checks from clineMessages (but leaves now-unused variables/extraction logic).

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +1847 to +1877
const formatRequestWithReadFileRedaction = (blocks: Anthropic.Messages.ContentBlockParam[]) => {
let redactNext = false
const parts = blocks.map((block: any) => {
if (block?.type === "text") {
const text = String(block.text ?? "")

// 1) Detect the explicit read_file header line emitted by pushToolResult
const isReadFileHeader = /^\[read_file\b[\s\S]*\]\s*Result:/i.test(text)

// 2) Detect any XML-like file payloads that tools may include
// Examples: <files>...</files>, <file>...</file>, <content ...>...</content>, <file_content ...>...</file_content>
const looksLikeFilePayload = /<files[\s>]|<file[\s>]|<content\b|<file_content\b/i.test(text)

// If we see the header, show the header but redact the next text block (payload)
if (isReadFileHeader) {
redactNext = true
return text
}

// If the previous block was a read_file header, or this block itself looks like a file payload, redact it
if (redactNext || looksLikeFilePayload) {
redactNext = false
return "[tool output omitted from UI storage]"
}
}

// Default formatting for other blocks
return formatContentBlockToMarkdown(block as any)
})
return parts.join("\n\n")
}
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Non-redacted text blocks (including the read_file header) bypass formatContentBlockToMarkdown and return raw text, which diverges from prior behavior and from how non-text blocks are formatted. To keep formatting consistent and avoid UI regressions, return formatContentBlockToMarkdown(block) for the non-redacted text path (and for the header), e.g., replace return text with return formatContentBlockToMarkdown(block as any).

Copilot uses AI. Check for mistakes.

let errorOccurred: string | null = null
let toolExecuted = false
let toolResult: string | null = null
let _toolResult: string | null = null
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

_toolResult is never read after assignment in this test. Remove this variable and the associated extraction/logging code to reduce noise and keep the test focused on verifying AI responses.

Suggested change
let _toolResult: string | null = null

Copilot uses AI. Check for mistakes.

Comment on lines 159 to 164
if (resultMatch) {
toolResult = resultMatch[1]
console.log("Extracted tool result:", toolResult)
_toolResult = resultMatch[1]
console.log("Extracted tool result:", _toolResult)
} else {
console.log("Could not extract tool result from request")
}
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

This extraction/logging block sets _toolResult but the value is no longer asserted, making it dead code. Remove the extraction and console logs to simplify the test.

Copilot uses AI. Check for mistakes.

let toolResult: string | null = null
let _toolResult: string | null = null

// Listen for messages
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

_toolResult is declared but never used in this test case. Remove the variable and the related parsing code added for it.

Copilot uses AI. Check for mistakes.

@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Review] in Roo Code Roadmap Oct 17, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Oct 17, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@hannesrudolph
Copy link
Collaborator Author

Closed in favour of #8696

@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Oct 17, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

2 participants