Skip to content

feat(codex): show system-default/real-home account identity in switcher (PR-B) - #9176

Closed
brennanb2025 wants to merge 2 commits into
brennanb2025/codex-home-consolidationfrom
brennanb2025/codex-ma-b-identity
Closed

brennanb2025 wants to merge 2 commits into
brennanb2025/codex-home-consolidationfrom
brennanb2025/codex-ma-b-identity

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

What & why

The account switcher modeled the system-default Codex account as activeAccountId:null with no identity fields (src/shared/types.ts). Under real-home routing the null account's effective identity is "whatever ~/.codex/auth.json currently is," but it rendered blank ("System default" + a generic subtitle), and managed-account switches never touch ~/.codex so it couldn't track or display a stable identity. Env-key/custom-provider logins (no ChatGPT usage) also had nothing to render.

This PR surfaces a real, live, read-only identity for the system-default / real-home account and renders activeAccountId:null as that identity.

Changes

  • src/shared/types.ts — new CodexSystemDefaultIdentity descriptor { hasAuth, authKind: 'oauth' | 'api-key' | 'none', email, providerAccountId, workspaceLabel }, added as optional systemDefault on CodexRateLimitAccountsState (optional so WSL/remote/empty states are unaffected).
  • src/main/codex-accounts/service.ts — getSnapshot() (returned by listAccounts()) now resolves the descriptor live and READ-ONLY from ~/.codex/auth.json. OAuth → email/provider; auth.json with OPENAI_API_KEY (or an OPENAI_API_KEY env with no auth.json) → api-key; no auth.json → none. Reuses the existing JWT/identity parsing via extracted extractOAuthCredentials/resolveIdentityFromCredentials (no behavior change to managed add/re-auth). It flows unchanged through IPC and the remote getAccountsSnapshot() RPC, so each runtime reports its own host's ~/.codex.
  • Renderer switcher (AccountsPane.tsx) — the system-default row subtitle now shows the OAuth email when signed in, "Custom provider — no usage tracked." for env-key/custom-provider, or the generic fallback when signed out. Host-scoped (per-distro WSL keeps the generic label).

Attribution & the fetcher (deliberately not changed)

Usage for the null account already routes to the real home via prepareForRateLimitFetch → getSystemCodexHomePath() (unchanged), so the switcher now attributes it to a real, displayed identity. The env-key (no auth.json) case is already reported cleanly as status: 'unavailable' (no usage) by the existing presence gate (codex-auth-presence.ts). I prototyped an api-key short-circuit in codex-fetcher.ts but reverted it: it added an auth.json read + parse to every poll on the hot path for all users (OAuth included) to catch a rare case, and perturbed fake-timer RPC/PTY tests that read the real ~/.codex. The clean "custom provider / no usage" rendering is fully delivered by the descriptor-driven switcher instead. Happy to add a fetcher-side relabel as a follow-up if the status-bar (separate surface) api-key-auth.json edge is in scope.

Guardrails

  • Never mutates ~/.codex — the identity read is read-only; a dedicated test asserts select/deselect of a managed account leaves ~/.codex/auth.json byte-identical.
  • No flag-OFF regression — the descriptor read is flag-agnostic; with the real-home flag OFF the runtime home still mirrors ~/.codex, so the displayed identity matches. No runtime-home-service/flag code touched.
  • No max-lines disables added (ratchet check passes). Localization catalog synced (sync:localization-catalog) across all 5 locales. Follows AGENTS.md / STYLEGUIDE.md.

Test evidence

Sandboxed temp homes only (homedir() mocked):

  • src/main/codex-accounts/service.test.ts (+5): OAuth email/provider resolution; api-key auth.json → custom provider; env OPENAI_API_KEY (no auth.json) → custom provider; signed-out → none; select/deselect never mutates ~/.codex.
  • Full affected suite green: service.test.ts, codex-fetcher*.test.ts, rate-limits/service.test.ts, provider-account-visibility.test.ts, codex-account-auth-warning.test.ts, status-bar-runtime-groups.test.ts, runtime-provider-accounts-client.test.ts (114 passed).
  • pnpm run typecheck:node ✅ and pnpm run typecheck:web ✅. oxlint clean; max-lines ratchet OK; localization verify OK.

Addresses matrix rows 2, 3, 4, 5.

…er (PR-B)

The account switcher modeled the system-default Codex account as
activeAccountId:null with no identity fields, so the null row rendered
blank ("System default" / generic subtitle) even though its effective
login is whatever ~/.codex/auth.json currently is.

Add a CodexSystemDefaultIdentity descriptor {hasAuth, authKind, email,
providerAccountId, workspaceLabel} to CodexRateLimitAccountsState,
resolved live and READ-ONLY from ~/.codex by the accounts service and
returned from listAccounts()/getSnapshot(). The settings switcher now
renders the null (system-default) row as that real identity: the OAuth
email when signed in, "Custom provider — no usage tracked." for
env-key/custom-provider logins (auth.json with OPENAI_API_KEY, or an
OPENAI_API_KEY env with no auth.json), and the generic fallback when
signed out. Identity is host-scoped (per-distro WSL keeps the generic
label). Orca never writes ~/.codex; managed-account switches only touch
Orca-owned homes, so the system-default identity stays a stable,
displayed source of truth. Usage already routes to the real home via
getSystemCodexHomePath, so the switcher now attributes it to a real face.

Tests (sandboxed temp homes only): OAuth email/provider resolution,
api-key auth.json and env-key (no auth.json) as custom-provider,
signed-out, and select/deselect of a managed account never mutating
~/.codex/auth.json.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing as superseded: #9501 (real-home routing + self-contained multi-account homes) explicitly lists this draft as superseded in its description, and that consolidation merged and shipped in v1.4.149 stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant