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.
This commit is contained in:
yetone
2026-10-28 13:57:48 +08:00
parent 7b007e9866
commit f25871cddc
+4
View File
@@ -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) {