clyzhicore (Discord) runs a server magpie as the gateway and a local magpie
that takes its /v1/models and writes the models into dsh. They asked for
an ETag or a list you can wait on, so the local side knows a change at
once and a dead connection costs little. The wait is there since
06c4582cc (v0.1.3172: X-Magpie-List-Wait with If-None-Match, and the
Remote magpie follower). What was missing, and is added here:
- A plain GET /v1/models (no wait header) is answered with the same ETag
a wait answers (listTag of the bytes this caller gets), Cache-Control
private, no-cache, and 304 with no body, at once, when If-None-Match
names it (strong or W/, in a comma list, or *). A tag it doesn't name,
or none, is answered the list as before, same bytes. A refused list
(400) stays untagged. Any client (a script, curl, another tool) can
now poll cheaply.
- A wait's answer, 200 or 304, says in X-Magpie-List-Wait how many
seconds it held. A plain answer doesn't.
- The follower (waitRemoteList) takes a 304 that comes sooner than
followQuick (5s) without that header as a magpie that doesn't wait.
This guards the change above: a proxy that drops X-Magpie-List-Wait
would now get a tagged plain list and an instant 304, and the follower
would ask every followGap (1s). It now leaves such a magpie to its
schedule and asks again after followOldAgain (1h), as for one from
before the wait. Servers from 06c4582cc on hold each wait to its end
(50s), so their 304s pass.
Compatibility: an old server (no ETag) is still left to the schedule,
as TestRemoteMagpieOldListNotFollowed checks. An old client never sends
If-None-Match without the wait header and gets the same bytes plus an
ETag. The GUI doesn't read the gateway's /v1/models through Wails (whose
304 on WebView2 is a 505, gui/api.go writeJSONSame), so that doesn't
apply.
Hidden models (their second ask) already exist and are not changed: a
provider's "Only through routing groups" (Provider.Unlisted, `magpie
provider listed <id> no`) and a group's listed=no (Group.Unlists, `magpie
group set ... listed=no`, CLI only) keep models out of /v1/models while
groups still route to them.
docs/subsystems/gateway-routing.md says the above.
Run (on mote, through mote-run, first at 04ed05733):
- gofmt -l on the changed packages: clean.
- go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet
./...; go build ., GOOS=linux -tags nogui, GOOS=windows: all ok.
- go test -tags nogui -race -count=1 -timeout 90m ./internal/gateway:
ok 2145s, no DATA RACE (mote at load ~100-130).
- go test -tags nogui -count=1 -timeout 45m ./internal/provider: ok 126s.
- After rebasing onto origin/main (5 commits, none in these files):
gofmt -l clean; go vet (darwin, linux nogui, windows) of both
packages ok; -race -run "ModelsWait|ModelsList|RemoteMagpie": gateway
ok 12.5s, provider ok 4.8s.
Broken by hand, each red:
- models() back to listModels (no tag on the plain list):
TestModelsListConditional ("ETag \"\"") and TestModelsWaitTagged ("a
plain list: 200, ETag \"\"").
- tagNamed never matching: TestModelsListConditional (200 with the body
for each of the tag, W/, a list and *).
- No X-Magpie-List-Wait on a wait's answers: TestModelsWaitTagged ("a
wait's list says it held \"\"", same for its 304).
- The followQuick check off: TestRemoteMagpieStrippedWaitNotAskedOver
("asked 28 times in 300ms, want 2").
Not tried: two real magpies, or a real reverse proxy that drops the
header (the stripped case is a fake in the test). Not run on Windows or
Linux. The full suite (go test ./...) and the GUI suite: not run at push.
Following a provider added as a plain OpenAI-compatible endpoint (not the
Remote magpie type) is not done: its list URL comes from fetchOne's
several bases, and it still goes by its #2135 schedule.
Reported-by: clyzhicore (Discord)
KaCli (Discord) runs two magpies: the server's is the gateway, and the
local one has it as a Remote magpie and writes its models into dsh. A
route or group changed on the server reached the local dsh only on the
next 10-minute fetch (#2135's RemoteMagpieEvery). The server knows when
its list changes (filememo), so it now says so.
- Server: GET /v1/models with X-Magpie-List-Wait: <secs> and
If-None-Match answers the list with an ETag once it differs from that
tag. It answers 304 at the end of the wait (at most 50s, under a
proxy's 60s) or as the gateway stops. The list is looked at again on
each magpie write and on each change another process makes to its
files (filememo.Written). It is the list's own route, so the key,
lanGuard, corsGuard and a key's models judge it as before. The wait is
exempt from holdCatalog, and each look holds the catalog for itself.
Without the header the answer is the same as before, with no ETag.
- Client: KeepRemoteListsFollowed (started beside KeepListsFresh) keeps
one long-poll per Remote magpie. On a new tag it fetches the list
through the same RefetchTaking, so catalog.Touched rewrites the
agents' configs. A magpie from before answers at once with no ETag; it
is left to the 10m schedule and asked again after an hour. A Remote
magpie whose user set its list to "off" is not followed. The schedule
stays as the fallback.
Run (on mote, through mote-run):
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...; go build ./..., GOOS=linux -tags nogui and
GOOS=windows builds: all ok.
- go test -tags nogui -count=1 ./internal/gateway ./internal/provider
./internal/catalog ./internal/filememo: all ok (gateway 863s, provider 152s, catalog, filememo).
- After the rebase on 650bf8412 (11 files changed under gateway and
provider since): go vet of both, go build ./..., and -run
"ModelsWait|RemoteMagpie|ListsFresh|HoldCatalog|Models" of both: ok.
- Two real magpies (this build, `serve`, sandbox HOMEs, 127.0.0.1:3561
server and :3562 local, a gateway key, dsh profile web wired to
office/up/m1). `magpie group add kacli-fast` on the server put
office/group/kacli-fast in the local cordis.patch.yml in 1.14s
(log: "office: its list changed there, fetched again: 3 models"). 130s
idle after it: no further fetch.
Control: origin/main on both, nothing in 37s. origin/main server, this
local: nothing in 37s, logged once "doesn't wait ... fetched on its
schedule", asked once.
Broken by hand, each red:
- Without the dispatch to the wait: TestModelsWaitTagged,
AnswersAChange, EndsWithTheGateway.
- Without the filememo.Written wake: TestModelsWaitAnswersAChange
(answered after 5.0s, at the others timer).
- Without RefetchTaking in the follower: TestRemoteMagpieListFollowed.
- Without the RefreshInterval > 0 check: TestRemoteMagpieOffNotFollowed
(asked 3 times).
- Removing the holdCatalog exemption is caught by no test: a held
catalog is still dropped on a write (heldFreshLocked), so the change is
seen. It is kept so a 50s hold doesn't pin the build, as with a
WebSocket.
Not tried: across two real computers on a LAN, or behind a reverse
proxy (only loopback with a key, and the LAN/no-key, foreign Origin and
Origin null refusals in TestModelsWaitGuardedAsTheList). Not tried on
Windows or Linux. Agents other than dsh weren't checked, though they go
through the same catalog.Touched sync.
Reported-by: KaCli (Discord)