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)
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
// kepner_53726: a provider the user added on a company gateway whose
|
|
// HTTP/2 connections broke mid-reply is spoken HTTP/1.1 once asked
|
|
// (HTTP1), through every request Via makes: its models list lists the
|
|
// protocol it was asked over. A preset's provider is refused it, and one
|
|
// set by hand is spoken HTTP/2 as before.
|
|
func TestHTTP1OwnProviderOnly(t *testing.T) {
|
|
azureHome(t)
|
|
dialsOut(t)
|
|
srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
io.WriteString(w, `{"data":[{"id":"`+r.Proto+`"}]}`)
|
|
}))
|
|
srv.EnableHTTP2 = true
|
|
srv.Config.ErrorLog = log.New(io.Discard, "", 0)
|
|
srv.StartTLS()
|
|
t.Cleanup(srv.Close)
|
|
ctx := context.Background()
|
|
proto := func(p Provider) string {
|
|
t.Helper()
|
|
ms, err := p.List(ctx)
|
|
if err != nil || len(ms) != 1 {
|
|
t.Fatalf("%s: %v %v", p.ID, ms, err)
|
|
}
|
|
return ms[0].ID
|
|
}
|
|
|
|
if err := Save(Provider{ID: "gw", Name: "Gateway", Anthropic: srv.URL + "/v1", InsecureTLS: true, Models: []string{"m"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, _ := Find("gw")
|
|
if got := proto(*p); got != "HTTP/2.0" {
|
|
t.Fatalf("not asked, spoken %s", got)
|
|
}
|
|
p.HTTP1 = true
|
|
if err := Save(*p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, _ = Find("gw")
|
|
if !p.HTTP1 {
|
|
t.Fatal("HTTP1 not kept")
|
|
}
|
|
if got := proto(*p); got != "HTTP/1.1" {
|
|
t.Fatalf("asked HTTP/1.1, spoken %s", got)
|
|
}
|
|
|
|
if err := Save(Provider{ID: "ollama", Name: "Ollama", Preset: "ollama", Chat: srv.URL + "/v1", HTTP1: true}); err == nil {
|
|
t.Fatal("a preset's provider saved with HTTP1")
|
|
}
|
|
hand := Provider{ID: "codex", Chat: srv.URL + "/v1", HTTP1: true}
|
|
if hand.TakesInsecureTLS() {
|
|
t.Fatal("a subscription's id takes HTTP1")
|
|
}
|
|
}
|