Files
magpie/docs
yetone 06c4582cca remote magpie: a list changed on the other magpie reaches this one's agents at once
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)
2026-11-06 20:57:55 +08:00
..