Skip to content

feat(codex-accounts): import existing CODEX_HOME without re-login - #10394

Open
innocarpe wants to merge 3 commits into
stablyai:mainfrom
innocarpe:feat/import-existing-codex-home
Open

innocarpe wants to merge 3 commits into
stablyai:mainfrom
innocarpe:feat/import-existing-codex-home

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds Import CODEX_HOME next to Add Account in Settings → Codex Accounts
  • Copies an already-authenticated external CODEX_HOME into Orca managed storage and registers it as a normal managed account without running codex login again (issue Option B)
  • Validates auth.json, resolves OAuth identity (email required), refuses import from Orca managed storage or WSL slots (host only for now)

Closes #10366

Motivation

Power users keep isolated homes (~/.codex-work, device-auth flows, enterprise login). Today every extra account must go through Orca's browser login, so those homes cannot be reused.

Implementation

  • CodexAccountService.importAccountFromExistingHome(sourceHomePath, target?)
  • Shared helpers in import-existing-codex-home.ts (validate, copy, ownership marker)
  • IPC codexAccounts:importExistingHome + preload API
  • UI: folder picker → import; disabled for remote / WSL scope
  • Applies the OAuth provider policy to the imported config when no canonical config exists

Test plan

  • Unit: import helpers (auth.json required, reject managed storage, copy + marker)
  • Unit: service imports without spawn/codex login, rejects API-key-only and WSL target
  • Full service.test.ts + helper tests (72 pass, including custom-provider import rejection)
  • Manual: Settings → Codex Accounts → Import CODEX_HOME → pick ~/.codex-* with prior codex login → account appears and becomes active without browser login

Notes

  • Host runtime only; WSL import can follow if needed
  • Source directory is left intact (copy, not move)

ELI5

You can import an already-logged-in CODEX_HOME into Orca managed accounts without running codex login again. Handy if you keep separate Codex homes for different workflows.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Walkthrough

Adds support for importing an authenticated external CODEX_HOME into Orca-managed storage. The change validates source directories, rejects managed-storage paths, copies files while rewriting ownership metadata, and registers the imported account without running Codex login. It exposes the operation through IPC and preload APIs, adds a web fallback, and provides a settings UI action with directory selection, runtime restrictions, loading state, and restart handling. Tests cover helper behavior, service integration, invalid credentials, and WSL rejection.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the change and testing, but it omits the required Screenshots, AI Review Report, and Security Audit sections. Add the missing template sections, state “No visual change” or provide screenshots, and document AI review, cross-platform checks, and security audit findings.
✅ Passed checks (3 passed)

Check name Status Explanation
Linked Issues check ✅ Passed The changes implement importing an authenticated CODEX_HOME, validating identity, copying it into managed storage, and registering it without reauthentication [#10366].
Out of Scope Changes check ✅ Passed The service, helper, IPC, preload, tests, and settings UI changes directly support the linked issue and contain no unrelated code changes.
Title check ✅ Passed The title clearly and concisely describes importing an existing CODEX_HOME without requiring another login.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/renderer/src/components/settings/AccountsPane.tsx (1)

1191-1194: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remember to sync the locale catalog for the new key.

importCodexHome is a new translate key with only an English fallback baked into the code. Based on learnings, when adding a localization key you should validate/update the catalogs with pnpm sync:localization-catalog, pnpm verify:localization-catalog, and pnpm verify:localization-coverage so es/ja/ko/zh stay in sync.

Based on learnings: "When making any localization change, validate/update the catalogs using pnpm sync:localization-catalog, pnpm verify:localization-catalog, and pnpm verify:localization-coverage."

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 404590c1-1603-485e-b051-38478c205b6e

📥 Commits

Reviewing files that changed from the base of the PR and between 17959a2 and 5891d00.

📒 Files selected for processing (9)
  • src/main/codex-accounts/import-existing-codex-home.test.ts
  • src/main/codex-accounts/import-existing-codex-home.ts
  • src/main/codex-accounts/service.test.ts
  • src/main/codex-accounts/service.ts
  • src/main/ipc/codex-accounts.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/web/web-preload-api.ts

@nwparker nwparker added the enhancement New feature or request label Jul 27, 2026
@innocarpe
innocarpe force-pushed the feat/import-existing-codex-home branch from 8c7f046 to 234a00c Compare August 6, 2026 03:56
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (234a00cb86)

Rebase onto latest upstream/main: import existing CODEX_HOME alongside addAccountFromHome CLI path.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d780d1c-02d1-4c6e-840c-d4421fb55e77

📥 Commits

Reviewing files that changed from the base of the PR and between 81e7a2d and 234a00cb86e33952940318634543e02eb55410bd.

📒 Files selected for processing (9)
  • src/main/codex-accounts/import-existing-codex-home.test.ts
  • src/main/codex-accounts/import-existing-codex-home.ts
  • src/main/codex-accounts/service.test.ts
  • src/main/codex-accounts/service.ts
  • src/main/ipc/codex-accounts.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/web/web-preload-api.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/preload/api-types.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/main/codex-accounts/import-existing-codex-home.test.ts
  • src/main/codex-accounts/service.test.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/AccountsPane.tsx

Comment thread src/main/codex-accounts/service.ts Resolved
@innocarpe
innocarpe force-pushed the feat/import-existing-codex-home branch from 234a00c to 5efcc8e Compare August 6, 2026 04:21
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (5efcc8e251)

Addressed CodeRabbit review: enforce the OAuth provider policy against an imported CODEX_HOME config when no canonical config exists, and add regression coverage for a custom model_provider. Validation: 72 Codex account service tests, typecheck, native/type-aware Oxlint, and Oxfmt pass.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] Adds account import flow for existing CODEX_HOME directories.

The recursive import must be contained before merging because a selectable source layout can make it copy managed credentials or recurse into its own destination.

Findings

  1. P1 Recursive copy escapes containment ▶

Summary

The PR adds a desktop flow for importing an authenticated external CODEX_HOME into managed account storage without another login.

  • Adds source validation, OAuth identity resolution, managed-home copying, and account registration.
  • Exposes the operation through IPC/preload APIs and adds a host-only settings action.
  • Adds unit and service coverage for successful imports, invalid authentication, custom-provider policy, and WSL rejection.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  UI[Settings: Import CODEX_HOME] --> Picker[Choose directory]
  Picker --> IPC[Desktop IPC]
  IPC --> Validate[Validate auth and OAuth identity]
  Validate --> Allocate[Create managed home]
  Allocate --> Copy[Copy external home]
  Copy --> Mirror[Apply canonical config and Orca hooks]
  Mirror --> Persist[Register and activate account]
Loading

Reviews (1) · Last reviewed commit: "fix(codex-accounts): enforce provider po..." · Reviewed by Greptile

Comment on lines +86 to +92
await cp(from, to, {
recursive: true,
force: true,
// Why: CODEX_HOME often holds symlinks (skills, config overlays); copy
// contents so the managed home stays self-contained on every host.
dereference: true
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Recursive copy escapes containment

When the selected CODEX_HOME contains a directory symlink targeting Orca managed storage, or contains Orca’s user-data directory as a descendant, this recursive copy dereferences that path and enters the managed account tree or its own destination, causing credential duplication, runaway disk usage, or a failed partial import. Validate both containment directions and nested symlink targets before copying.

Allow Settings → Codex Accounts → Import CODEX_HOME to copy an already
authenticated external home into Orca managed storage and register it as
a normal managed account (issue stablyai#10366 Option B).
CodeRabbit: use statSync for type checks; async cp so large homes do not
block the Electron main process.
@innocarpe
innocarpe force-pushed the feat/import-existing-codex-home branch from ca54ef3 to 9a3d509 Compare November 10, 2026 05:14
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (9a3d509ad4)

Rebased onto current main. Import CODEX_HOME now sits on the accounts codex section, and provider policy still applies to imported homes.

This branch has not been deployed

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support importing an existing CODEX_HOME

3 participants