Commit Graph
2 Commits
Author SHA1 Message Date
yetone cb7f442785 gateway: Codex's /models builds magpie's providers once, and cursor-agent's Keychain token is read once a while (#746, sperwe: /backend-api/codex/models called All() over and over, rescanning accounts and running /usr/bin/security some 200 times, 5.3–5.6 s against about 1 s straight to the backend, past Codex's 5 s model refresh, so Codex fell back to the official list) — after the ChatGPT backend's list, codexModels read magpie's: CodexListed (CatalogFor's catalog, and AutoVision through codexListed's descriptions), CodexNativeWindow, CodexNativePicked and CodexListTag (CodexListed again, codexWindowsTag), seven builds of All() in a test with one provider, each going through Accounts() and every agent's sign-in; a plugin's accounts ask pluginOwnUser, and for a Cursor moved onto its plugin that is cursorSignedOut, a security find-generic-password each time. All() now goes through the hold the GUI's reads use (heldOf, dff14ff4): while a request holds the catalog it is built once (a clone each call, so a caller's change stays its own; resolveIn's own heldOf("all", All) is plain All() now), and codexModels takes the hold (provider.Hold) for what follows the backend's answer. A hold is dropped by a write, as before (store → catalog.Touched → Changed, a plugin's sign-in), and now also by writeLogins and forgetAccountCaches, so an account signed in, switched or removed while one is held is seen at once; a sign-in changed outside magpie shows within the hold's second (heldFor). cursor-agent's Keychain token (readCursorToken, cursorToken) is read at most once in 10 s (cursorTokenTTL, as claudeCacheTTL); forgetCursorStatus, which a sign-in or out in magpie calls, drops it, and CursorToken reads it afresh after asking cursor-agent to renew it, so a renewed or new token isn't missed. AllBuilt counts builds for tests. TestCodexModelListBuildsProvidersOnce counts one build for one /models request (7 on the old code), TestHoldBuildsProvidersOnce one build for two All() calls under a hold, a caller's change not leaking, a provider saved and logins written while held being seen, and TestCursorKeychainReadOnce, with a fake security on PATH, one run for three reads, a fresh one after forgetCursorStatus and after a fresh read. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. Not timed with the reporter's accounts: here the request built the providers 7 times and builds them once, so their ~200 security runs should come to about a seventh, Cursor's from one a build to one in 10 s; the GUI's held reads (GET /api/*) now share one All() too. 2026-10-04 12:15:40 +08:00
yetone 7911002497 gateway: Codex's model list answers within 3 s even when chatgpt.com is slow, so magpie's models are in it (#539: Codex 0.159.2 in ChatGPT mode on v0.1.641 shows no relay models) — in ChatGPT mode Codex asks openai_base_url (magpie's /backend-api/codex) for GET /models, and magpie answered only after the ChatGPT backend had answered it, waiting as long as the gateway client lets a response's headers take (10 min). Codex's models manager gives that fetch 5 s (MODELS_REFRESH_TIMEOUT) and on a timeout keeps its bundled list, which has none of magpie's models; where chatgpt.com is slow or hangs (in China, through a proxy) that is every time. Both Codex 0.159.2 (from npm) and 0.160.0, run in a sandbox HOME against a fake gateway, list magpie's models from /models in codex debug models and the app-server's model/list, and show only their own when the answer takes 6 s. codexModels now gives the backend 3 s (codexModelsWait); past that it answers from Codex's own models_cache.json and magpie's models, as it does when the backend can't be reached. A 401/403 from the backend is still passed on as it was. TestCodexModelListBackendSlow (a backend that never answers: magpie's and the cached models come back within 3 s) fails without the change. No request was made to OpenAI. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-02 16:48:26 +08:00