[Repo Assist] perf(logger): sanitize RPC payload once for text+markdown previews#8722
Merged
lpcox merged 2 commits intoJul 5, 2026
Merged
Conversation
RPC messages are logged in two formats (text with a 10KB preview and markdown with a 512-byte preview). Previously, logRPCMessageToAll called newRPCMessageInfo twice, which called truncateAndSanitize → SanitizeString twice on the same payload. SanitizeString runs 10 compiled regex patterns over the full payload, so every RPC hop paid that cost twice. This change: - Adds newRPCMessageInfoFromSanitized: builds RPCMessageInfo from an already-sanitized string, only truncating to the desired length. - Adds truncateSanitized: thin wrapper over util.Truncate that signals "this is already sanitized; just truncate". - Updates logRPCMessageToAll to call sanitize.SanitizeString once, then share the sanitized string for both the text and markdown info structs. - Rewrites formatRPCMessage to use strings.Builder + strconv.Itoa instead of []string + append + strings.Join + fmt.Sprintf, eliminating the intermediate slice allocation. No behaviour change: output is identical. The sanitization contract is preserved because newRPCMessageInfoFromSanitized is only called from logRPCMessageToAll after an explicit sanitize.SanitizeString call. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces per-RPC logging overhead in the internal/logger package by ensuring payload sanitization is performed once per message and reused across multiple preview formats, and by reducing allocations in the text RPC formatter.
Changes:
- Added a sanitized-payload path (
newRPCMessageInfoFromSanitized+truncateSanitized) so text + markdown previews share the same sanitization work. - Updated
logRPCMessageToAllto sanitize once and then truncate to the two configured preview lengths. - Rewrote
formatRPCMessageto usestrings.Builder+strconv.Itoato avoid intermediate slice allocations.
Show a summary per file
| File | Description |
|---|---|
| internal/logger/rpc_logger.go | Sanitizes RPC payload once and reuses it for text/markdown previews via a new helper constructor. |
| internal/logger/rpc_format.go | Adds truncateSanitized and optimizes formatRPCMessage to reduce allocations. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Low
Collaborator
|
@copilot fix failing ci |
Contributor
Fixed in 0ee12ef. The CI failure was the |
This was referenced Jul 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist, an AI assistant.
Summary
Each RPC message is logged in two preview formats — a text log (10 KB preview) and a markdown log (512-byte preview). Previously
logRPCMessageToAllcallednewRPCMessageInfotwice, each of which calledtruncateAndSanitize→sanitize.SanitizeString.SanitizeStringruns 10 compiledregexp.Regexp.ReplaceAllStringFunccalls over the full payload, so every RPC hop paid that cost twice.Root Cause
Before: two full sanitization passes per RPC hop:
Fix
newRPCMessageInfoFromSanitized: buildsRPCMessageInfofrom an already-sanitized string, only truncating.truncateSanitized: thin wrapper overutil.Truncateto signal "already sanitized, just truncate".logRPCMessageToAllto callsanitize.SanitizeStringonce and share the result for both previews.formatRPCMessageto usestrings.Builder+strconv.Itoainstead of[]string + append + strings.Join + fmt.Sprintf, eliminating the intermediate slice allocation.After: one sanitization pass shared between both preview lengths:
Trade-offs
newRPCMessageInfoFromSanitizedis only called fromlogRPCMessageToAllafter an explicitsanitize.SanitizeStringcall.newRPCMessageInfois retained for future callers that provide a raw payload.Test Status
proxy.golang.orgis blocked in this sandbox, preventinggo test/make agent-finishedfrom downloading module dependencies. The changes were reviewed for correctness against existing tests:TestFormatRPCMessage— exercisesformatRPCMessageviaRPCMessageInfo; builder-based rewrite produces identical output.TestLogRPCRequest,TestLogRPCResponse,TestLogRPCRequestWithSecrets,TestLogRPCRequestPayloadTruncation— exerciselogRPCMessageToAllthrough the public API; behaviour is unchanged.TestTruncateAndSanitize— teststruncateAndSanitizewhich is unchanged.Warning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
awmgmcpgproxy.golang.orgSee Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run