Commit Graph
2 Commits
Author SHA1 Message Date
yetone 238f0d927b gateway tests: the fake Cursor servers close their connection after a reply, so their log has no "http: panic serving …: invalid concurrent Body.Read call" (CI Test run 37791950740 at 8db24fd6, macOS, and green runs since 85fd35ab)
The five fakes answer a Run in full duplex (EnableFullDuplex) and return
while magpie's request body is still open, as Cursor does. Go's server
then reads the rest of that body in finishRequest's Close, after it has
stopped the connection's background read; the read's EOF starts another
background read, and the kept-alive connection's next request reads
beside it and panics. net/http recovers it and the tests pass, so it
was only noise in the log, beside the run's real failure
(TestBurstTellsNoSpeed, fixed in 5e17a183). magpie's own server never
uses full duplex: the panic is the fakes' alone. cursorDuplex enables
full duplex and sends Connection: close, so there is no next request on
that connection.

Red before: the cursor tests -count=10 -cpu 1,2,4 log the panic 11
times (a standalone full-duplex server returning before the body ends
logs it on every other request; 0 with Connection: close); after, 0.
go test -race -tags nogui ./internal/gateway (temp HOME), go vet
-tags nogui ./internal/gateway for darwin, linux and windows, and
gofmt -l pass at this head.
2026-10-08 23:33:44 +08:00
yetone 730a163f47 cursor: a step that calls tools records what it used, the cache included (#676) — Cursor tells a turn's usage (TurnEndedUpdate) only once the client has run the tools and sent their results in the same Run, and the caller runs them after the Run is closed, so every tool step was recorded as an estimated input with no cache (2395 / 0 where Cursor counted 4265, 4224 of them cached), while text turns showed ~99% cache. After the calls Cursor sends only the checkpoint (no token details) and heartbeats; a cancelled Run ends with an error and no usage. Every Run is counted in the dashboard's usage events (DashboardService/GetFilteredUsageEvents) by its conversation_id, input apart from the cache read and written; one shows about 2.5 s after the Run closes. So a tool step with no TurnEnded now closes the Run and looks for its event (after 1.5 s, every 0.5 s, up to 6 s): its conversation's, no older than the Run, not already counted; else the estimate as before. A Run with no conversation id gets one, to be found by. The estimate is also no longer added to a turn read wholly from the cache (input 0, cache read > 0). The mover's min for cursor is 0.1.9, which does the same in the plugin (magpie-community/plugins: cursor 0.1.9). TestCursorToolStepReadsItsUsageEvent fails on the old code (5008 estimated, 0 cached) and passes. Tried with the real Cursor account: the built-in (grok-4.7-medium-fast) reports 6153 in, 6144 cached on a tool call, streamed or not; and through a sandbox magpie's plugin host with plugin 0.1.9, 6186 in, 6144 cached, 121 out, where 0.1.8 recorded 5057 estimated, 0 cached. A tool step now takes about 2.5 s longer to finish. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-03 21:14:13 +08:00