The test reads the heap once the upstream has written each request's
first chunk: got is sent from its handler right after the Flush. The
gateway lets the body it sent go when forwardOnce returns (#3383),
after the transport has read that reply off the connection and p.Do
has returned it, so the heap can be read while a request still holds
what it sent, and only the two GCs before the read give it time. A
scratch copy of the test, on 23cec6c4, counted the requests whose
first text had reached their agent when the wait ended: -count=30 at
-cpu 1, 2, 4 and 8, it was 8 of 8 in none of the 120 runs (7 in 85,
down to 1), and the held ratio ran from 1.74 to 2.87 against the bar
of 3. In my full suite at 6b556f5a (go test ./..., internal/gateway
441 s beside the other packages) it went over:
streaming_heap_test.go:96: 8 streaming requests of 4 MB hold 121 MB,
3.1 times the body each
The test now waits for each request's first text at the agent's end
of its pipe (firstText): the gateway streams it from the reply
forwardOnce returned, so that request's LetGo has run. What the heap
is read for, and the bar, are unchanged.
What was run (this commit on 23cec6c4; go1.26.8, -tags nogui):
the same count with this wait, -count=30 at -cpu 1, 2, 4 and 8: 8 of
8 in 120 of 120, the ratio 2.09 to 2.19
the answers made to reach forwardOnce late, a 300 ms pause after
p.Do (scratch, not in this commit):
all 8, -count=10: the old test red 10 of 10, "3.7 times" to "4.0
times the body each"; this one ok
the first 3, six runs: the old test red in one, "8 streaming
requests of 4 MB hold 122 MB, 3.1 times the body each"; this one
ok in six. The first 1 or 2: both ok six times, the old test's
ratio up to 2.73
LetGo taken out of forwardOnce, -count=10: red 10 of 10, "8 streaming
requests of 4 MB hold 152 MB, 3.9 times the body each"
-race -count=20: ok; -cpu 1,2,4 -count=20: ok
gofmt -l internal/gateway: nothing; GOOS=linux, darwin, windows go
vet -tags nogui ./internal/gateway: exit 0
full suite, go test -tags nogui -count=1 -timeout 45m ./... at this
commit: 63 packages ok; internal/gateway ran 445 s, this test ok in
it. 7 packages red, each of this machine and named before (#3480's
d970371e): #3141's lookup tick (TestInstalledVersion,
TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
TestQoderSettingsFromAnIDEPluginIsNotTheCLI, TestOmpDetectedWithPiDir,
TestZedAppPath); Reasonix's two (a /tmp/.git that isn't this user's);
every connection proxied, even to this machine's own non-loopback
addresses (TestCallbackGoesPastTheAgentsProxy,
TestClaudeToolCallbackOnANonLoopbackAddress,
TestGatewayFixQuitsOnlyAMagpie, TestGatewayHeldByAContainer); umask
077 (TestWriteAtomicReadOnlyHardLink, testenv's TestProgram); Bun
1.3.11 (TestBunProxyLoginWithReservedCharacters, #3397)
Not tried: macOS, Windows, CI's runners.
Landed by yetone in a batch of Coffemon's patches from the issues.
What was run, go1.26.8, on origin/main cc81ad4ea, then again at
70a0c387c (gofmt, the three vets, the changed tests, umask 077):
- mote (macOS 27): gofmt -l clean; go vet, GOOS=linux go vet -tags
nogui and GOOS=windows go vet ./...: ok. edit and testenv at umask
077; agent, provider, library and gateway with an empty .git above
TMPDIR; davsync, imagemcp, plugin, library, edit, testenv whole; the
changed tests in agent, provider, gateway and gui; the timing tests
-count=10 (gateway, davsync, imagemcp) and -count=5 (agent): all ok.
TestCoreScriptBudget ok: core 1,536,751 of 1,537,034, app.js
1,312,975 of 1,315,316, no budget raised.
- Red on the old code: on origin/main, TestWriteAtomicReadOnlyHardLink
at umask 077 and two Reasonix tests under an empty .git; on Linux
(wsl-run) TestProgram at umask 077 with the old program.go. With
each fix's code taken back to main's, the Gemini imageConfig tests,
TestPluginToldWhereTheAgentWorks, TestSkillRepoTraced,
TestTaggedHooksAlone, TestMainURL/TestMainView and update-auto,
plugin-github-hooks, plugins-more-discover, plugin-namesake were
red. Broken by hand: claudeKeyed always true (both
OwnEndpointNeverAsked tests red), claudeAsk a no-op
(TestClaudeFirstWriteAsksTheProxy red), GitAt taking any .git folder
(the three TestGitOnDisk tests red).
- GUI: 123 files (plugins*, update-*, panel/tray/start/context, i18n,
gui-zh-tw/ja/de and every file that evals app.js parts) in WebKit on
Linux (wsl-run). 11 files had reds (click-scroll, panel-fold,
plugin-card-update, plugin-github, plugin-move*, segs-glide,
tray-totals, update-*), and run again side by side they fail the
same on origin/main d80d75f30 (79 pass, 26 fail here; 78 and 27
there). They are click-scroll guards ("the click must not scroll
the page"), varying by language from run to run (#4385).
copilot-ghe's route-after-close red is #1949, seen on main 244d80e23
too. In Chromium on mote, Chromium segfaulted partway through files
(#4125): context-map, context-scroll-end and context-tune fail the
same on origin/main 0911a65e7, so the batch's own files
(plugin-namesake, update-auto, plugins-more-discover,
plugin-github-hooks) ran in Chromium on Linux: 62 of 62.
- Full suite (go test -tags nogui -count=1 -timeout 45m ./..., mote)
at 472a0608f (on 70a0c387c): every package ok but internal/gateway,
whose five reds were #4362's (Antigravity turned-away and
TestCodexSpentGrokFailingIsTold), fixed on main in d80d75f30. After
the rebase on 244d80e23 the five pass, and gofmt, the three vets
and the targeted runs above were run again: ok. In Linux the
sign-in, copilot, plugin-github*, plugins-more-discover,
plugin-namesake, plugin-gateway, update-auto, quota-refresh-order
and i18n files ran in both engines: 475 pass, 4 fail (copilot-ghe
#1949, plugin-github's click scroll, both red on main too).
- Rebased again on c7171a256, over its budget fix e94bf7a08: gofmt, vet of
gui, gateway, provider and plugin, TestCoreScriptBudget (core
1,536,265 of 1,536,586 with the batch's last commit, statusTErr and settingsErr), the Gemini,
GitOnDisk and plugin tests, and in Linux both engines i18n-keys,
update-mirror, plugin-namesake, plugins-more-discover,
plugin-github-hooks and update-auto (138 of 138): ok.
Not tried: the whole GUI suite (mote's WebKit wouldn't launch and its
Chromium segfaulted, #4125); macOS WebKit; the real app's window.
The transport holds a request until its reply's body is closed, a
stream's whole length, and with it the bytes.Reader body and the GetBody
NewRequest made over it. So every streaming request kept the body it
sent upstream alive to its end: for a Claude Code request translated to
Chat, the marshalled body (marshalRaw/appendHTMLEscaped in the report's
heap, 503 MB live).
provider.SetBody gives a request a body whose reader drops its bytes
once read and whose GetBody reads them again until provider.LetGo.
forwardOnce lets go once its retries (RetryOneAuth, RetryZhipuCoding)
are done; Codex's zstd turn, Copilot Auto's model swap and Gemini's Code
Assist envelope set their bodies the same way, so LetGo reaches them.
Run (worktree perf-stack, on the four commits before it, over
origin/main 137187a40):
- a heap probe, 8 Claude Code requests of 4.7 MB held mid-stream to a
Chat upstream: 152 MB held before, 88 MB after; the rest is the body
as it came (another member) and as read (a continuation). Anthropic
to Anthropic holds the body once, 41 MB.
- TestStreamingRequestsLetTheirSentBodyGo (bar 3x the body each) and
TestSetBodyLetsItsBytesGo: green; red with LetGo commented out of
forwardOnce ("8 streaming requests of 4 MB hold 166 MB, 4.2 times the
body each") and with LetGo storing nothing ("the request holds its
body's bytes after it was answered").
- go test ./internal/provider/ ./internal/redact/ ok; ./internal/gateway
-run 'Mask|Redact|Codex|Copilot|Gemini|Google|Antigravity|Zhipu|Auth|
Retry|Stream|Continu' ok; GOOS=linux and windows vet -tags nogui
clean, gofmt clean. The full suite runs at the pushed head.
Not tried: a real vendor; the bytes on the wire are the same.