Skip to content

Add shared-home account session switching - #1

Open
patrickallensimpson wants to merge 2 commits into
mainfrom
feature/shared-home-account-sessions
Open

patrickallensimpson wants to merge 2 commits into
mainfrom
feature/shared-home-account-sessions

Conversation

@patrickallensimpson

@patrickallensimpson patrickallensimpson commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • implements the existing v2 accountSession/add, accountSession/list, accountSession/switch, and accountSession/logout protocol
  • keeps one shared CODEX_HOME for threads, rollouts, config, skills, and memories while isolating each account's credentials
  • stores only account/workspace metadata in account-sessions.json; tokens remain in the configured file, keyring, or secrets backend under a per-session namespace
  • rejects account mutations while a turn is active, reloads app-server auth after changes, and refreshes workspace-scoped tokens before switching
  • documents the lifecycle and updates both stable and experimental generated schemas

Motivation

Using separate Codex homes isolates credentials, but it also fragments local threads and memories. It can additionally make a shared rollout unusable when a forked conversation is validated against a different home. This proposal makes account identity switchable independently of the local session store: one shared home owns the local working context, while each saved account session owns only its credentials and selected workspace.

Relationship to existing work

This builds on the account-session protocol types merged upstream in openai#25469 and provides a current-main implementation of the lifecycle discussed in openai#25383. It also addresses the shared-session use case behind openai#4432 without requiring one CODEX_HOME per auth profile.

The main storage distinction from openai#25383 is that bearer and refresh tokens are never serialized into account-sessions.json. Existing auth backends remain the credential authority, namespaced by an opaque account-session ID.

Safety properties

  • token-free metadata index with atomic writes
  • UUID validation for credential namespace paths
  • serialized mutations and rejection during active turns
  • no Debug implementation on the backend token response
  • workspace token exchange completes before the active account header changes
  • logout removes both metadata and the corresponding credential namespace

Validation on 2026-09-14

Rebased onto upstream b9bfc0aff84de6af4c549f1ae544de569474f5f4 (59 commits beyond the previous base). Source changes merged cleanly; stable and experimental binary schema bundles were regenerated using the current generators. Git range-diff reports the original feature patch unchanged by the rebase.

The follow-up fix replaces exclusive turn admission with a reader/writer barrier and reloads persisted OAuth credentials after refresh before applying workspace-token replacements.

  • just test -p codex-app-server account_sessions: all six cases passed.
  • Negative controls on this upstream base reproduced both defects twice: exclusive turn admission rejected seven of eight starts, and omitting the post-refresh reload restored the old refresh token.
  • just test -p codex-app-server -p codex-app-server-protocol -p codex-backend-client --failure-output final --status-level fail: 1,890 passed, 9 failed, 12 skipped. Protocol: 304/304 passed; backend client: 32/32 passed. One existing login redirect test passed on retry.
  • All nine failures report the unavailable codex-code-mode-host executable. Building it was attempted, but the required rusty_v8 150.4.0 Windows sandbox archive returned HTTP 404. The separate test_stdio_server helper was built successfully. This is not a fully green broad-suite result.
  • Stable and experimental schema generation completed successfully.
  • just fmt completed; unrelated Bazel formatting churn was excluded.
  • Scoped just fix completed, and just clippy -p codex-app-server -p codex-app-server-protocol -p codex-backend-client -- -D warnings passed. Intentional async admission guards have narrowly scoped lint expectations following existing server conventions.

The public JSON-RPC tests cover credential isolation and token-free metadata, eight overlapping turns on independent threads, refresh-token preservation when omitted and replacement when supplied, rejecting add/switch/logout while a model response is gated, and allowing switching after completion. Another test keeps one conversation across two turns and verifies the second model request has the new bearer/account headers while retaining the earlier conversation input. HTTP/OAuth tests use synthetic credentials and local mock servers, not real accounts.

Follow-up scope

GitHub CI limitations observed after publication

The PR is mergeable, but CI is not green. Several SDK/Windows jobs fail before execution because the private fork does not have the required codex-runners runner group. The repo-checks job also reports a stale code-mode entry in MANIFEST_FEATURE_EXCEPTIONS; both that checker and codex-rs/code-mode/Cargo.toml are unchanged from upstream b9bfc0aff84d. These failures are recorded separately from the validated account-session changes; runner provisioning and upstream manifest-policy cleanup were not changed in this PR.

This is the server-side lifecycle and storage layer with one active account per app-server. Per-thread account routing and Desktop integration are separate follow-ups. A UI account picker and a dedicated accountSession/login/start UX can be layered on separately; clients can currently bootstrap the store with list, use the existing login flow, and then call add.

Upstream PR creation was attempted directly but the account was denied the CreatePullRequest permission. This fork PR is the reviewable proposal and branch of record.

Patrick Simpson added 2 commits September 14, 2026 13:53
What:
- implement accountSession add, list, switch, and logout routes in app-server
- isolate each saved login through the configured auth backend while keeping one shared CODEX_HOME for threads, rollouts, skills, and memories
- exchange workspace-scoped tokens, reload active auth, and block account mutations during active turns
- add generated protocol fixtures, app-server documentation, and an end-to-end two-account test

Why:
- users with multiple ChatGPT accounts currently need separate Codex homes, which fragments local sessions and memory and can break thread forking when rollout paths cross homes
- the protocol types already existed, but the server lifecycle and secure credential persistence were missing

Risks/Notes:
- workspace metadata refresh is best effort; callers should refresh before selecting a non-current workspace
- clients bootstrap the current login with accountSession/list, complete the existing login flow for another identity, then call accountSession/add
- this does not add UI account switching

Tests:
- cargo fmt --all -- --check
- cargo clippy --tests -p codex-app-server -p codex-backend-client -p codex-app-server-protocol
- cargo nextest run --no-fail-fast -p codex-app-server account_sessions_share_codex_home_and_isolate_credentials
- cargo nextest run --no-fail-fast -p codex-app-server-protocol -p codex-backend-client
- stable and experimental app-server schema generation
What:
- Use a shared read lock for independent turn admissions and an exclusive
  write lock for account mutations, retaining the active-turn rejection.
- Reload saved OAuth credentials after auth refresh before applying a
  workspace-token response, preserving rotated refresh tokens when omitted.
- Add public JSON-RPC regressions for eight overlapping thread turns,
  workspace refresh-token preservation and replacement, active-turn mutation
  guards, and switching model-request credentials within one conversation.

Why:
- Exclusive admission incorrectly treated another thread's turn start as an
  account change. A pre-refresh auth snapshot could overwrite rotated tokens.
- Validate the shared-home feature against upstream b9bfc0a before
  publishing the rebased branch, rather than relying on a clean source merge.

Risks/Notes:
- This remains one active account per app-server; per-thread account routing
  and Desktop integration are separate work.
- HTTP/OAuth integration uses synthetic credentials and local mock servers,
  not live account switching.
- The broad suite is not fully green: nine code-mode tests lack the Windows
  codex-code-mode-host binary. Its required rusty_v8 150.4.0 Windows sandbox
  archive returns HTTP 404, preventing the helper build.

Tests:
- Six account-session cases passed; restoring exclusive admission and stale
  auth behavior made the two targeted regressions fail on both attempts.
- just test -p codex-app-server -p codex-app-server-protocol
  -p codex-backend-client: 1890 passed, 9 failed, 12 skipped. All failures
  report the missing code-mode helper; one login test passed on retry.
- Stable and experimental app-server schemas regenerated successfully.
- just fix -p codex-app-server -p codex-app-server-protocol
  -p codex-backend-client completed; deliberate async admission guards have
  narrowly scoped lint expectations consistent with existing server code.
- just clippy -p codex-app-server -p codex-app-server-protocol
  -p codex-backend-client -- -D warnings passed.
- just fmt completed; unrelated Bazel formatter churn was excluded.
@patrickallensimpson
patrickallensimpson force-pushed the feature/shared-home-account-sessions branch from 81818e3 to 4876ea4 Compare September 14, 2026 20:17
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