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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user