Conversation
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/ac7dc66f-a385-4612-8f8a-66a15160508c Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/ac7dc66f-a385-4612-8f8a-66a15160508c Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix duplicate code patterns in codebase
Refactor duplicated marshal/log paths and unify sanitized sys tool response logging
Apr 18, 2026
Copilot stopped work on behalf of
lpcox due to an error
April 18, 2026 16:28
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors duplicated JSON-marshal-for-logging code paths and centralizes sys-tool call/error/log handling, while ensuring sys tool responses (notably sys_list_servers) are sanitized before being written to logs.
Changes:
- Added
logger.LogMarshaledForDebug(...)and replaced repeated marshal+log blocks in guard/server DIFC paths. - Introduced
callAndLogSysTool(...)andmarshalAndSanitizeForLog(...)to unify sys tool call flow and sanitize sys tool response logging. - Added focused unit tests covering marshal-debug behavior and sanitization/error behavior in the sys-tool helper path.
Show a summary per file
| File | Description |
|---|---|
| internal/server/tool_registry.go | Consolidates response marshaling+sanitization for logging and unifies sys tool call/log flow. |
| internal/server/tool_registry_test.go | Adds coverage for sanitization redaction and sys-tool error result behavior. |
| internal/server/guard_init.go | Replaces duplicated marshal-for-debug logging with shared helper. |
| internal/guard/wasm.go | Replaces duplicated marshal-for-debug logging with shared helper in WASM guard label flow. |
| internal/logger/marshal_debug.go | Adds shared helper to marshal values for debug logging with success/failure callbacks. |
| internal/logger/marshal_debug_test.go | Tests success and marshal-failure paths for the new marshal-debug helper. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 0
This was referenced Apr 18, 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.
Recent
SendRequestWithServerIDcleanup left three duplication/safety gaps: repeated marshal-for-debug blocks, duplicated sys tool handler skeletons, and unsanitizedsys_list_serversresult logging. This PR consolidates those paths and closes the sanitization gap.Consolidate marshal-for-debug logic
logger.LogMarshaledForDebug(...)ininternal/logger/marshal_debug.go.internal/guard/wasm.gointernal/server/guard_init.goUnify sys tool call/error/log skeleton
callAndLogSysTool(...)ininternal/server/tool_registry.go.sysInitHandlerandsysListHandlernow share one call path (call sys server → handle error → marshal/log result → return).Fix sanitization gap in
sys_list_serversloggingmarshalAndSanitizeForLog(...)intool_registry.go.sys_list_serversresponse logs now usesanitize.SanitizeString(...), matchingsys_initand backend tool logging behavior.Focused test coverage
internal/logger/marshal_debug_test.gointernal/server/tool_registry_test.goWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build1793350213/b510/launcher.test /tmp/go-build1793350213/b510/launcher.test -test.testlogfile=/tmp/go-build1793350213/b510/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 3350213/b184/_pk-errorsas 64/src/log/slog/-ifaceassert bin/as -p zevo/backend/isa-atomic -lang=go1.25 /opt/hostedtoolc-buildtags -o s/attributes.go idRS/k9xnSFeesAm-ifaceassert x_amd64/compile -p crypto/internal/info -lang=go1.25 x_amd64/compile(dns block)/tmp/go-build3990767025/b514/launcher.test /tmp/go-build3990767025/b514/launcher.test -test.testlogfile=/tmp/go-build3990767025/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3990767025/b495/vet.cfg ry=1 -trimpath x_amd64/vet -p github.com/githupush -lang=go1.25 x_amd64/vet -ato�� .cfg -buildtags 64/pkg/tool/linux_amd64/vet -errorsas -ifaceassert -nilfunc 64/pkg/tool/linu-trimpath(dns block)/tmp/go-build848674421/b514/launcher.test /tmp/go-build848674421/b514/launcher.test -test.testlogfile=/tmp/go-build848674421/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s know�� l/server/tool_registry_test.go known-linux-gnu/lib/rustlib/x86_--format=format:%H %ct %D stable-x86_64-REDACTED-linux-gnu/--end-of-options 6e1dc71b.rlib ccc.rlib --systemd-cgroup-bool(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build1793350213/b492/config.test /tmp/go-build1793350213/b492/config.test -test.testlogfile=/tmp/go-build1793350213/b492/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 3350213/b151/_pk-p o x_amd64/compile(dns block)/tmp/go-build3990767025/b496/config.test /tmp/go-build3990767025/b496/config.test -test.testlogfile=/tmp/go-build3990767025/b496/testlog.txt -test.paniconexit0 -test.timeout=10m0s n-me�� g_.a pkg/mod/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp@v1.43.0/doc.go x_amd64/vet -p github.com/segme--norc -lang=go1.17 x_amd64/vet -ato�� MQJZCSQ0B -buildtags x_amd64/vet -errorsas -ifaceassert -nilfunc ks..."; \ elif c--revs(dns block)/tmp/go-build848674421/b496/config.test /tmp/go-build848674421/b496/config.test -test.testlogfile=/tmp/go-build848674421/b496/testlog.txt -test.paniconexit0 -test.timeout=10m0s 05ed�� 05ed-cgu.10.rcgu-errorsas 05ed-cgu.11.rcgu-ifaceassert 05ed-cgu.12.rcgu-nilfunc 05ed-cgu.13.rcgugit 05ed-cgu.14.rcguls-files pt_build-842ae9a--exclude-standard pt_build-842ae9a--others /usr�� --root .rlib 6b2b26a06.rlib 327.rlib 653.rlib 86b29d.rlib ive.12123747d8da05ed-cgu.00.rcgu.o(dns block)nonexistent.local/tmp/go-build1793350213/b510/launcher.test /tmp/go-build1793350213/b510/launcher.test -test.testlogfile=/tmp/go-build1793350213/b510/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 3350213/b184/_pk-errorsas 64/src/log/slog/-ifaceassert bin/as -p zevo/backend/isa-atomic -lang=go1.25 /opt/hostedtoolc-buildtags -o s/attributes.go idRS/k9xnSFeesAm-ifaceassert x_amd64/compile -p crypto/internal/info -lang=go1.25 x_amd64/compile(dns block)/tmp/go-build3990767025/b514/launcher.test /tmp/go-build3990767025/b514/launcher.test -test.testlogfile=/tmp/go-build3990767025/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3990767025/b495/vet.cfg ry=1 -trimpath x_amd64/vet -p github.com/githupush -lang=go1.25 x_amd64/vet -ato�� .cfg -buildtags 64/pkg/tool/linux_amd64/vet -errorsas -ifaceassert -nilfunc 64/pkg/tool/linu-trimpath(dns block)/tmp/go-build848674421/b514/launcher.test /tmp/go-build848674421/b514/launcher.test -test.testlogfile=/tmp/go-build848674421/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s know�� l/server/tool_registry_test.go known-linux-gnu/lib/rustlib/x86_--format=format:%H %ct %D stable-x86_64-REDACTED-linux-gnu/--end-of-options 6e1dc71b.rlib ccc.rlib --systemd-cgroup-bool(dns block)slow.example.com/tmp/go-build1793350213/b510/launcher.test /tmp/go-build1793350213/b510/launcher.test -test.testlogfile=/tmp/go-build1793350213/b510/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 3350213/b184/_pk-errorsas 64/src/log/slog/-ifaceassert bin/as -p zevo/backend/isa-atomic -lang=go1.25 /opt/hostedtoolc-buildtags -o s/attributes.go idRS/k9xnSFeesAm-ifaceassert x_amd64/compile -p crypto/internal/info -lang=go1.25 x_amd64/compile(dns block)/tmp/go-build3990767025/b514/launcher.test /tmp/go-build3990767025/b514/launcher.test -test.testlogfile=/tmp/go-build3990767025/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3990767025/b495/vet.cfg ry=1 -trimpath x_amd64/vet -p github.com/githupush -lang=go1.25 x_amd64/vet -ato�� .cfg -buildtags 64/pkg/tool/linux_amd64/vet -errorsas -ifaceassert -nilfunc 64/pkg/tool/linu-trimpath(dns block)/tmp/go-build848674421/b514/launcher.test /tmp/go-build848674421/b514/launcher.test -test.testlogfile=/tmp/go-build848674421/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s know�� l/server/tool_registry_test.go known-linux-gnu/lib/rustlib/x86_--format=format:%H %ct %D stable-x86_64-REDACTED-linux-gnu/--end-of-options 6e1dc71b.rlib ccc.rlib --systemd-cgroup-bool(dns block)this-host-does-not-exist-12345.com/tmp/go-build1793350213/b519/mcp.test /tmp/go-build1793350213/b519/mcp.test -test.testlogfile=/tmp/go-build1793350213/b519/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true transport/bdp_estimator.go transport/client_stream.go x_amd64/compile -pthread e/otlptracehttp/--version -fmessage-length=0 x_amd64/compile 3350�� g_.a 3350213/b165/ x_amd64/vet --gdwarf-5 mcpgodebug -o x_amd64/vet(dns block)/tmp/go-build3990767025/b523/mcp.test /tmp/go-build3990767025/b523/mcp.test -test.testlogfile=/tmp/go-build3990767025/b523/testlog.txt -test.paniconexit0 -test.timeout=10m0s -ato�� .cfg -buildtags 0278e5566a20dc05-d -errorsas -ifaceassert -nilfunc 64/pkg/tool/linu-buildtags --ve�� .cfg -tests 64/pkg/tool/linu-nilfunc 1024825-9d38bb40/usr/bin/runc.original toml@v1.6.0/depr--version x_amd64/compile 64/pkg/tool/linu-tests(dns block)/tmp/go-build848674421/b523/mcp.test /tmp/go-build848674421/b523/mcp.test -test.testlogfile=/tmp/go-build848674421/b523/testlog.txt -test.paniconexit0 -test.timeout=10m0s ogpt�� q7jvxzdnkys32nfz-errorsas 0ok7l9sshaaz07e8-ifaceassert hw1mmy6a1aekmmsh-nilfunc 4p2kq4dabhq5b2kedocker wmuqycv01jbjtq95inspect ntained/cc stable-x86_64-un{{.Config.OpenStdin}} stab�� stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libobject-926daa94a00ee/usr/libexec/docker/docker-init stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libmemchr-48d5b0db80402--version .1/x64/codeql/tools/linux64/java/lib/jspawnhelper stable-x86_64-un/usr/libexec/docker/cli-plugins/docker-compose 7a5585.0r6f2y9pmdocker-cli-plugin-metadata 7a5585.0y8i0suihruczucboywd9kbz6/tmp/go-build985941549/b001/_pkg_.a .1/x64/codeql/tools/linux64/java-trimpath(dns block)If you need me to access, download, or install something from one of these locations, you can either: