Commit Graph
4 Commits
Author SHA1 Message Date
yetone 3ee6c2d948 providers: a provider list looks at the stamps, plugin logins, client shapes and accounts once a request
/api/providers took ~25ms of CPU a call with the owner's real config (25
providers, plugins signed in), polled by every open window. Its profile
had file system calls at about half, each repeated for every provider
the list shows:

- StampNow stat'ed providers.json, settings.json and the catalog for every
  provider (KeptListing); under a request's Hold it is looked at once.
- plugin.ListedAt was asked for every plugin provider's Listed(); once a
  request (heldOf "plugin-listed").
- pluginLogins took logins.json's lock, a file opened across magpies,
  for every plugin even with nothing to change. It now settles the list
  as read first, and takes the lock and settles again from a fresh read
  only when something changes.
- clientShape read and parsed client-shapes.json for every relay a list
  shows (TestsAs); parsed once until the file changes (filememo), a copy
  given out.
- Logins(agent) took the same lock for every provider, twice with its
  account models; listed once an agent a request, a copy each, listed
  anew after a write (writePrivate's filememo.Forget).

Run (on mote unless named):
- go test ./internal/provider ./internal/gui -timeout 45m: provider ok
  (102s) with the new tests; gui red on TestMainWindowCorners (macOS 27,
  #3949) and on TestSettingsSaveKeepsWhatItDoesNotSend, red on main since
  b09349d17, fixed by #4514's commit before this one.
- At the pushed head (rebased on e84870f17): go test ./internal/provider
  ok (100.7s), ./internal/plugin ok (102.7s), TestLoginsListedOnceARequest
  -count=5 ok (it now clears the 30s look another test left), gui
  TestSettingsSaveKeepsWhatItDoesNotSend and TestCoreScriptBudget ok;
  GOOS=linux and windows go vet ./internal/provider ok.
  Then rebased onto 3defaf662 (internal/agent dsh.go only); not rerun.
- New tests: TestStampLooksOnceARequest, TestClientShapeParsedOnceUntilWritten,
  TestLoginsListedOnceARequest, and TestAccountListsCopyNoLoginsUnchanged
  now counts the lock. Broken by hand, each goes red: "51 stamps in one
  request looked 51 times, want 1", "30 asks parsed the file 30 times",
  "20 plugin lists with nothing to change took the lock 20 times",
  "20 lists in one request listed 20 times".
- GOOS=linux and windows go vet ./internal/provider: ok. gofmt clean.
- Real config, on this Mac: a copy of the owner's ~/.config/magpie in an
  offline sandbox HOME (proxy :9), 200 GET /api/providers each:
  v0.1.2541 5.04s CPU (25.2ms a call, median 22.5ms wall), this change
  4.55s (22.8ms, median 20.3ms). The profile's stats under StampNow fell
  from 2.17s to 0.34s.

Not run: the full ./... suite; GUI (browser) tests, as nothing the page
gets changed. What is left in the profile: StepFun's sign-in file,
sync.json, plugin icons and agent detection, each read once a request.
2026-11-01 13:32:30 +08:00
yetone 40f206dff1 vertex: partner models (DeepSeek V4.1 Flash, GLM, gpt-oss) go to Google's OpenAI-compatible chat completions
Dani Ariyanto (Discord) asked for Vertex AI's partner/open models, such as
DeepSeek V4.1 Flash, beside Gemini. Google serves them (Model as a Service)
on an OpenAI-compatible chat completions endpoint in the same project,
https://<host>/v1/projects/<p>/locations/<loc>/endpoints/openapi/chat/completions,
with the same OAuth token. The model goes in the body as publisher/model
(deepseek-ai/deepseek-v4.1-flash-maas). Source: Google's
maas/call-open-model-apis page.

An existing Vertex provider needs no change. A model id with a slash
(VertexPartner) is a partner model, as is every publisher/model id that
models.dev lists for google-vertex as @ai-sdk/openai-compatible. It is
asked on Base(Chat) = <project base>/endpoints/openapi (ListedAPIs, so
ModelAPI can't move it). Gemini ids have no slash and stay on
streamGenerateContent. Speaks is now [chat, gemini].
- vertexEffort (Gemini's levels) no longer applies to a partner model.
  Before, a Codex xhigh was clamped to high.
- The provider's own test probes Gemini only. A partner model answers
  only after the project enables it in Model Garden, so an unenabled
  partner model would turn every Gemini user's test red. A partner model
  is tested by its own model test.
- tinyBody's chat probe uses Base(Chat), so the probe goes to the openapi
  address. That address is the only one Sign lets the token go to.
- A test as Codex is refused for Vertex, as it already is for Claude Code
  ("only of a relay").

The global list adds the three partner models that Google's docs list as
live at global on 2026-10-28:
- deepseek-ai/deepseek-v4.1-flash-maas (Preview, global only)
- zai-org/glm-5.2-maas
- openai/gpt-oss-120b-maas

Left out of the list: Gemma 4 (Experimental) and the models retired on
10-21 (v3.x, glm-4.7/5, qwen3, llama-3.3...). Gemma 4 still routes when
typed in by its full id. us/eu/regions are unchanged.

Docs: providers-accounts.md and gateway-routing.md Vertex rows;
reference.md (the global row, how a partner id routes, Model Garden
enablement, typing one in).

Run (on mote via mote-run):
- go test -tags nogui -run TestVertex ./internal/provider ./internal/gateway: ok.
- New: TestVertexPartnerModel (gateway). It covers Chat, Anthropic and
  Responses clients, streamed and whole, against a fake openapi endpoint
  answering in the shape of Google's docs. It checks the path, the Bearer
  token, the body model and the client's text, that Gemini stays on
  streamGenerateContent, and that xhigh is kept.
- New: TestVertexPartnerModels (provider). It covers Speaks/Base,
  APIs per model, the global list, no partner model at us/us-central1,
  that Test() probes Gemini alone, and TestModels on openapi with the
  minted token.
- TestVertexProviderListed now pins Speaks [chat gemini].
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build ./...: all ok; gofmt -l clean.
- Full suite: go test -tags nogui -count=1 -timeout 45m ./... at
  80f2bda50 (this change on cb167fcbd): SUITE-EXIT=0, 77 packages ok.
- An earlier full run at base 396e0e463 was red only in
  TestPluginStreamsPastTheBudgetWait. That is #3946, fixed in 7fd77a944
  after that base. It passed 3 of 3 alone at origin/main cb167fcbd.
- The final rebase onto b5d2858f4 (usage, a gateway test, LESSONS) was
  followed by go build and the TestVertex runs again; the suite was not
  run again.

Broken by hand:
- All nine non-test files restored to main, with VertexPartner kept so
  the tests compile: TestVertexPartnerModel red (asked
  publishers/google/models/deepseek-ai/...:streamGenerateContent with a
  Gemini body), TestVertexPartnerModels and TestVertexProviderListed red
  (speaks [gemini]).
- vertexEffort guard removed: red, "effort xhigh sent ... as high".
- Test()'s Vertex chat skip removed: TestVertexTestRequest and
  TestVertexPartnerModels red (a chat probe of the partner model).
- tinyBody back to q.Chat: TestVertexPartnerModels red ("asked only at
  Vertex AI, at its project's address").

Not tried:
- No real Vertex AI account or project here. Nothing reached Google:
  the endpoint, auth and response shapes come from Google's docs only.
- Per-model thinking controls (chat_template_kwargs: DeepSeek thinking,
  GLM enable_thinking) are not mapped. A partner model gets the generic
  chat completions reasoning_effort, and gpt-oss takes it natively.
- Claude on Vertex (publishers/anthropic rawPredict) is out of scope. It
  takes its own request shape and its ids have no slash.
- No GUI change (the API picker reads URL fields, which Vertex has
  none of), so no GUI suite was run.
2026-10-29 00:33:50 +08:00
yetone a84d2ec80f provider: two Codex windows no longer write client-shapes.json on every request (#3394)
SawClient keeps the headers a client last came with, and writes
client-shapes.json (read, unmarshal, marshal, synced temp, rename) when
they differ from what it last wrote. Each Codex window sends its own
X-Codex-Window-Id, which was taken as part of Codex's shape, so with two
or more Codex sessions on a keyed provider nearly every request rewrote
and fsynced the file. The window id and a retry's count
(X-Stainless-Retry-Count) are now left out, like the session and turn
ids already were.

Run (sandbox HOME, real deepseek account, three real `codex exec`
0.162.1 sessions through a -tags nogui build on :3482, 60s each,
counting the file's mtime/inode changes every 50ms):
  origin/main 20d63621d: 85 rewrites over 91 requests
  this change:            2 rewrites over 97 requests (the first strips
                          the window id kept before), keeping Originator,
                          User-Agent and X-Codex-Beta-Features
In the base run's 120s CPU profile (253 requests) SawClient's reads and
writes were ~0.22s of 7.5s.

TestClientShapeWrittenOnceForTwoWindows: ok; with test_as.go at HEAD it
FAILs ("client-shapes.json was written again for another window's
request"). go test -run 'TestAs|Shape|ClientHeader|CodexHeaders|
ClaudeCodeHeaders|AskedAs' ./internal/provider ./internal/gateway
./internal/cli ok. gofmt clean; go vet -tags nogui GOOS=linux and
windows ./internal/provider ok. Not run: the whole ./... suite.
2026-10-25 00:31:26 +08:00
yetone df2b44ef6c provider: a model's test can be asked as Codex or Claude Code asks, for a relay that serves only them (耍赖天都爱 on Discord)
A relay that serves only Codex or Claude Code tells them by their headers
("This account only allows Codex official clients"). The gateway already
lets those headers go on to a provider reached with a key, so the agents'
own requests were served, but the provider/model test is magpie's own
tiny request (Go's User-Agent), so it was turned away and said the
provider didn't work.

provider.TestAs(ctx, "codex"|"claude-code") asks Test and TestModels as
that agent asks. It goes to that agent's API (Codex: Responses, else Chat;
Claude Code: Anthropic Messages), streamed, store:false on Responses, and
with the headers the gateway last let through for it. The gateway notes
them with provider.SawClient beside the existing pass-through, without the
session, thread, turn, request id, subagent kind, anthropic-beta or
anything that signs. They are kept in client-shapes.json so the CLI has
them too.

Claude Code's headers are never made up. Until a Claude Code request has
come through magpie, the test says so. They are sent only to a relay,
never to anthropic.com, googleapis.com, Bedrock or Azure. A signed-in
account, a decision-only provider, and OpenCode/Cline/Kilo (which already
ask as their own client) are not offered it. Codex's fall back to the
headers a ChatGPT account's requests use (codexSign) until Codex has come
through.

Surfaces:
- CLI: magpie provider test <id> [--as codex|claude-code] [model…]
- GUI: a model chip's right-click has "Test as Codex" and "Test as Claude
  Code" where the provider offers them (providerJSON.testsAs). An item that
  can't run yet is off, with the reason shown. zh, zh-TW, ja, de strings.

Run:
- TestModelTestAsClient (internal/gateway). A fake relay 403s anything but
  codex_*/claude-cli/. The plain test gives 403. As Codex it is OK on
  /v1/responses with stream+store:false and codex_cli_rs headers. As
  Claude Code it is refused before Claude Code came, then OK after one
  Claude Code request through the gateway, with its UA/x-app/x-stainless
  but no session id or beta. Anthropic's API is refused. With the beta
  filter removed by hand the test goes red.
- model-test-as.test.cjs, Chromium and WebKit, en/zh/zh-TW/ja/de at
  420px: 10/10. On the old app.js it fails (no such items). Siblings
  model-test-one, model-copy-id, model-test-why, provider-typed: 28/28.
- Sandbox CLI (fake chat relay on :3571, sandbox HOME):
  - provider test relaya --as codex deepseek-chat sent
    codex_cli_rs/0.162.0 … with originator and version, stream:true.
  - --as claude-code said the relay has no Anthropic endpoint.
- go test -tags nogui ./internal/{provider,gateway,gui} and the root
  package under a temp HOME with pinned caches: ok. gofmt -l clean.
  go vet darwin/linux/windows on those packages: ok.
2026-10-10 15:08:14 +08:00