[Repo Assist] perf(logger): eliminate double sanitize pass per RPC hop - #9521
Merged
lpcox merged 2 commits intoJul 17, 2026
Merged
Conversation
…ToAll Previously, logRPCMessageToAll called SanitizeString (10 compiled regexes) to build text/markdown previews, then LogRPCMessageJSONLWithTags called SanitizeJSON -> SanitizeString again on the same payload bytes — tripling the regex work on the hot logging path. This commit: - Adds SanitizeJSONFromString to the sanitize package: compacts an already-sanitized string into json.RawMessage, skipping the regex pass. - Splits LogRPCMessageJSONLWithTags into a public wrapper (unchanged API) and an internal logRPCMessageJSONLWithTagsAndSanitized that accepts a pre-sanitized json.RawMessage. - Updates logRPCMessageToAll to reuse the sanitized string already computed for preview truncation, eliminating two redundant regex passes per hop. - Adds unit tests for SanitizeJSONFromString including a consistency check and a benchmark for the new fast path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes RPC logging by reusing sanitized payloads across all log sinks.
Changes:
- Adds an already-sanitized JSON compaction path.
- Reuses sanitized payloads for JSONL logging.
- Adds unit tests and a benchmark.
Show a summary per file
| File | Description |
|---|---|
internal/sanitize/sanitize.go |
Adds reusable JSON compaction helper. |
internal/sanitize/sanitize_test.go |
Tests and benchmarks the helper. |
internal/logger/rpc_logger.go |
Reuses sanitized payload for JSONL. |
internal/logger/jsonl_logger.go |
Adds internal pre-sanitized logging path. |
internal/logger/global_state.go |
Updates helper usage documentation. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Medium
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
lpcox
deleted the
repo-assist/perf-avoid-double-sanitize-2954db436af8542a
branch
July 17, 2026 15:09
This was referenced Jul 17, 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 PR was created by Repo Assist, an automated AI assistant.
Summary
Every RPC message that passes through the gateway is logged to three sinks: text, markdown, and JSONL. Before this change,
SanitizeString(10 compiled regex patterns) was called three times per message:logRPCMessageToAllto build the text previewSanitizeJSON→SanitizeStringwhen writing the JSONL entryThis PR eliminates the redundant third pass by reusing the sanitized string that
logRPCMessageToAllalready holds.Changes
internal/sanitize/sanitize.goSanitizeJSONFromString(sanitized string) json.RawMessage: compacts an already-sanitized string without re-running the regex patterns.SanitizeJSONnow delegates to this helper.internal/logger/jsonl_logger.goLogRPCMessageJSONLWithTagsinto a public wrapper (unchanged API) and an internallogRPCMessageJSONLWithTagsAndSanitizedthat accepts a pre-sanitizedjson.RawMessage.internal/logger/rpc_logger.gologRPCMessageToAllto calllogRPCMessageJSONLWithTagsAndSanitizedwithSanitizeJSONFromString(sanitized), reusing the string already computed for preview building.internal/sanitize/sanitize_test.goTestSanitizeJSONFromStringcovering normal, pre-redacted, pretty-printed, and invalid-JSON inputs.TestSanitizeJSONFromString_Consistencyverifying the two-step path produces identical output toSanitizeJSON.BenchmarkSanitizeJSONFromString_Compactfor the new fast path.Impact
On the hot RPC logging path,
SanitizeStringis now called once per message instead of twice. Each call applies 10 compiled regexes across the full JSON payload — typically 0.5–5 KB per message — so this is a measurable saving under load.Test Status
The change is backward-compatible: all existing call sites of
SanitizeJSON,LogRPCMessageJSONL, andLogRPCMessageJSONLWithTagsare unaffected.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