Skip to content

refactor: move outlier functions to semantically correct files#6152

Merged
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering
May 21, 2026
Merged

refactor: move outlier functions to semantically correct files#6152
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

Automated semantic clustering of 811 functions across 14 packages identified 3 misplaced functions and 1 over-broad file. This PR moves each to where a developer would naturally look for it.

Changes

  • mcp/errors.gomcp/connection_logging.go: ConnectionErrorContext + LogConnectionError belonged with the other connection diagnostic helpers (logReconnectStart, logOutboundRPCRequest, etc.), not in a file conventionally reserved for error type definitions. errors.go deleted.

  • config/config_tracing.go → new config/validation_tracing.go: validateOpenTelemetryConfig and its 4 W3C regex patterns extracted into a dedicated validation file, consistent with the existing validation*.go convention in this package.

  • mcp/tool_result.gomcp/collaborator_permission.go: LogAndWrapCollaboratorPermission moved alongside ParseCollaboratorPermissionArgs — all collaborator permission logic now co-located.

  • server/http_helpers.go → split into server/middleware.go: Middleware composition (wrapWithMiddleware, applyIfConfigured, WithOTELTracing, buildMCPHandler, WithSDKLogging, mcpHandlerConfig) extracted into a dedicated file; request/response utilities remain in http_helpers.go.

No logic changes — pure file reorganization.

…and server helpers

- Move ConnectionErrorContext + LogConnectionError from mcp/errors.go → mcp/connection_logging.go, delete errors.go
- Extract validateOpenTelemetryConfig + regex patterns from config/config_tracing.go → new config/validation_tracing.go
- Move LogAndWrapCollaboratorPermission from mcp/tool_result.go → mcp/collaborator_permission.go
- Split server/http_helpers.go: middleware functions → new server/middleware.go

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor outlier functions in semantic function clustering refactor: move outlier functions to semantically correct files May 20, 2026
Copilot AI requested a review from lpcox May 20, 2026 23:23
Copilot finished work on behalf of lpcox May 20, 2026 23:23
@lpcox lpcox marked this pull request as ready for review May 20, 2026 23:56
Copilot AI review requested due to automatic review settings May 20, 2026 23:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors code layout by relocating a few “outlier” helpers into files whose names and responsibilities better match their semantics (server middleware composition, MCP connection diagnostics, tracing validation, collaborator permission helpers), without changing behavior.

Changes:

  • Extracts MCP HTTP middleware composition + OTEL/SDK logging wrappers into internal/server/middleware.go, leaving request/response utilities in http_helpers.go.
  • Moves MCP connection failure diagnostic types/helpers into internal/mcp/connection_logging.go and deletes the now-redundant errors.go.
  • Extracts OpenTelemetry validation into internal/config/validation_tracing.go and co-locates collaborator permission logging with its argument parsing helper.
Show a summary per file
File Description
internal/server/middleware.go New file containing MCP handler construction and standard middleware stack (OTEL/auth/HMAC/shutdown/SDK logging).
internal/server/http_helpers.go Removes middleware-related code, keeping only HTTP helper utilities.
internal/mcp/tool_result.go Removes collaborator-permission logging/wrapping helper from tool result utilities.
internal/mcp/errors.go Deletes file after relocating the only remaining connection-diagnostic helpers.
internal/mcp/connection_logging.go Adds connection failure diagnostic context + logging helpers alongside other connection logging.
internal/mcp/collaborator_permission.go Adds LogAndWrapCollaboratorPermission next to collaborator permission arg parsing.
internal/config/validation_tracing.go New validation file for OpenTelemetry config (W3C ID regex + endpoint rules).
internal/config/config_tracing.go Removes embedded validation/regex; keeps tracing config + variable expansion/default registration.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 8/8 changed files
  • Comments generated: 0

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 21, 2026

@copilot merge main

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 21, 2026

@copilot merge main

Done — merged main into the branch (c108941). There was one conflict in internal/server/http_helpers.go where main had kept the middleware functions we moved to middleware.go; resolved by keeping our split. Also forward-ported main's gen_ai semantic conventions change (replacing attribute.String("session.id", …) / "gateway.tag" with tracing.GenAIConversationID / tracing.GatewayTag) into middleware.go. All checks pass.

Copilot finished work on behalf of lpcox May 21, 2026 00:24
@lpcox lpcox merged commit 0d6c828 into main May 21, 2026
14 checks passed
@lpcox lpcox deleted the copilot/refactor-semantic-function-clustering branch May 21, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] Semantic Function Clustering: Outliers and Organizational Improvements

3 participants