f2eb56c6bbde1300dddc402861b59cd4e45e0215
6
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
85cde4a4de |
provider: Codex and ChatGPT API refreshes lock across magpies
Two magpies can now run at once: a restart to update hands the gateway
over and the old one finishes its requests for up to 15 minutes (next
commit), and a magpie run from a terminal can sit beside the app. Codex's
auth.json and the ChatGPT API sign-in rotate their refresh token on every
refresh. Their refresh locks (codexMu, siwcRefreshing) were a sync.Mutex,
held in one process only. So both magpies could refresh with the same
refresh token, and the second got refresh_token_reused, which signs the
account out.
Both are now a filelock.Mutex beside logins.json (.codex.lock,
.siwc.lock). The sign-in is read again once the lock is held, so a magpie
that waited uses the tokens the other one wrote instead of refreshing
again. Claude's saved tokens, MCP servers' and plugins' were already
locked across processes. Google's, Vertex AI's and Copilot's refresh
tokens don't rotate. Docs: providers-accounts.md, Constraints.
Tests: TestCodexRefreshWaitsForAnotherMagpie and
TestChatGPTAPIRefreshWaitsForAnotherMagpie. Each holds the file lock as
another magpie would, mid-refresh, writes that magpie's rotated tokens,
then lets go. The refresh must return those tokens and send nothing to
the token endpoint.
Broken by hand: with both locks put back to sync.Mutex, both tests are
red ("refreshed 1 times beside another magpie").
Run: see the next commit's body. The provider package ran at the pushed
head with -timeout 45m.
Not tried: a real Codex or ChatGPT API account refreshing in two magpies
at once. The tests use fake token endpoints.
|
||
|
|
40df6dbd38 |
provider: a subscription sign-in canceled while its token is fetched adds no account (#2054)
A sign-in checked canceled/finished only when its callback was claimed. The token exchange after that went on to addLogin / addGoogleLogin / addSideLogin and only then called finish, a no-op after CancelSignIn, so a sign-in the user canceled while its token was in flight still added the account, or replaced an existing account's tokens. Sibling of #1750 (mcpauth's flow.keep, |
||
|
|
2a8a9aecfa |
provider: signing out of ChatGPT and Devin's CLI checks go through the account's own proxy, as its sign-in does (#1663, demystify0137)
What changed: two siblings of
|
||
|
|
437bf023b8 |
codex, chatgpt-api: a conversation with tools reuses its cached prompt, its session sent in session-id/thread-id as Codex 0.162 sends it (#1473 inthink, #933 Scallions)
The ChatGPT backend looks up a conversation's prompt cache by the session headers, not by the body's prompt_cache_key. I probed a real Pro account (gpt-6.1-sol, 13 tools, about 7.6K-token prompt) directly: - key in body only, 6 requests: cached 0 every time - no key and no headers: 0 every time - session-id + thread-id: 0, then 7552 x5 - old session_id/conversation_id: 0, then 7552 - a bare request with no tools: 4096 every time. That is the instructions' shared cache, so #1473's "bare requests hit" pattern fits this. Codex CLI 0.162 (captured with codex exec against a fake server) now sends only session-id and thread-id. It no longer sends the underscored names, which a proxy may drop. Changes: - codexSign: sets session-id and thread-id from the prepared body's key (sessionHeaders). It drops the underscored names. A keyless body keeps the session the client named. - codexHeader: relays session-id/thread-id from Codex clients. - ChatGPT API (SIWC) provider: it sent only Authorization. Now it names the conversation (conversationKey for keyless clients) and sends the same session headers. Scallions' screenshots: chatgpt-api/ got 0% cache where codex/ got 10-99%. This was NOT tried against api.openai.com with a real ChatGPT API sign-in, since none is available here. Left for the reporter to confirm. Run: - Sandbox magpie on a real Codex account, client sending no key: old build cached 0/7296 erratically; new build 0, 0, then 7296 x4. - go test ./internal/provider ./internal/gateway: ok. - Break check: reverting codex_request.go and chatgpt_api.go turns TestCodexSignSessionHeaders, TestCodexSignAndBody and TestChatGPTAPISession red. - gofmt -l: clean. GOOS=linux and GOOS=windows go vet: clean. base_instructions and the identity line are unchanged. |
||
|
|
b0607ef5a6 |
provider: the ChatGPT API subscription lists, beside the models its account catalog lists, those Codex lists for the plan, which the token runs though the catalog leaves them out (#933, knothhe)
knothhe found the ChatGPT API account listing far fewer models than pi, while gpt-6-luna, added by hand, ran. OpenAI's catalog for a Sign in with ChatGPT token (GET api.openai.com/v1/models, its visibility "list" entries, as OpenAI's Models and inference page says to show) leaves out models the token runs: fastagent's run on a real account (fastagent-sh/fastagent#698) found 5 listed, and gpt-6-luna, gpt-6-sol and gpt-6.1-sol running though not in it at all, while pi lists its 44 built-in openai models, 36 of which answer "not supported when using Codex with a ChatGPT account". The token is served as Codex on the plan, so the list now adds to the catalog's models the ones Codex lists for a ChatGPT plan: the list magpie's Codex subscription last fetched, else Codex CLI's models_cache.json. A model the catalog hides stays out, and so do magpie's own in Codex's list. TestChatGPTAPIListsCodexModels is new and fails without the change (models [gpt-5.5 gpt-5.4-mini], no gpt-6-luna). Tested against fake OpenAI servers; not yet with a real ChatGPT API account. go vet, go build (GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. |
||
|
|
7a926dd3ce |
provider, gateway, gui: a ChatGPT plan can be signed in with OpenAI's Sign in with ChatGPT, as the ChatGPT API subscription, and asked on api.openai.com's Responses with the agent's own instructions (#933, knothhe)
OpenAI's Sign in with ChatGPT lets an open-source app on the user's machine use their ChatGPT plan through the public API: it registers itself on the way (client_id dynamic_agent_client, an ext_agent_host_id kept for this machine, agent_name_hint magpie), the callback brings the client id OpenAI issued, and the token (scope chatgpt.tokens.use.direct, resource https://api.openai.com/v1) is sent as a Bearer to api.openai.com/v1/responses. The new subscription, chatgpt-api ("ChatGPT API" in the add sheet, beside Codex's ChatGPT), signs in so in magpie (PKCE, a loopback callback on 1455 or any free port, the ID token's issuer, audience, nonce and expiry checked), keeps its accounts as the other in-magpie sign-ins do, refreshes under the issued client id (rotated refresh token, serialised; a refresh token OpenAI won't take again marks the account to sign in again), revokes it on sign-out, and lists the models /v1/models gives the token. Requests go with the agent's own instructions — no Codex prompt, no Codex headers; the Codex path is unchanged — stored nowhere and streamed, without the fields the API refuses for a ChatGPT token (max_output_tokens, temperature, prompt_cache_retention, …) and without hosted tools; a system message is a developer one. OpenAI's subscription_sharing_* refusals are said with what to do (the plan's usage at chatgpt.com/settings/usage, an ineligible account, a capability the token can't use). There is no usage meter: the token has no usage API. Tested against fake OpenAI auth and API servers (TestChatGPTAPISignIn, …Refused, …Refresh, …Body, …Explain; gateway TestChatGPTAPIRequests over chat completions, messages and responses) and the add sheet in Playwright on Chromium and WebKit (chatgpt-api-sub.test.cjs); the gateway and GUI tests fail without the change. Not yet signed in with a real ChatGPT account: the consent page needs the account's owner. go vet, go build (GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. |