{{ message }}
Refactor internal helper placement and naming to resolve semantic clustering outliers#7170
Merged
Merged
Conversation
Closed
9 tasks
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering to fix outliers and duplicates
Refactor internal helper placement and naming to resolve semantic clustering outliers
Jun 7, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors several internal helpers to better align them with their owning domains (server/guard/config/logger/mcp), reduces duplicated validation logic, and resolves a session-method naming collision in the MCP connection layer.
Changes:
- Moved session-ID truncation logic from
internal/strutilintointernal/serverand updated all server logging call sites and tests. - Moved WASM guard discovery helpers into
internal/guardand updated server initialization/tests to use guard-owned discovery. - Consolidated duplicated validation and expansion helpers (config/guard), simplified DIFC filtered-item metadata extraction, and renamed MCP SDK session validation helper to
requireSDKSession.
Show a summary per file
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 30/30 changed files
- Comments generated: 0
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.

This PR resolves the semantic clustering findings across
internal/by relocating outlier functions/types to their owning domains and removing duplicate validation logic betweenconfigandguard. It also resolves an ambiguous transport-vs-server session method name collision.Config expansion logic consolidation
expandMapInPlaceandexpandTracingVariablesintointernal/config/expand.goso${VAR}expansion behavior lives in one place.config_stdin.goandconfig_tracing.go.Guard/config validator consolidation
internal/config/guard_policy_validation.go:ValidateStringArrayFieldIsValidAllowOnlyReposValueinternal/guard/wasm_validate.goto delegate to config validators instead of reimplementing equivalent checks.WASM guard discovery ownership moved to
guardinternal/guard/wasm.go:GetWASMGuardsRootDirFindServerWASMGuardFileinternal/server/guard_init.goand related tests to call guard-owned helpers.DIFC filtered-item map helper outliers removed
buildFilteredItemLogEntry(internal/server/difc_log.go) per issue recommendation.difc_log_test.go.Logger cleanup API scope
ExtractErrorMessagetoextractErrorMessage(internal/logger/log_cleanup.go) since usage is internal/test-only.MCP tag snapshot type placement
AgentTagsSnapshotandGetAgentTagsSnapshotFromContextfromconnection.gotoconnection_logging.goto colocate declarations with actual logging consumers.Label-agent helper placement
emptyAgentLabelsResultandApplyLabelAgentResultfrominternal/guard/guard.gotointernal/guard/label_agent.goalongsideRunLabelAgent.Session ID truncation ownership
internal/strutilintointernal/server/session_util.goastruncateSessionID.TruncateSessionIDfromstrutiland moved tests to server package.Naming collision removal
(*mcp.Connection).requireSession()torequireSDKSession()to distinguish SDK transport session validation fromserver.requireSession(ctx)lifecycle behavior.