fix(mcp): filter debug log lines from audit tool error response#19506
Merged
fix(mcp): filter debug log lines from audit tool error response#19506
Conversation
When the audit tool is called with an invalid run ID and DEBUG=* is set in the environment, the subprocess inherits the env and emits debug initialization logs to stderr. These were being included verbatim in the MCP error response as mainMsg. Add extractLastConsoleMessage() helper that filters debug log lines (e.g. "workflow:script_registry Creating... +151ns") and returns only the last user-facing console message (lines starting with ✗, ✓, ℹ, etc.). The full stderr is still preserved in errorData.stderr for debugging. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix debug initialization logs in MCP error response
fix(mcp): filter debug log lines from audit tool error response
Mar 4, 2026
pelikhan
approved these changes
Mar 4, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Filters noisy debug initialization logs out of the MCP audit tool’s surfaced error message so callers see the intended user-facing console error, while still preserving full stderr in structured error data.
Changes:
- Replaces
strings.TrimSpace(stderr)withextractLastConsoleMessage(stderr)when constructing the MCP error message for theaudittool. - Adds
extractLastConsoleMessagehelper that prefers the last console-prefixed line (✗/✓/ℹ/⚠/etc.) and otherwise falls back to the last non-empty line. - Adds unit tests covering empty/whitespace stderr, debug-only output, mixed output, and multiple console messages.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/cli/mcp_tools_privileged.go | Uses a new helper to extract a user-facing stderr line for MCP audit errors instead of returning full stderr as the message. |
| pkg/cli/mcp_tools_privileged_test.go | Adds unit tests validating the stderr line extraction behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
This was referenced Mar 4, 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.
When
DEBUG=*is set in the MCP server's environment, theauditsubprocess inherits it and emits debug initialization logs to stderr. Because the error handler used the full stderr as the MCP error message, callers received a wall of internal diagnostics instead of the actual error.Changes
mcp_tools_privileged.go: Replacestrings.TrimSpace(stderr)asmainMsgwith a newextractLastConsoleMessagehelper. The helper scans stderr lines and returns the last line prefixed with a console symbol (✗,✓,ℹ,⚠, etc.), falling back to the last non-empty line if none found. Full stderr is still preserved inerrorData.stderr.mcp_tools_privileged_test.go: Unit tests forextractLastConsoleMessagecovering debug-only output, mixed output, empty input, and multiple console message cases.Before —
mainMsgcontained the entire stderr:After — only the user-facing console message:
Warning
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:
https://api.github.com/graphql/usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw GO111MODULE 64/bin/go git rev-�� --show-toplevel go(http block)https://api.github.com/repos/actions/ai-inference/git/ref/tags/v1/usr/bin/gh gh api /repos/actions/ai-inference/git/ref/tags/v1 --jq .object.sha --get remote.origin.url /opt/hostedtoolcache/node/24.13.1/x64/bin/node -json GO111MODULE tions/node_modul--show-toplevel node /tmp�� /git/ref/tags/v8 go /usr/bin/git -json GO111MODULE 1/x64/bin/node git(http block)https://api.github.com/repos/actions/checkout/git/ref/tags/v3/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v3 --jq .object.sha ithub/workflows/audit-workflows.md k/gh-aw/gh-aw/pkg/cli/actionlint.go 7761935/b397/vet.cfg GOSUMDB GOWORK 64/bin/go /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/compile -o /tmp/go-build3484860492/b001/_pkg_.a -trimpath /usr/bin/gh -p main -lang=go1.25 gh(http block)https://api.github.com/repos/actions/checkout/git/ref/tags/v5/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json 18462d14 ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE sh(http block)/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha --show-toplevel go /opt/hostedtoolcache/node/24.13.1/x64/bin/node .js' --ignore-pagit GO111MODULE 64/bin/go node /tmp�� /home/REDACTED/work/gh-aw/gh-aw/.github/workflows/brave.md tDxh6_4/9rUbv3kNTest User /usr/bin/gh -json GO111MODULE 64/bin/go gh(http block)/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha pload-artifact/git/ref/tags/v7 go /usr/bin/infocmp 18462d14:pkg/cligit GO111MODULE x_amd64/link infocmp -1 xterm-color x_amd64/link /usr/bin/git "prettier" --chegit GOPROXY ache/go/1.25.0/x--show-toplevel git(http block)https://api.github.com/repos/actions/checkout/git/ref/tags/v6/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha --show-toplevel(http block)/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha /tmp/gh-aw-test-runs/20260304-051311-37222/test-2019783519 rev-parse g_.a th .prettierignogit GO111MODULE 64/bin/go git init�� GOMODCACHE go ache/go/1.25.0/x64/pkg/tool/linux_amd64/vet -json GO111MODULE de/node/bin/sh ache/go/1.25.0/x64/pkg/tool/linux_amd64/vet(http block)/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha --show-toplevel go /usr/bin/git -json GO111MODULE ache/go/1.25.0/x--show-toplevel git rev-�� --show-toplevel go /usr/bin/git 94/001/test-compgit GO111MODULE 64/pkg/tool/linu--show-toplevel git(http block)https://api.github.com/repos/actions/download-artifact/git/ref/tags/v8/usr/bin/gh gh api /repos/actions/download-artifact/git/ref/tags/v8 --jq .object.sha prettier --check ache/go/1.25.0/x64/bin/go **/*.ts **/*.json 18462d14 node /hom�� 1311-37222/test-2524783878/.github/workflows scripts/**/*.js /opt/hostedtoolcache/go/1.25.0/x64/bin/go .prettierignore GO111MODULE 64/bin/go go(http block)/usr/bin/gh gh api /repos/actions/download-artifact/git/ref/tags/v8 --jq .object.sha -json GO111MODULE g_.a GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE ache/go/1.25.0/x64/pkg/tool/linux_amd64/vet GOINSECURE GOMOD GOMODCACHE ache/go/1.25.0/x64/pkg/tool/linux_amd64/vet(http block)/usr/bin/gh gh api /repos/actions/download-artifact/git/ref/tags/v8 --jq .object.sha 051322571/001 GO111MODULE ache/go/1.25.0/x64/pkg/tool/linux_amd64/compile elete GOMOD 66775556ce06bd83--show-toplevel ache/go/1.25.0/x64/pkg/tool/linux_amd64/compile env 7761935/b416/_pkg_.a GO111MODULE 7761935/b416=> GOINSECURE GOMOD GOMODCACHE git(http block)https://api.github.com/repos/actions/github-script/git/ref/tags/v8/usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha go1.25.0 -c=4 -nolocalimports -importcfg /tmp/go-build3484860492/b001/importcfg -pack /tmp/go-build3484860492/b001/_testmain.go ules�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha -c=4 -nolocalimports -importcfg /tmp/go-build2287761935/b385/importcfg -embedcfg /tmp/go-build2287761935/b385/embedcfg -pack env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha th .prettierignoGOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 1/x64/bin/node GOINSECURE GOMOD igFiles,SwigCXXF/tmp/go-build2287761935/b392/_pkg_.a go(http block)https://api.github.com/repos/actions/setup-go/git/ref/tags/v4/usr/bin/gh gh api /repos/actions/setup-go/git/ref/tags/v4 --jq .object.sha --show-toplevel go /usr/bin/git th .prettierignogit GO111MODULE 64/bin/go git conf�� user.name Test User e/git-remote-https -json GO111MODULE 86_64/sh e/git-remote-https(http block)https://api.github.com/repos/actions/setup-node/git/ref/tags/v4/usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v4 --jq .object.sha /tmp/gh-aw-test-runs/20260304-051311-37222/test-2041707579 rev-parse /usr/bin/git th .prettierignogit GO111MODULE 64/bin/go git init�� GOMODCACHE go /usr/bin/git -json GO111MODULE 1/x64/lib/node_m--show-toplevel git(http block)https://api.github.com/repos/actions/upload-artifact/git/ref/tags/v4/usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v4 --jq .object.sha SameOutput3124576825/001/stability-test.md GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 1/x64/bin/node GOINSECURE GOMOD GOMODCACHE git(http block)https://api.github.com/repos/actions/upload-artifact/git/ref/tags/v7/usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v7 --jq .object.sha -json 18462d14 ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE sh -c 94/001/test-frontmatter-with-arrays.md GOPROXY ache/go/1.25.0/x64/bin/go GOSUMDB GOWORK 18462d14 node(http block)/usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v7 --jq .object.sha 18462d14:pkg/cli/mcp_tools_privileged.go GO111MODULE 86_64/bash GOINSECURE GOMOD GOMODCACHE node /opt�� prettier --check ache/go/1.25.0/x64/bin/go **/*.ts **/*.json --ignore-path go(http block)/usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v7 --jq .object.sha 18462d14:pkg/cli/mcp_tools_privileged.go GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE sh -c 6825/001/stability-test.md GOPROXY ache/go/1.25.0/x64/bin/go GOSUMDB GOWORK 64/bin/go git(http block)https://api.github.com/repos/github/gh-aw/actions/runs/1/artifacts/usr/bin/gh gh run download 1 --dir test-logs/run-1 GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile k/gh�� -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD erignore go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/12345/artifacts/usr/bin/gh gh run download 12345 --dir test-logs/run-12345 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go estl�� -json GO111MODULE n-dir/bash GOINSECURE GOMOD erignore go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/12346/artifacts/usr/bin/gh gh run download 12346 --dir test-logs/run-12346 GO111MODULE 64/bin/go GOINSECURE GOMOD ode-gyp-bin/sh go estl�� -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD erignore go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/2/artifacts/usr/bin/gh gh run download 2 --dir test-logs/run-2 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go k/gh�� -json GO111MODULE ndor/bin/bash GOINSECURE GOMOD erignore go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/3/artifacts/usr/bin/gh gh run download 3 --dir test-logs/run-3 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go k/gh�� -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD erignore go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/4/artifacts/usr/bin/gh gh run download 4 --dir test-logs/run-4 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go k/gh�� -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD erignore go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/5/artifacts/usr/bin/gh gh run download 5 --dir test-logs/run-5 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go k/gh�� -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD erignore go(http block)https://api.github.com/repos/github/gh-aw/actions/workflows/usr/bin/gh gh workflow list --json name,state,path on' --ignore-patGOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 100 GOMOD GOMODCACHE go env leged_test.go GO111MODULE ules/.bin/sh GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 6 GOMOD GOMODCACHE x_amd64/compile env ty-test.md GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.0.0/usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha ty-test.md GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE erignore env -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.2.3/usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.2.3 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/git/ref/tags/v2.0.0/usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE tions/setup/js/node_modules/.binGOMODCACHE GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE ules/.bin/node GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/git/ref/tags/v3.0.0/usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v3.0.0 --jq .object.sha -json GO111MODULE utofind GOINSECURE GOMOD GOMODCACHE utofind env -json GO111MODULE tions/setup/node_modules/.bin/noGOMODCACHE GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/nonexistent/action/git/ref/tags/v999.999.999/usr/bin/gh gh api /repos/nonexistent/action/git/ref/tags/v999.999.999 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE erignore env 1925893531/.github/workflows GO111MODULE ndor/bin/git GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/nonexistent/repo/actions/runs/12345/usr/bin/gh gh run view 12345 --repo nonexistent/repo --json status,conclusion GOINSECURE GOMOD GOMODCACHE x_amd64/vet env ck 'scripts/**/*.js' --ignore-pa-c=4 GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/owner/repo/actions/workflows/usr/bin/gh gh workflow list --json name,state,path --repo owner/repo x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh workflow list --json name,state,path --repo owner/repo 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/owner/repo/contents/file.md/tmp/go-build2287761935/b383/cli.test /tmp/go-build2287761935/b383/cli.test -test.testlogfile=/tmp/go-build2287761935/b383/testlog.txt -test.paniconexit0 -test.v=true -test.parallel=4 -test.timeout=10m0s -test.run=^Test -test.short=true GOINSECURE GOMOD GOMODCACHE go env th .prettierignoGOSUMDB GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/test-owner/test-repo/actions/secrets/usr/bin/gh gh api /repos/test-owner/test-repo/actions/secrets --jq .secrets[].name -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[cli-tools-test] audit: debug initialization logs leaked in MCP error response for invalid run IDs</issue_title>
<issue_description>## Problem Description
When the
audittool is called with an invalid or non-existent run ID via the MCP server, the error response includes verbose internal debug/initialization log output mixed with the actual error message. The real error is buried at the end of a wall of diagnostic output, making it hard to identify the actual problem.Tool
auditSteps to Reproduce
agenticworkflowsMCP tool'sauditcommand with a non-existent run ID (e.g.,99999999999)Expected Behavior
A clean error message like:
The debug logger initialization messages (using the
loggerpackage withpkg:filenamenamespace format) are being captured from stderr and included verbatim in the MCP error message.Root Cause
The MCP server appears to capture the binary's stderr output and include it in the error message. When debug logging is active (or when initialization logs are emitted unconditionally), these get bundled into the error response returned to the caller.
Environment
Impact
The issue degrades developer experience when troubleshooting audit failures, as the actual error is obscured by internal diagnostic output. It also exposes internal implementation details (module names, timing data) to end users.
Suggested Fix
Either:
DEBUGenv var not set)Comments on the Issue (you are @copilot in this section)
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.