Commit Graph
1 Commits
Author SHA1 Message Date
yetone 3a3bdb9f23 provider: IsOpenCode reads the host without parsing a URL
The Providers page asks IsOpenCode for each model of each provider, and
it parsed "//"+host with url.Parse each time: url.parse was 20 MB of what
20 warm rounds of drift, state and providers allocated with the owner's
real accounts, OpenCodeURL's share 7.5 MB.

openCodeAt takes the host as Host gives it: whatever is before the last
'@' aside, an IPv6 literal never OpenCode's, the port aside, then the
same openCodeHost check OpenCodeURL ends in.

Run on mote (mote-run, Go 1.26.8):
- gofmt clean; go vet ok, also GOOS=windows and GOOS=linux.
- TestOpenCodeAtReadsTheHostAsAURLWould alone: ok. It checks openCodeAt
  against OpenCodeURL for 18 hosts (user info, ports, IPv6, a trailing
  dot, look-alikes such as opencode.ai@evil.com and opencode.ai.evil.com)
  and that a look allocates nothing.
- Broken by hand (openCodeAt answering through OpenCodeURL): red, "a look
  allocated 3 times, want 0".
- go test -timeout 45m ./internal/provider ./internal/gateway: ok
  (156s, 681s), at 606743831; this head is it rebased on main.

Real use: the owner's real-account sandbox, offline (proxy to :9), 20
warm rounds of /api/drift, /api/state and /api/providers, at this head:
- net/url.parse 20.5 MB -> 5 MB (what is left is openCodeGateway and
  others, not IsOpenCode); all allocated 371 MB -> 327 MB.
- /api/state and /api/drift bytes identical to 6a7a690be's (cmp);
  /api/providers differs only in each provider's "fetched" time.
2026-11-01 05:42:21 +08:00