Refactor: Consolidate shutdown middleware, centralize session utilities, remove deprecated wrappers #483
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.
Addresses code duplication and organizational issues identified in semantic function clustering analysis: duplicate shutdown middleware (~95% identical), misplaced session truncation utility, and actively-used deprecated wrapper.
Changes
Shutdown Middleware Consolidation
rejectIfShutdown()andrejectIfShutdownUnified()into single parameterized functionlogNamespaceparameter for call-site specific debug loggingSession Utilities to Auth Package
truncateSession()frominternal/server/sdk_logging.gotointernal/auth/header.goas exportedTruncateSessionID()Deprecated Wrapper Removal
extractSessionFromAuth()wrapper that delegated toauth.ExtractSessionID()auth.ExtractSessionID()directlyImpact
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:
nonexistent.local/tmp/go-build2901014057/b269/launcher.test /tmp/go-build2901014057/b269/launcher.test -test.testlogfile=/tmp/go-build2901014057/b269/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a 64/src/internal/crypto/tls ndor/bin/as user.name abis(dns block)this-host-does-not-exist-12345.com/tmp/go-build2901014057/b278/mcp.test /tmp/go-build2901014057/b278/mcp.test -test.testlogfile=/tmp/go-build2901014057/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/cgo --global ache/go/1.25.6/x64/pkg/tool/linu--64 user.name(dns 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>[refactor] Semantic Function Clustering Analysis - Minor Code Organization Improvements</issue_title>
<issue_description>Analysis of repository: githubnext/gh-aw-mcpg
Executive Summary
Analyzed 48 non-test Go files across 14 packages containing approximately 362 functions/methods (both exported and unexported). The codebase demonstrates excellent organization with strong use of Go generics, clear separation of concerns, and well-structured packages. Identified 3 actionable refactoring opportunities that can improve code organization and reduce duplication.
Key Findings:
Function Inventory Summary
By Package
internal/authinternal/cmdinternal/configinternal/difcinternal/guardinternal/launcherinternal/loggerinternal/mcpinternal/middlewareinternal/serverinternal/sysinternal/testutilinternal/timeutilinternal/ttyTotal: 48 files, 362 functions/methods
Semantic Clustering Results
Major Function Patterns Identified:
New*constructorsvalidate*)Close()methodsLog*)format*)parse*)Identified Issues
1. 🔴 Duplicate Shutdown Middleware (Critical - High Impact)
Issue: Two nearly identical functions for shutdown rejection middleware
Occurrences:
internal/server/routed.go:21-33-rejectIfShutdown()internal/server/transport.go:18-30-rejectIfShutdownUnified()Code Comparison:
Analysis:
logRoutedvslogTransport)Recommendation:
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.