Commit d4ac02b
authored
refactor: relocate misplaced functions to their natural homes (#5006)
Four findings from semantic function clustering analysis: session
lifecycle helpers in the wrong file, feature-specific constructors
buried in `unified.go`, a zero-logic passthrough wrapper, and two tiny
tracing files that should be one.
## Changes
- **Finding 1 — Session helpers → `session.go`**
Moved `extractAndValidateSession`, `injectSessionContext`,
`setupSessionCallback`, `logHTTPRequestBody` out of `http_helpers.go`
into `session.go`. `http_helpers.go` shrinks ~100 lines; all session
lifecycle logic is now in one file.
- **Finding 2 — Feature constructors → their owning files**
- `buildCircuitBreakers`: `unified.go` → `circuit_breaker.go`
- `buildAllowedToolSets` + `hasWildcard`: `unified.go` →
`tool_registry.go`
Added `config` import to both destination files.
- **Finding 3 — Remove `writeErrorResponse` wrapper**
Deleted the one-line passthrough and replaced all call sites with
`httputil.WriteErrorResponse` directly:
```go
// before
func writeErrorResponse(w http.ResponseWriter, statusCode int, code,
message string) {
httputil.WriteErrorResponse(w, statusCode, code, message)
}
// after — call sites use httputil directly
httputil.WriteErrorResponse(w, status, code, msg)
```
- **Finding 4 — Merge tracing CLI files**
`cmd/tracing_helpers.go` + `cmd/flags_tracing.go` (75 lines combined) →
`cmd/tracing.go`.
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `example.com`
> - Triggering command: `/tmp/go-build3872797525/b513/launcher.test
/tmp/go-build3872797525/b513/launcher.test
-test.testlogfile=/tmp/go-build3872797525/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s 8043��
olang.org/grpc@v1.80.0/internal/idle/idle.go cfg x_amd64/vet . --gdwarf2
--64 x_amd64/vet -I 8043057/b418/_pkg_.a -I x_amd64/vet --gdwarf-5
g/grpc/internal//usr/bin/runc -o x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build3399420040/b509/launcher.test
/tmp/go-build3399420040/b509/launcher.test
-test.testlogfile=/tmp/go-build3399420040/b509/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
/tmp/go-build2509960937/b173/vet/run/containerd/io.containerd.runtime.v2.task/moby/db2aa2a60d29ftail
64/pkg/tool/linu-buildtags bash g_.a -trimpath "REQUESTS_CA_B--root
/opt/hostedtoolc/var/run/docker/runtime-runc/moby -uns�� y x_amd64/vet
e-handler @v1.43.0/propaga/usr/libexec/docker/cli-plugins/docker-compose
@v1.43.0/propagadocker-cli-plugin-metadata x_amd64/vet e-handler` (dns
block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3872797525/b495/config.test
/tmp/go-build3872797525/b495/config.test
-test.testlogfile=/tmp/go-build3872797525/b495/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -I g_.a NbAn/6jVna5QQyS18CrolNbAn
x_amd64/vet --gdwarf-5
resolver/delegat/tmp/go-build2509960937/b300/vet.cfg -o x_amd64/vet
8043�� qzhGZjM5u cfg 64/pkg/tool/linux_amd64/vet (compatibility issue
with Go 1.25.0). Continuing with other checks..."; \
elif command -v golan -imultiarch` (dns block)
> - Triggering command: `/tmp/go-build3399420040/b491/config.test
/tmp/go-build3399420040/b491/config.test
-test.testlogfile=/tmp/go-build3399420040/b491/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
88635552ec0a846ca0962f57bea95f938934c2423396c1fa129 x_amd64/compile
ateway_with_pipe.sh cdc8770c07c851b4aae2b041e8136bb0e9e/log.json
pc_health_v1/hea--prefix=/net/ipv4/conf/vethe00a9b0 x_amd64/compile
ateway_with_pipe--prefix=/net/ipv6/conf/vethe00a9b0 -uns��
3c2c91bb777a34fa x_amd64/compile
by/db2aa2a60d29f83ac692768d36051d3e54950f8b5453b528136881dc8dce1cff/log.json
g_.a -trimpath x_amd64/vet
dCQFD9yY_0oeD/ar--prefix=/net/ipv6/conf/vethdaded9f` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build3872797525/b513/launcher.test
/tmp/go-build3872797525/b513/launcher.test
-test.testlogfile=/tmp/go-build3872797525/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s 8043��
olang.org/grpc@v1.80.0/internal/idle/idle.go cfg x_amd64/vet . --gdwarf2
--64 x_amd64/vet -I 8043057/b418/_pkg_.a -I x_amd64/vet --gdwarf-5
g/grpc/internal//usr/bin/runc -o x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build3399420040/b509/launcher.test
/tmp/go-build3399420040/b509/launcher.test
-test.testlogfile=/tmp/go-build3399420040/b509/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
/tmp/go-build2509960937/b173/vet/run/containerd/io.containerd.runtime.v2.task/moby/db2aa2a60d29ftail
64/pkg/tool/linu-buildtags bash g_.a -trimpath "REQUESTS_CA_B--root
/opt/hostedtoolc/var/run/docker/runtime-runc/moby -uns�� y x_amd64/vet
e-handler @v1.43.0/propaga/usr/libexec/docker/cli-plugins/docker-compose
@v1.43.0/propagadocker-cli-plugin-metadata x_amd64/vet e-handler` (dns
block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build3872797525/b513/launcher.test
/tmp/go-build3872797525/b513/launcher.test
-test.testlogfile=/tmp/go-build3872797525/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s 8043��
olang.org/grpc@v1.80.0/internal/idle/idle.go cfg x_amd64/vet . --gdwarf2
--64 x_amd64/vet -I 8043057/b418/_pkg_.a -I x_amd64/vet --gdwarf-5
g/grpc/internal//usr/bin/runc -o x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build3399420040/b509/launcher.test
/tmp/go-build3399420040/b509/launcher.test
-test.testlogfile=/tmp/go-build3399420040/b509/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
/tmp/go-build2509960937/b173/vet/run/containerd/io.containerd.runtime.v2.task/moby/db2aa2a60d29ftail
64/pkg/tool/linu-buildtags bash g_.a -trimpath "REQUESTS_CA_B--root
/opt/hostedtoolc/var/run/docker/runtime-runc/moby -uns�� y x_amd64/vet
e-handler @v1.43.0/propaga/usr/libexec/docker/cli-plugins/docker-compose
@v1.43.0/propagadocker-cli-plugin-metadata x_amd64/vet e-handler` (dns
block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3872797525/b522/mcp.test
/tmp/go-build3872797525/b522/mcp.test
-test.testlogfile=/tmp/go-build3872797525/b522/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -I 8043057/b414/_pkg_.a -fPIC
x_amd64/vet -pthread g/grpc/internal//usr/bin/runc
-fmessage-length--version x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build3399420040/b518/mcp.test
/tmp/go-build3399420040/b518/mcp.test
-test.testlogfile=/tmp/go-build3399420040/b518/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true -I
by/eca09d10600f3--log-format ker/docker-init
by/eca09d10600f3/usr/libexec/docker/cli-plugins/docker-compose
b1a7041eaee94398docker-cli-plugin-metadata x_amd64/vet 91e/log.json
/tmp�� tes.crt x_amd64/vet /usr/sbin/bash by/b7068f2c73a9cbash
/interface.go x_amd64/vet bash` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>9 files changed
Lines changed: 178 additions & 180 deletions
This file was deleted.
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
10 | | - | |
11 | 15 | | |
12 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
13 | 33 | | |
14 | 34 | | |
15 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
236 | 253 | | |
237 | 254 | | |
238 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | | - | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| |||
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 46 | | |
56 | 47 | | |
57 | 48 | | |
| |||
64 | 55 | | |
65 | 56 | | |
66 | 57 | | |
67 | | - | |
| 58 | + | |
68 | 59 | | |
69 | 60 | | |
70 | 61 | | |
| |||
79 | 70 | | |
80 | 71 | | |
81 | 72 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | 73 | | |
101 | 74 | | |
102 | 75 | | |
| |||
124 | 97 | | |
125 | 98 | | |
126 | 99 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | 100 | | |
200 | 101 | | |
201 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
732 | 733 | | |
733 | 734 | | |
734 | 735 | | |
735 | | - | |
| 736 | + | |
736 | 737 | | |
737 | 738 | | |
738 | 739 | | |
| |||
782 | 783 | | |
783 | 784 | | |
784 | 785 | | |
785 | | - | |
| 786 | + | |
786 | 787 | | |
787 | 788 | | |
788 | 789 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
110 | 114 | | |
111 | 115 | | |
112 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
0 commit comments