From f25871cddcd3c719e229fa0aa44dbfc3443eea79 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 28 Oct 2026 13:57:45 +0800 Subject: [PATCH] agent: the Codex app's route is read from one look at Codex's config (#1665) KeepCodexAppOnItsProvider asks codexAppRoute every 3s for as long as magpie runs, and it read config.toml's keys one getter at a time, each a look at the disk: 42 looks in 25s on Windows, where an antivirus works on each. It now holds what it read (filememo.Hold) for the call, so each tick looks once, and its keys come from one version of the file. Measured on xiaomi-gpu (Windows 11), an empty sandbox HOME, magpie web --gateway, second start, 27s, counting looks with an uncommitted build, with the warm-up's hold (fcbbb8e47) in both: codexAppRoute's looks 42 to 8, all looks 483 to 448. Run (mote): gofmt -l internal/agent clean; go vet ./internal/agent for darwin, windows and linux (-tags nogui) clean; go test -count=1 ./internal/agent ./internal/provider ok. Not tested by its own test: nothing in codexAppRoute lets a test write between its getters. --- internal/agent/agents.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/agent/agents.go b/internal/agent/agents.go index d9d8ef314..7cba1f772 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -17,6 +17,7 @@ import ( "github.com/yetone/magpie/internal/appdir" "github.com/yetone/magpie/internal/catalog" "github.com/yetone/magpie/internal/edit" + "github.com/yetone/magpie/internal/filememo" "github.com/yetone/magpie/internal/gateway" "github.com/yetone/magpie/internal/proc" "github.com/yetone/magpie/internal/provider" @@ -59,6 +60,9 @@ func init() { // its used-up ChatGPT account (AppOut). Not known when Codex's config // can't be read. func codexAppRoute() (route string, out, known bool) { + // asked every 3s for as long as magpie runs: the config looked at once + // for its keys, not once for each (#1665) + defer filememo.Hold()() home, _ := homes() a := codex(home) if _, err := os.ReadFile(a.Path); err != nil && !errors.Is(err, fs.ErrNotExist) {