Refactor duplicated filter validation and localize RPC/launcher helpers#7802
Merged
Conversation
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering for outliers and near-duplicates
Refactor duplicated filter validation and localize RPC/launcher helpers
Jun 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors and consolidates a few duplicated/helper utilities (jq filter validation, RPC logging helpers, and launcher session suffix formatting) to tighten package boundaries and reduce maintenance overhead while aiming to preserve existing behavior.
Changes:
- Refactors config tool-response-filter validation so the no-vars path delegates to the vars-aware implementation.
- Consolidates RPC payload formatting + marshal helpers into
internal/logger/rpc_format.goand removes the extra helper file. - Moves launcher session suffix formatting out of
internal/strutilinto a launcher-local helper (and relocates the test).
Show a summary per file
| File | Description |
|---|---|
| internal/strutil/strutil.go | Removes exported SessionSuffix helper from strutil to reduce cross-package coupling. |
| internal/strutil/session_suffix_test.go | Deletes the strutil-scoped test that covered the removed helper. |
| internal/logger/rpc_logger.go | Updates the internal file-organization comment to reflect the consolidation. |
| internal/logger/rpc_helpers.go | Removes the standalone RPC helper file (helpers moved into rpc_format.go). |
| internal/logger/rpc_format.go | Adds payload/marshal helper functions alongside formatting utilities. |
| internal/launcher/log_helpers.go | Introduces a launcher-local sessionSuffix helper and updates call sites. |
| internal/launcher/log_helpers_test.go | Adds coverage for the moved sessionSuffix helper. |
| internal/config/validation.go | Refactors tool response filter validation to delegate through the vars-aware implementation. |
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: 2
Comment on lines
+129
to
133
| // filters that reference variables which are only bound at run time. A nil varNames | ||
| // slice preserves validateToolResponseFilters behavior by disallowing jq variables. | ||
| func validateToolResponseFiltersWithVars(filters map[string]string, jsonPath string, varNames []string) error { | ||
| if len(filters) == 0 { | ||
| return nil |
Comment on lines
+117
to
121
| // validateToolResponseFilters validates tool response filters without permitting jq | ||
| // variables, preserving the historical runtime behavior by delegating with nil varNames. | ||
| func validateToolResponseFilters(filters map[string]string, jsonPath string) error { | ||
| if len(filters) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| for toolName, rawFilter := range filters { | ||
| if strings.TrimSpace(toolName) == "" { | ||
| return fmt.Errorf("%s contains an empty tool name", jsonPath) | ||
| } | ||
| filter := strings.TrimSpace(rawFilter) | ||
| if filter == "" { | ||
| return fmt.Errorf("%s.%s must not be empty", jsonPath, toolName) | ||
| } | ||
|
|
||
| query, err := gojq.Parse(filter) | ||
| if err != nil { | ||
| return fmt.Errorf("%s.%s contains an invalid jq expression: %w", jsonPath, toolName, err) | ||
| } | ||
| if _, err := gojq.Compile(query, | ||
| gojq.WithEnvironLoader(func() []string { return nil }), // match runtime compile options (defense-in-depth) | ||
| ); err != nil { | ||
| return fmt.Errorf("%s.%s contains an invalid jq expression: %w", jsonPath, toolName, err) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| return validateToolResponseFiltersWithVars(filters, jsonPath, nil) | ||
| } |
This was referenced Jun 20, 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.
This addresses the main semantic-clustering findings from the refactor audit: duplicated jq filter validation logic, RPC logging helpers split across too many files, and a launcher-specific session formatter living in
strutil. The change keeps behavior intact while tightening package boundaries and reducing maintenance overhead.Config validation
validateToolResponseFiltersto a thin wrapper overvalidateToolResponseFiltersWithVars(..., nil).nilpreserves the existing “no jq variables” behavior.RPC logger consolidation
internal/logger/rpc_format.go.rpc_helpers.gosplit;rpc_logger.goremains the coordination/API surface.Launcher/package boundary cleanup
internal/strutilintointernal/launcher/log_helpers.goas a local helper.Scope intentionally left out
server/gateway_tls.goormiddleware/schema.go; those were lower-priority organizational observations rather than the highest-value refactors.