Repository navigation
Description
Problem
Two of the audit's bugs come from a pattern that repeats across files. Fixing each copy by hand leaves the next copy to be written. A source-scanning test would catch every new one, like core/listener/parity/dispatch_audit_test.go already does for request-context dispatches.
1. http.Transport without MaxIdleConnsPerHost
Without it, Go keeps 2 idle connections per host. With an HTTP/1.1-only gateway such as LiteLLM, extra concurrent requests then pay a new TCP+TLS handshake each (#1546: 10 concurrent callers opened 36–45 connections instead of 10).
A prototype go/ast scan of main (43cf553) finds all 3 http.Transport literals without it:
core/listener/forwardproxy/server.go:209core/tlsbridge/upstream.go:28core/plugins/inferencerouter/routerconfig/models.go:134. This one is a one-shot model-list fetch, so it can be exempt with a reason.
2. Temp-file-and-rename without Sync
Renaming a temp file over the real one without f.Sync() first can leave the destination empty after a power loss (#1547). The plugin store and the session archive do it right; the same scan finds 12 functions that do not:
| Function | What it writes | Losing it means |
|---|---|---|
core/tlsbridge/ca.go:286 atomicWriteFile |
bridge CA key + cert | every agent's trust of the CA breaks |
cmd/agentop/cmd_claudecode.go:954 writeSettings |
the user's ~/.claude/settings.json |
user config lost |
cmd/agentop/cmd_config_migrate.go:226 replaceConfig |
~/.cortex/config.yaml |
proxy will not start |
cmd/agentop/userconfig.go:102 saveUserConfig |
agentop settings | user config lost |
cmd/agentop/cmd_bob.go:951 bobWriteKeys, cmd_codex.go:464 write |
agent config files | user config lost |
core/observe/claude/harvest.go:1999 SaveMetadata |
session titles | #1547 |
core/spiffe/mirror.go:24 atomicWrite |
SVID mirror | rewritten on next rotation |
cmd/agentop/cmd_script.go:455 writeAtomic |
installed script plugin | reinstall |
core/cost/pricing/pricelist/pricelist.go:162 save |
price-list cache | re-downloaded |
cmd/agentop/cmd_service_platform.go:789 writeProxyStamp |
binary checksum stamp | recomputed |
core/plugins/script/sdk.go:18 installSDK |
SDK file | rewritten |
The scan matches by name inside one function (os.Rename, plus CreateTemp/WriteFile, minus any .Sync()), so each hit needs a look. The last four look safe to exempt, since the file is rebuilt or rewritten anyway.
Proposed tests
- Two
go/astaudits in the style ofdispatch_audit_test.go. One walks the non-test.gofiles ofcoreandcmd; the other does the same for the rename pattern. - Each failure names
file:lineand what to add. - Each test keeps an allowlist that gives a reason per entry, so an exemption is a decision someone made, not silence.
How to land
Both tests need no fix to land: today's hits go into the allowlist, each pointing at #1546 or #1547, and leave it as those issues are fixed. From then on, a new transport or atomic write fails CI unless it is done right or allowlisted with a reason.
Found while checking why the bugs from an experiment-driven audit (#1541–#1547) got past CI. Grounded on main at 43cf553.
Assisted-By: Claude (Anthropic AI) [email protected]
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity