Conversation
4 tasks
…ean up outlier functions - Add shared httputil.ParseRateLimitResetHeader (with TrimSpace); remove duplicate parseRateLimitResetHeader (server) and parseRateLimitReset (proxy) - Move validateGuardPolicies from config/guard_policy.go to config/validation.go alongside all other top-level config validators; replace logGuardPolicy with logValidation - Remove trivial truncateForLog wrapper in proxy/graphql.go; inline strutil.TruncateRunes directly at the two call sites - Update/remove tests accordingly Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/2e461a0f-7bcc-4bd7-b521-c39a4af9ad09 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering analysis for outliers
refactor: eliminate three near-duplicate/outlier functions flagged by semantic analysis
Apr 15, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors a few small utilities to reduce duplication and keep validation/helpers in more appropriate packages, based on semantic analysis findings.
Changes:
- Added
internal/httputil.ParseRateLimitResetHeaderand updated proxy rate-limit handling to use it. - Moved
validateGuardPoliciesintointernal/config/validation.goto align with other config validation helpers. - Inlined
strutil.TruncateRunes(..., 80)at GraphQL logging call sites and removed the now-redundant wrapper + its dedicated test file.
Show a summary per file
| File | Description |
|---|---|
| internal/server/circuit_breaker_test.go | Removes the server-local header parsing test now covered by shared httputil tests. |
| internal/server/circuit_breaker.go | Deletes an unused/duplicated parseRateLimitResetHeader helper. |
| internal/proxy/rate_limit_test.go | Removes proxy-local header parsing test now covered by shared httputil tests. |
| internal/proxy/handler.go | Switches rate-limit reset parsing to httputil.ParseRateLimitResetHeader. |
| internal/proxy/graphql_test.go | Removes a test file that only exercised a trivial wrapper. |
| internal/proxy/graphql.go | Inlines strutil.TruncateRunes and removes truncateForLog. |
| internal/httputil/httputil_test.go | Adds shared tests for the new reset-header parsing helper (including whitespace trimming). |
| internal/httputil/httputil.go | Introduces shared ParseRateLimitResetHeader helper. |
| internal/config/validation.go | Adds validateGuardPolicies alongside other config validation routines. |
| internal/config/guard_policy.go | Removes validateGuardPolicies from guard policy implementation file. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 10/10 changed files
- Comments generated: 0
This was referenced Apr 15, 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.
Three recurring code-quality findings from semantic function clustering analysis: a near-duplicate pair across
server/proxy, a misplaced config validator, and a trivial one-liner wrapper.Changes
internal/httputil— add sharedParseRateLimitResetHeader(value string) time.Timewithstrings.TrimSpacenormalization, replacing two near-identical private implementations:parseRateLimitResetHeaderininternal/server/circuit_breaker.go(hadTrimSpace)parseRateLimitResetininternal/proxy/handler.go(lackedTrimSpace)internal/config/validation.go— movevalidateGuardPolicieshere fromguard_policy.go; it takes*Configand belongs alongsidevalidateGatewayConfig,validateTrustedBots,validateOpenTelemetryConfig, etc. ReplacelogGuardPolicy→logValidation.internal/proxy/graphql.go— removetruncateForLog(a one-line pass-through tostrutil.TruncateRunes); inlinestrutil.TruncateRunes(s, 80)directly at the two call sites, consistent with the rest of the codebase.Test changes
TestParseRateLimitResetHeadertohttputil_test.go(includes whitespace-trimming case).TestParseRateLimitResetHeaderfromcircuit_breaker_test.goandTestParseRateLimitResetfromrate_limit_test.go— now covered by the shared test.graphql_test.go(only containedTestTruncateForLog;strutil.TruncateRunesis already tested instrutil/truncate_test.go).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:
example.com/tmp/go-build907643046/b514/launcher.test /tmp/go-build907643046/b514/launcher.test -test.testlogfile=/tmp/go-build907643046/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s .cfg�� 6809213/b405/_pk-errorsas 0L32/Gn657Kg8UZO-ifaceassert x_amd64/vet --gdwarf-5 /http2/hpack -o x_amd64/vet .cfg�� lete: awmg" ache/go/1.25.8/x64/src/crypto/tls/alert.go x_amd64/vet . --gdwarf2 --64 x_amd64/vet(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build907643046/b496/config.test /tmp/go-build907643046/b496/config.test -test.testlogfile=/tmp/go-build907643046/b496/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build907643046/b395/vet.cfg /testutil/mcptesgo1.25.8 /testutil/mcptes-c=4 x_amd64/vet 6809213/b151/ -imultiarch x86_64-linux-gnu-bool x_amd64/vet 6809�� g_.a olang.org/grpc@v-ifaceassert 64/pkg/tool/linu-nilfunc . ce/tracetest --64 64/pkg/tool/linu-buildtags(dns block)nonexistent.local/tmp/go-build907643046/b514/launcher.test /tmp/go-build907643046/b514/launcher.test -test.testlogfile=/tmp/go-build907643046/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s .cfg�� 6809213/b405/_pk-errorsas 0L32/Gn657Kg8UZO-ifaceassert x_amd64/vet --gdwarf-5 /http2/hpack -o x_amd64/vet .cfg�� lete: awmg" ache/go/1.25.8/x64/src/crypto/tls/alert.go x_amd64/vet . --gdwarf2 --64 x_amd64/vet(dns block)slow.example.com/tmp/go-build907643046/b514/launcher.test /tmp/go-build907643046/b514/launcher.test -test.testlogfile=/tmp/go-build907643046/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s .cfg�� 6809213/b405/_pk-errorsas 0L32/Gn657Kg8UZO-ifaceassert x_amd64/vet --gdwarf-5 /http2/hpack -o x_amd64/vet .cfg�� lete: awmg" ache/go/1.25.8/x64/src/crypto/tls/alert.go x_amd64/vet . --gdwarf2 --64 x_amd64/vet(dns block)this-host-does-not-exist-12345.com/tmp/go-build907643046/b523/mcp.test /tmp/go-build907643046/b523/mcp.test -test.testlogfile=/tmp/go-build907643046/b523/testlog.txt -test.paniconexit0 -test.timeout=10m0s .cfg�� FM1m/LEd7bURSK2u2w4dcFM1m /tmp/go-build1626809213/b288/ x_amd64/vet � Warning: golanrunc --gdwarf2 --64 x_amd64/vet .cfg�� 6184859/b100/vet.cfg -trimpath x_amd64/vet lock.go lock_sort.go -lang=go1.19 x_amd64/vet(dns block)If you need me to access, download, or install something from one of these locations, you can either: