Commit Graph
2 Commits
Author SHA1 Message Date
yetone 1fd0bb9670 update: a download whose HTTP/2 transfer broke off tries again over HTTP/1.1
biubiu8802 on X (tweet 2118719081872540038): behind their proxy every
update failed with "download broke off, a network problem", while the
same proxy carried ordinary downloads. Confirmed in the code: download()
retried up to 5 times with Range, but each try went through
netproxy.Dispatch over HTTP/2 again; Dispatch moves a host to HTTP/1.1
only on a TLS record error (recordError: bad record MAC and kin), and
"unexpected EOF" or a stream reset is not one. So a proxy that cuts
HTTP/2 streams part way cut every try the same way.

- netproxy: OverHTTP1(ctx) sends every request under ctx through
  Dispatch's HTTP/1.1 copy (route.h1), kept through With.
  BrokeOff(err) says a transfer broke off (net.Error, unexpected EOF,
  HTTP/2 stream error / GOAWAY / lost connection, a reset; not a
  context that ended). AgainOverHTTP1 runs a download once more over
  HTTP/1.1 after such a failure.
- update: the tries after a broken one go over HTTP/1.1, and still
  resume with Range from the bytes kept.
- Siblings, the other big downloads through Dispatch's client: the
  masking model and pf-serve (pii.fetch, one more try over HTTP/1.1
  from what is on the .part file), Bun's zip (plugin getURLFrom),
  Claude Code's binary (claudecode.download) and the Grok CLI
  (grokDownload) each try once more over HTTP/1.1.
- docs/subsystems/providers-accounts.md names it.

Run (mote, Go 1.26.8, at this tree, base 80ae904c2 = origin/main fetched
just before push):
- TestDownloadBrokenOverHTTP2TriesHTTP1 (httptest TLS HTTP/2 server
  that resets each HTTP/2 stream after 100KB, serves HTTP/1.1 whole):
  red with the update.go line taken out, all six tries over HTTP/2
  ("stream error: ... INTERNAL_ERROR"); green after, asked
  ["HTTP/2.0 ", "HTTP/1.1 bytes=102400-"].
- TestOverHTTP1EveryHost, TestAgainOverHTTP1, TestBrokeOff: green.
- go test ./internal/netproxy ./internal/update ./internal/pii
  ./internal/claudecode ./internal/plugin ./internal/provider: ok.
- go test ./... -count=1 -timeout 45m: 86 ok, gateway 795s and agent
  303s ok; internal/gui red only on two AppKit tests already filed for
  mote's macOS 27: TestMainWindowCorners/macOS_26_SDK (#3949) and
  TestPanelHiddenByWailsMarksPageOutOfSight (#5322). Nothing in gui is
  touched here.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet of the touched
  packages clean.

Not tried: a real proxy that cuts HTTP/2 (the reporter's); the retry of
pii, Bun, Claude Code and Grok against a real host (unit-covered by
AgainOverHTTP1 only); Windows/Linux test runs.
2026-11-06 23:44:58 +08:00
yetone ee91d86ea0 provider: a custom provider can be held to HTTP/1.1, and a TLS record error on HTTP/2 moves its host there
kepner_53726 (Discord, magpie 0.1.2926): a custom Anthropic provider at a
company intranet gateway failed 124 turns in 3 days mid-stream with "tls:
bad record MAC" / "received record with version eaf1", each a 200 with 0
output tokens, until a restart; a plain Go 1.26.8 client to the gateway held.

Cause: none found in magpie. The bytes are read by stdlib crypto/tls, and
every conn wrapper on the path only passes them through, so a record whose
MAC fails was mangled before it reached us: by the gateway or a box between
(the system proxy route, a TLS-inspecting middlebox). HTTP/2 meets it far
more than one-off clients do: one long-lived connection carries every
stream, plus magpie's health pings (netproxy.HTTP2Health), so a gateway
that interleaves its writes racily breaks it.

- Provider.HTTP1 ("HTTP version" row, "HTTP/1.1 only" tick, under the
  editor's Advanced; shown for a provider of the user's own at an https://
  address, the same set InsecureTLS takes). Via adds netproxy.WithHTTP1 for
  its own base URLs' hosts; Dispatch sends those over its HTTP/1.1 copy.
  Another host, and a request made for another provider (With), keep HTTP/2.
  Save refuses it on a preset's; a save that leaves the key out keeps it.
- With no setting: a TLS record error read on an HTTP/2 reply (h2Watch) or
  round trip marks the host:port, and Dispatch speaks HTTP/1.1 to it for 6
  hours. Go's transport already drops the broken connection. Zero-config
  default otherwise unchanged.
- Advanced opens by itself when the tick is set. No note under the row
  (the core script budget, not raised).

Run (mote, at 1ccad582d plus this; budget and these tests again at a10ad0ec8 plus this): gofmt -l; go vet of netproxy,
provider, gui; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet
./...; go test -tags nogui -run 'HTTP1|RecordError|H2Record|InsecureTLS|
Dispatch|With|Budget|I18n' over netproxy, provider and gui, ok;
TestCoreScriptBudget ok after trimming. GUI: provider-http1 (new, 60 of 60,
chromium+webkit, 5 languages, 1100/420), provider-insecure-tls,
provider-advanced-fold, editor-advanced-align, provider-limit-rest,
i18n-en-no-cjk pass. i18n-keys "a plugin's words are its own" is red on
three plugin strings this change doesn't touch (library, routing, usage).

TestH2RecordErrorMovesHostToHTTP1 mangles a real TLS stream through a TCP
relay that flips a byte, and checks the next request goes over HTTP/1.1.

Not broken by hand yet; not tried against a real company gateway, or in
the real app window.

Reported-by: kepner_53726 (Discord)
2026-11-06 15:24:18 +08:00