From 19794cc10ce5c96ef3d2f88020c970a62376fe97 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 16 Nov 2026 15:46:15 +0800 Subject: [PATCH] serve: a headless magpie follows a Remote magpie's agent picks (KoiLx0 on X) v0.1.4298 made a client magpie follow the models a Remote magpie's agents are on (agent.FollowRemotePicks), but only the app's Library loop (library.KeepLinked) ran it. `magpie serve` and `magpie serve --web` followed the remote's model list and efforts (the long-poll in the gateway) and never a pick changed on the remote. Both now run agent.KeepFollowingRemote, which calls FollowRemotePicks every 30s; it still asks the remote at most every 5 minutes, and only while a Remote magpie is added. Run at this head, on mica: - go test -timeout 45m ./internal/agent/ ./internal/cli/: ok - go vet; GOOS=linux go vet -tags nogui; GOOS=windows go vet: ok - Real use: two sandbox magpies (R with a fake OpenAI upstream and a gateway key, C with R as remote-magpie "office"), both `magpie serve`. Claude Code connected on R to openai/gpt-5.5: C recorded claude.model.remote at start. R's Claude Code moved to openai/gpt-5.4-mini at 15:41; C's ~/.claude/settings.json followed at 15:45:49 (the 5-minute step). Efforts set on R (low,high) and a new upstream model reached C's /v1/models, Codex's magpie-models.json and Claude Code's model list within seconds to about a minute, before and after this change. Not broken by hand: the loop is a ticker around FollowRemotePicks, whose following is covered by remote_picks_test.go. Not tried: Windows and Linux real boxes. --- internal/agent/remote_picks.go | 18 ++++++++++++++++++ internal/cli/providers_cli.go | 2 ++ internal/cli/web_cli.go | 3 +++ 3 files changed, 23 insertions(+) diff --git a/internal/agent/remote_picks.go b/internal/agent/remote_picks.go index a8807f2ba..57aed6d39 100644 --- a/internal/agent/remote_picks.go +++ b/internal/agent/remote_picks.go @@ -171,6 +171,24 @@ func FollowRemotePicks(ctx context.Context) { followRemote(ctx) } +// KeepFollowingRemote runs FollowRemotePicks until ctx ends, for a magpie +// with no app: the app's Library loop runs it there (library.KeepLinked), +// and a headless `magpie serve` client of a Remote magpie followed its +// model list and efforts but never a pick changed on the remote (KoiLx0 +// on X). +func KeepFollowingRemote(ctx context.Context, interval time.Duration) { + t := time.NewTicker(interval) + defer t.Stop() + for { + FollowRemotePicks(ctx) + select { + case <-ctx.Done(): + return + case <-t.C: + } + } +} + func followRemote(ctx context.Context) { cctx, cancel := context.WithTimeout(ctx, 2*provider.RemoteAgentModelsWait) picks := remotePicks(cctx, 0) diff --git a/internal/cli/providers_cli.go b/internal/cli/providers_cli.go index 0c11e9a5b..91898c1e2 100644 --- a/internal/cli/providers_cli.go +++ b/internal/cli/providers_cli.go @@ -1728,6 +1728,8 @@ func serve() error { // one's own Remote magpies follow it gateway.SetUpdater(serveUpdateAsked(follow)) go provider.KeepRemotesUpdated(ctx, version) + // the models a Remote magpie's agents are on, as the app follows them + go agent.KeepFollowingRemote(ctx, 30*time.Second) err := s.ListenAndServe(ctx) if exe := follow.restartTo(); exe != "" { // the plugin hosts end, waited for, first, as magpie web's diff --git a/internal/cli/web_cli.go b/internal/cli/web_cli.go index 17659acd7..295565858 100644 --- a/internal/cli/web_cli.go +++ b/internal/cli/web_cli.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/yetone/magpie/internal/agent" "github.com/yetone/magpie/internal/daemon" "github.com/yetone/magpie/internal/gateway" "github.com/yetone/magpie/internal/gui" @@ -241,6 +242,8 @@ func serveCmd(args []string) error { return serve() } go stats.Run(version, "serve") + // the models a Remote magpie's agents are on, as the app follows them + go agent.KeepFollowingRemote(context.Background(), 30*time.Second) w, err := gui.StartWeb(web, version) if err != nil { return err