plugin load: a model listed by another id gets its plugin's load (axelburks)

axelburks on Discord: a plugin reports a model's load through
input.magpie.load by its own model id. A model the user lists in magpie
under another id (Listed as, settings' ModelIDs) showed no load on the
Providers page, and with Busy models last on it was never judged busy;
models whose id wasn't changed worked. The reporter's reading was right:
plugin.ModelLoad keeps the load by the plugin's id and both callers asked
it by the listed one.

Both call sites of plugin.ModelLoad (grep: there are only two) now map the
listed id back through Provider.OwnModelID first:
- internal/gui/providers.go providerInfoWith (models[].load), which
  already computed OwnModelID for models[].vendor; it is now read once
  and used for both.
- internal/gateway/fallback.go busyOf (restLast's busy ordering and the
  trace's busy).
A listed id whose own id is a model@size (grok -> grok-4.7@256k) still
falls back to the model's load inside ModelLoad. The provider-plugins
subsystem page says the lookup is by the plugin's own id.

Tests:
- internal/gui TestModelLoadListedAsAnotherID: a plugin provider with
  fast -> big and grok -> grok-4.7@256k listed, loads noted for big,
  grok-4.7 and small; models[].load must be 87.4 / 60 / 12 for fast /
  grok / small and absent for quiet.
- internal/gateway TestBusyModelListedAsAnotherID: busyOf at 80 judges
  fast, grok and big busy, and an unreported model not.

Run at the pushed head on mote (mote-run):
- at base de7953e3b with this change: gofmt -l clean; go vet of
  internal/gui, gateway, plugin for darwin, GOOS=linux (-tags nogui) and
  GOOS=windows: ok. go test -count=1 -timeout 45m ./internal/gui
  ./internal/gateway ./internal/plugin: plugin ok; gui red only on
  TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27 corners) and
  gateway red only on TestCodexPoolSaysTheClientsVersion (#4807, another
  test's Codex identity in a full package run); both filed, neither
  touches loads. internal/gui/tests/model-load.test.cjs (Chromium and
  WebKit, every language, narrow and wide): 82 of 82 pass.
- at the pushed head 7a804cf03 (rebased; the rebase changed none of the
  touched files): vet for the three OSes ok, and go test -run
  "Load|Busy|ListedAs" of internal/gui, gateway and plugin: ok.

Broken by hand: with both call sites put back to m.ID / c.model, both new
tests fail ("fast: no load, want 87.4", "grok: no load, want 60";
"fast: load 0 busy false", "grok: load 0 busy false"); restored, both pass.

Not tried: a real plugin reporting loads in the running app with a
renamed model (the reporter's in-house vendor plugin isn't available
here); model-load.test.cjs fakes the API, so it checks the badge's
drawing, not this lookup. No full go test ./... (another session's full
suite was running on mote).
This commit is contained in:
yetone
2026-11-02 03:40:03 +08:00
parent d2a83de612
commit eb3b9376ea
5 changed files with 96 additions and 6 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ A plugin can tell magpie of a request it sent its vendor on its own, outside any
A plugin can say how busy each model is (axelburks on Discord: an in-house vendor queues requests to its busy models, and a load put in the model's name changed only when the list did). It calls `input.magpie.load(provider, {"<model id>": 0 and up | null})` whenever it likes, from its own timer, as usage data refreshes; magpie never asks. The host ([`host.js`](../../internal/plugin/host.js) `reportLoad`) throws a TypeError for a provider that isn't a string of 1–200 characters or a `loads` that isn't a plain object, clamps each finite number to 0–10000 (`LOAD_MOST`, `plugin.LoadMost`: past 100 is a vendor that queues, 200 twice what it serves at once, axelburks again; 10000 is a sanity cap), sends `null` as -1 (cleared), drops every other value and an id over 200 characters, takes at most 1000, and sends what is left as an unasked `{event:"load", provider, loads}` (`dispatch` in [`host.go`](../../internal/plugin/host.go)). It returns how many it took.
[`load.go`](../../internal/plugin/load.go) keeps each by the plugin's provider id and the model id lowercased, with when it came (`noteLoads`, at most 1000 a provider). `ModelLoad(provider, model, now)` answers it, a model@size falling back to its model, and unknown once it is older than `LoadFresh` (5 minutes): a plugin that stops reporting leaves its models unknown, never idle. Nothing is saved; a restart starts with none known.
[`load.go`](../../internal/plugin/load.go) keeps each by the plugin's provider id and the model id lowercased, with when it came (`noteLoads`, at most 1000 a provider). `ModelLoad(provider, model, now)` answers it by the plugin's own id of the model (its callers, the provider editor and `busyOf`, map a model the user lists by another id back through `OwnModelID` first), a model@size falling back to its model, and unknown once it is older than `LoadFresh` (5 minutes): a plugin that stops reporting leaves its models unknown, never idle. Nothing is saved; a restart starts with none known.
The provider editor shows it by the model as a grey badge (`/api/providers`' `models[].load`, `loadTag` in app.js). Routing reads it only when the user sets *Busy models last* (`settings.BusyLoad`, `POST /api/settings/busy-load {at}`, off by default): see `restLast` and `busyBehind` in [gateway routing](gateway-routing.md).