Files
magpie/internal/gui/assets/plugins/usage
yetone 6f92815335 routing: each try says where its time went: magpie, the network, the vendor (Discord, Magic_zero)
A user read a slow turn as the gateway being slow. The try loop's
httptrace now also records DNS, connect, TLS, GotConn (reused or not)
and the first response byte. Each Try keeps a TryNet ("net"): magpie's
own time, requests made before it, the wait for a pooled connection,
DNS, connect, TLS, sending, the vendor's wait for its first byte, and
Head (from the try's start to that byte). A Route also carries the usage
record's Sent/Own/Retried/Queued split. Usage records are unchanged.

The Routing page's story shows "Where the time went" under each finished
try. It is one stacked bar plus named values, in three groups (magpie,
network, vendor): Waiting for a slot (tr.queued, which was never shown
before), In magpie, DNS, Connecting, TLS, Sending, Vendor (first byte),
First token, Streaming. Parts that took no time are left out. The
strings are in every language. "Waiting for a slot" moves from the
Usage plugin's i18n into i18n.js, since Routing uses it too.

Not covered: plugin providers (and any other request sent by something
other than Go's client). Their request goes out through the Bun host's
fetch, so no httptrace fires. Such a try has no net and shows no
breakdown, only the time it took, as before (and so does a trace from
before this change).

Run (worktree at origin/main b03031738):
- gofmt -l: clean. go vet -tags nogui ./... for GOOS darwin, linux and
  windows: ok.
- TestTryTellsWhereItsTimeWent uses a TLS fake whose headers are held
  300 ms. Wait must land in [hold-1, hold+5000]. On a new connection
  TLS is > 0. The steps sum to no more than Head, and Head is no more
  than TTFT. A reused connection has no DNS, connect or TLS.
  -race -count=3: ok.
- Broken by hand: with the old two-hook trace back in gateway.go, the
  test fails ("no timing").
- routing-time-went.test.cjs: chromium and webkit × en, zh, zh-TW, ja,
  de at 440px: 10/10. It checks that the bar is to scale, that nothing
  spills out of the story, that there is no left border, and that the
  plugin try shows no breakdown. i18n-keys: ok. Rerun on the committed
  tree: 13/13 with i18n-keys.
- routing-*, usage-ledger*, lane-limit at --test-concurrency=4:
  4 reds, all webkit click timeouts in routing-busy ("trace updates
  keep the rows…", en and zh) and routing-idle-frame ("hiding a running
  replay…", 2). Both files run alone: 13/13, twice. Recorded on #2211 (the same files go red under load on main cf21b71ff).
- Real use: magpie serve --web on 3571/3572 in a sandbox HOME, against
  a fake vendor (900 ms before its headers, 300 ms to its first token,
  then 1 s of chunks). New connection: In magpie 1.3 ms, DNS 0.3,
  Connecting 0.4, Sending 0.1, Vendor (first byte) 912 ms, First token
  294 ms, Streaming 1.0 s. A reused connection had no DNS or connect.
  Both were seen in the page, in headless Chromium.
- Not tried: a real vendor over TLS through the app; the Linux
  WebKitGTK app; Windows.

Full suite: go test -tags nogui -count=1 -timeout 45m ./... ok
(66 packages; gateway 811s, agent 728s, provider 359s).
2026-10-16 01:55:47 +08:00
..