Commit Graph
3 Commits
Author SHA1 Message Date
yetone 6e55914b6d provider: Codex accounts are read one at a time and renewed every 8 days, not all at once
owl (Discord #general) holds several ChatGPT accounts in magpie with
no agent wired and had three deactivated. Auditing what magpie sends
to OpenAI for such accounts found two bursts from one address that
the official Codex client never makes:

- KeepOnAnAccountWithRoom read /wham/usage for every saved Codex
  account, concurrently, every 5 minutes (every minute near the cap),
  though only the account Codex is on matters until it is spent.
  NextLogin now reads the account it is on and the one it goes back
  to, and the spares only once the one it is on is spent; CodexUsedUp
  reads the active account alone (codexReadingHeld only looks at it).
  The Claude side of the same loop gets the same rule.
- KeepLoginsAlive force-refreshed every idle saved ChatGPT sign-in
  once a day, all in the same hourly look, so after day one they were
  refreshed side by side for good. It now renews after 8 days (codex-rs
  TOKEN_REFRESH_INTERVAL in login/src/auth/manager.rs) and one account
  per hourly look, so they drift apart.

Not changed: headers, identity, originator, prompts. The refresh and
usage requests still go with Go's User-Agent and no originator, while
Codex sends codex_cli_rs and an originator; that is left for the
owner. The hourly /models list per saved account and the Usage page
reading every account when it is open are unchanged too.

Run (mote-run, at origin/main f5dd4e142 plus this change):
- gofmt -l internal/provider: clean
- go vet ./internal/provider (darwin), GOOS=linux -tags nogui,
  GOOS=windows: ok; earlier also ./internal/cli ./internal/gateway
- go test -count=1 -timeout 45m ./internal/provider ./internal/cli: ok
- go test -run of the 24 internal/gateway tests that reach NextLogin,
  CodexUsedUp or LoginUsageVia (allowance_stale, claude_renewed,
  codex_accounts, codex_app_out, quotas_remote): 24 PASS
- go test ./internal/agent: ok (before the stand-in copy fix below)
Broken by hand: with the old codex_switch.go, login_usage.go and
keepalive.go, TestCodexLookReadsTheActiveAccountOnly read all three
accounts in one look and TestKeepAliveRenewsOneALook failed on the 24h
interval; with keepAliveAtOnce = 0 it renewed both idle accounts in
one look.
Not tried: a real ChatGPT account; whether this traffic had anything
to do with owl's deactivations is not known.
2026-10-30 02:09:54 +08:00
yetone e698e7dddd claude: adding a Claude account is Claude Code's own claude auth login, and magpie never refreshes a Claude sign-in nor asks Anthropic anything with one (the user: 把 magpie 自己的 Claude 登录改成直接用 claude /login,只要体验上没什么差别就改) — magpie traded the sign-in page's code for tokens with Claude Code's OAuth client, asked Anthropic's profile and model list with them, refreshed saved accounts itself (daily keepalive included) and handed a saved account to Claude Code as CLAUDE_CODE_OAUTH_TOKEN. Now Add account runs claude auth login --claudeai in a config directory of magpie's own: the page Claude Code would open comes to magpie's window (Claude Code is given magpie as its BROWSER, which writes the page down and exits), the browser comes back to Claude Code's own listener, and when the browser can't reach this machine the address it ended on, or the code Claude's page shows, is pasted as before and handed to Claude Code. Who signed in is what Claude Code kept (.claude.json, auth status). A saved account in use beside the signed-in one runs Claude Code with CLAUDE_CONFIG_DIR set to its own directory (claude-accounts/ beside magpie's config), its sign-in put there once from logins.json and read back as Claude Code refreshes it; switching to it moves it into Claude Code's own store and removes the directory, as forgetting it does. Claude's models are the catalog's (models.dev), not asked of Anthropic; an imported Claude login is kept as the file has it, and Claude Code refreshes it on first use. Claude Code is required to add a Claude account. TestClaudeSignInByPaste, TestClaudeSignInByPastedAddress, TestClaudeSavedAccountDir (a fake claude CLI, and a server standing in for Anthropic that fails the test if asked) and the reworked sign-in, import and gateway tests fail without the change. With the real Claude Code 2.1.286 in a sandbox directory, its sign-in page (localhost callback) reached magpie's binary and the sign-in waited for the browser; nothing was left behind once it was canceled. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; claude-risk, plugin-signin, signin-callback, signin-link, signin-paste-codex, routing-signin, own-signin-remove, click-scroll, old-webkit pass. 2026-10-01 16:37:07 +08:00
yetone a1e546d4a1 provider: saved accounts are kept signed in — a Claude or ChatGPT account saved in magpie but not the one the agent is on was refreshed only when used or its usage looked at, and smart routing leaves the ones waiting their turn idle for days; the magpie serving the gateway now renews each such sign-in about once a day (hourly check, so a machine that slept catches up), never the agent's own; a refresh the vendor refuses (400/401) marks the account signed out — the account list says to add it again, magpie accounts too — and one that succeeds clears it; magpie accounts refresh renews them all now, for cron or launchd; a switch waits for a refresh in flight, so the agent is never handed a refresh token being spent (#53) 2026-09-25 19:22:37 +08:00