refactor: semantic function clustering — collaborator helpers, SessionSuffix, middleware split, AgentTagsSnapshot#7633
Merged
Conversation
…pers, SessionSuffix, middleware split, AgentTagsSnapshot
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering based on analysis
refactor: semantic function clustering — collaborator helpers, SessionSuffix, middleware split, AgentTagsSnapshot
Jun 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors several cross-cutting helpers to better align with package responsibilities, reduce unnecessary dependencies (notably server → proxy), and split an overgrown middleware file into focused units.
Changes:
- Moved collaborator-permission REST helpers from
proxyinto sharedinternal/httputil, updating server/proxy call sites and relocating tests. - Moved
SessionSuffixfromloggertostrutiland updated launcher call sites and tests. - Split
internal/server/middleware.gointo smaller files and co-locatedAgentTagsSnapshotwith its context key ininternal/mcp/connection.go.
Show a summary per file
| File | Description |
|---|---|
| internal/strutil/session_suffix.go | Adds strutil.SessionSuffix utility. |
| internal/strutil/session_suffix_test.go | Moves SessionSuffix tests into strutil package. |
| internal/logger/common.go | Removes logger.SessionSuffix after relocation. |
| internal/launcher/log_helpers.go | Updates launcher logging to use strutil.SessionSuffix. |
| internal/httputil/collaborator.go | Moves collaborator permission helpers into shared HTTP utilities. |
| internal/httputil/collaborator_test.go | Relocates collaborator helper unit tests into httputil. |
| internal/proxy/proxy.go | Switches proxy collaborator calls to httputil helpers. |
| internal/server/unified.go | Removes proxy dependency by using httputil collaborator helpers. |
| internal/server/middleware.go | Leaves core middleware wiring/config; removes auth + SDK logging implementations. |
| internal/server/middleware_auth.go | New file containing API-key auth middleware and helpers. |
| internal/server/sdk_logging.go | New file containing SDK HTTP boundary logging helpers. |
| internal/mcp/connection.go | Moves AgentTagsSnapshot type/accessor next to context key. |
| internal/mcp/connection_logging.go | Removes relocated AgentTagsSnapshot code from logging file. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 13/13 changed files
- Comments generated: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Automated semantic analysis identified six misplaced functions and one over-stuffed file. Addresses all four priorities.
Priority 1 — Remove
server → proxydependencyParseCollaboratorPermissionArgs,FetchCollaboratorPermission, andLogAndWrapCollaboratorPermissionwere inproxy/despite serving bothproxyandserver. This forcedserver/unified.goto importproxy, requiring an injected-logPrintfworkaround to avoid circularity.internal/httputil/collaborator.go(existing shared HTTP utilities package)proxy/collaborator_permission.goproxy/proxy.goandserver/unified.go; removedproxyimport fromserver/unified.gointernal/httputil/collaborator_test.goPriority 2a —
SessionSuffix→strutillogger.SessionSuffixis a pure string formatter with no logger state, called only fromlauncher/log_helpers.go.internal/strutil/session_suffix.golauncher/log_helpers.goimport; moved test tostrutil/session_suffix_test.goPriority 2b — Split
server/middleware.go(316 lines, 5 concerns)middleware_auth.goapplyIfConfigured,authMiddleware,rejectAuthRequest,applyAuthIfConfiguredsdk_logging.goWithSDKLogging,withResponseLoggingmiddleware.go(~120 lines residual)WithOTELTracing,wrapWithMiddleware,buildMCPHandlerPriority 3 — Co-locate
AgentTagsSnapshotwith its context keyAgentTagsSnapshotandGetAgentTagsSnapshotFromContextlived inconnection_logging.gowhileAgentTagsSnapshotContextKeywas inconnection.go. Moved the type and accessor toconnection.go.