agents: a magpie on a port of its own (magpie-dev, a sandbox) takes an agent wired to the installed magpie's gateway (127.0.0.1:3425) for that one's, not drift — the two took turns flagging Codex with Apply again, each rewiring it to itself

This commit is contained in:
yetone
2026-09-27 14:54:35 +08:00
parent c46840a0b0
commit f7e38d0d2e
2 changed files with 44 additions and 1 deletions
+23 -1
View File
@@ -114,7 +114,7 @@ var started = time.Now()
// A field moved from one magpie model to another (the agent's own picker)
// isn't drift; one moved off magpie is.
func (a *Agent) Drift() *Drift {
if len(a.Fields) == 0 {
if len(a.Fields) == 0 || a.theInstalled() {
return nil
}
vals := a.Values()
@@ -162,6 +162,28 @@ func (a *Agent) Drift() *Drift {
return nil
}
// installedURL is the gateway of the magpie people install, on its own
// port; a magpie on another one (magpie-dev, a sandbox) is run beside it.
var installedURL = "http://" + gateway.DefaultAddr
// elsewhere: this magpie is not on the installed one's port.
func elsewhere() bool { return !sameHost(gateway.URL(), installedURL) }
// theInstalled: this magpie runs beside the installed one, and the agent is
// wired to that one's gateway, not this one's — the installed magpie set it
// up, so it is that one's to check, not drift here. Otherwise the two would
// take turns flagging each other's wiring.
func (a *Agent) theInstalled() bool {
if !elsewhere() || a.Path == "" {
return false
}
b, err := os.ReadFile(a.Path)
if err != nil {
return false
}
return strings.Contains(string(b), gateway.DefaultAddr) && !strings.Contains(string(b), hostOf(gateway.URL()))
}
// bypassed: the agent was used — while this gateway was up and after magpie
// last set it — and no request of it arrived since. A request leaves within
// moments of the prompt; a little grace keeps one in flight from counting.
+21
View File
@@ -237,3 +237,24 @@ func TestCodexDriftReached(t *testing.T) {
t.Fatalf("reached magpie: %+v", d)
}
}
// A magpie on a port of its own (magpie-dev) runs beside the installed one:
// an agent that one wired to its gateway is not drift here, while one wired
// to neither still is.
func TestDriftInstalledMagpie(t *testing.T) {
t.Setenv("MAGPIE_ADDR", "127.0.0.1:3426")
home, _ := codexHome(t, "", "")
cx := codex(home)
if err := cx.Apply("model", "fake/m1"); err != nil {
t.Fatal(err)
}
cfg := filepath.Join(home, ".codex", "config.toml")
os.WriteFile(cfg, []byte("openai_base_url = \"http://"+gateway.DefaultAddr+gateway.CodexPath+"\"\nmodel = \"fake/m1\"\n"), 0o644)
if d := cx.Drift(); d != nil {
t.Fatalf("the installed magpie's wiring taken for drift: %+v", d)
}
os.WriteFile(cfg, []byte("openai_base_url = \"http://127.0.0.1:9999"+gateway.CodexPath+"\"\nmodel = \"fake/m1\"\n"), 0o644)
if d := cx.Drift(); d == nil || d.Kind != "unwired" {
t.Fatalf("wired to neither: %+v", d)
}
}