Skip to content

fix(codex): persist account removal before deleting credentials - #25308

Open
nwparker wants to merge 1 commit into
mainfrom
fix/codex-account-removal-durable
Open

nwparker wants to merge 1 commit into
mainfrom
fix/codex-account-removal-durable

Conversation

@nwparker

@nwparker nwparker commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​775 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​756
Prod 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​353 $\color{#cf222e}{\Huge{\mathbf{−}}}$​100 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​253

ELI5

Removing a Codex account can hide its row even though its login files remain. Save the removal before deleting files, and keep failed cleanup visible for retry.

What Changed

  • Commit the account removal, runtime selection, reset-credit records and cleanup target together through the existing durable writer. A failed commit preserves credentials; an unknown commit outcome leaves deletion for recovery.
  • After acknowledgement, synchronize the runtime and delete the owned account home. Failed cleanup remains pending, retries on startup through the existing account queue, and can be retried with Remove.
  • Keep the ownership marker until credential files are gone. A retry can finish a validated empty home or confirm absence; an unavailable WSL share stays pending.
  • Show pending cleanup separately from selectable accounts, with selection and re-authentication disabled. Older remote clients still receive the usual selectable roster.

Why

This is a reproduced failure case, without a confirmed customer incident or frequency estimate. The account queue and durable writer already provide serialization, acknowledgement and known-failure rollback. Reusing them keeps runtime synchronization after the commit and makes cleanup failure an explicit pending state.

Replacement for #11655. Production code is +330/-98, net 232 lines, versus net 461 there. The entire PR is 28 files, +1128/-119; tests account for +785/-20 and translations for +13/-1. It uses one removal commit and one cleanup completion commit, without adding Store preview mode or a runtime repair loop.

Linked Issue

Fixes #11653

Visual Proof

Same refused ownership check, using isolated profiles and hidden Electron renderers on macOS.

Before on main: the account row disappears, but its credential file remains.

Before: failed cleanup loses its account row

After: the pending row keeps Remove available and disables selection and re-authentication. Verified that it survives app restart.

After: failed cleanup stays visible for retry

After repairing the test fixture's ownership marker and choosing Remove again, both the managed home and pending row disappear.

Successful retry removes the pending row

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

785 tests across 105 suites passed: account service, runtime routing, the persistence writer and Accounts UI. Coverage includes delayed acknowledgement, failed commit, committed write with lost acknowledgement, restart retry, failed completion write, partial deletion, refused ownership, WSL absence/unavailability and disabled pending actions.

pnpm tc, pnpm run check:code-quality:changed origin/main, formatting and git diff --check passed. The Electron dev build and actual UI removal/restart/retry flow passed.

Executed locally on macOS, including the generated WSL ownership script against Bash. Native Windows/WSL, Linux and remote-host integration depend on CI; no real account credentials were used.

Review

Self-reviewed the commit/deletion ordering, failure outcomes, host lifecycle, cross-version account roster and deletion boundaries. Retains ownership recovery work from #11655, with contributor attribution in the commit.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Cleanup executes on the account's owning runtime. Optional reply fields preserve mixed-version compatibility. Existing filesystem retries stay bounded; startup uses the existing queue without recurring polling. Ownership failures remain visible and require the underlying problem to be resolved before retry can succeed.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Changed-file quality and focused tests passed locally; CI covers full lint/test and packaged builds.

Commit account selection, credit guards and cleanup metadata through the
existing durable writer. Delete only after acknowledgement, retain failed
cleanup for startup/manual retry, and keep ownership proof through partial
deletion.

Co-authored-by: kazu-42 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1a350a69-18eb-4009-9353-82e4492e8f8a
📥 Commits

Reviewing files that changed from the base of the PR and between 97fa6ae and 5b72234.

📒 Files selected for processing (28)
  • src/main/codex-accounts/codex-account-selection.ts
  • src/main/codex-accounts/codex-managed-home-cleanup-recovery.test.ts
  • src/main/codex-accounts/codex-managed-home-lifecycle.ts
  • src/main/codex-accounts/codex-managed-home-path.ts
  • src/main/codex-accounts/codex-managed-home-removal-wsl-script.test.ts
  • src/main/codex-accounts/codex-reset-credit-coordinator.ts
  • src/main/codex-accounts/codex-reset-credit-ledger.test.ts
  • src/main/codex-accounts/codex-reset-credit-ledger.ts
  • src/main/codex-accounts/host-codex-managed-home-ownership.ts
  • src/main/codex-accounts/service-account-removal-durability.test.ts
  • src/main/codex-accounts/service-account-selection-and-removal.test.ts
  • src/main/codex-accounts/service-reset-credit-target-routing.test.ts
  • src/main/codex-accounts/service-test-harness.ts
  • src/main/codex-accounts/service.ts
  • src/main/persistence/loading-store/codex-account-removal-async-durability.test.ts
  • src/main/persistence/loading-store/primary-state-write-runtime.ts
  • src/main/persistence/loading-store/primary-state-writes.ts
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/settings/accounts-pane-codex-account-row.test.tsx
  • src/renderer/src/components/settings/accounts-pane-codex-account-row.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/global-settings-types.ts
  • src/shared/managed-account-types.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Account removal now persists removal-recovery metadata with account and reset-credit ledger updates before attempting managed-home cleanup. Failed cleanup leaves a pending record that startup or a later removal attempt can retry. Managed-home validation and removal now report cleanup results and handle verified missing homes. The account settings pane displays pending removals and disables selection and reauthentication for those accounts.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 5b722

Codex account removal can retain and retry failed cleanup, and pending accounts remain accessible for retry. No identified issue currently prevents merging after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 5b722

The change improves removal safety by saving recovery information before deleting credentials and keeping failed cleanup retryable. Pending accounts are blocked from selection and reauthentication. Remaining uncertainty concerns behavior on unavailable WSL shares and compatibility with older remote clients, rather than a demonstrated expansion of deletion privileges.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected destructive flow operates with the desktop process's filesystem privileges on resolved account homes and their account directories. Repeated calls or startup recovery can process multiple stored accounts, while account selection and reset-credit changes share profile persistence. This is local credential-cleanup authority, not evidence of provider-side token revocation or wider service authority.

Trust Boundaries and Controls

  • observed — Pending cleanup is not merely a disabled UI state. Account selection requires membership in codexManagedAccounts, and reauthentication uses the same requireAccount guard before accessing the home. Recovery-only accounts therefore cannot be reauthenticated through the inspected main-process flow.

Resilience and Maintainability Implications

  • observed — WSL absence confirmation requires an absolute path and a readable ancestor whose listing lacks the child; only ENOENT or ENOTDIR permits walking upward, and other errors or reaching the root without confirmation return false. Tests cover a readable missing home and an unavailable parent reported as EIO. They do not establish every live Windows WSL share failure mode, so that platform-specific completion guarantee remains partially evidenced.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 22 files. (6 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: persist Codex account removal before deleting credentials.
Description check ✅ Passed The description is mostly complete. It covers the user-facing change, implementation, rationale, linked issue, visual proof, testing, review notes, platform considerations, and checklist.
Linked Issues check ✅ Passed #11653 requires a durable cleanup retry path after account removal. CodexAccountSelection.remove commits the account removal and recovery record before cleanup, then clears the record only after cle…
Out of Scope Changes check ✅ Passed The persistence-writer and reset-credit changes support committing account settings, recovery state, and reset-credit records together. The lifecycle, runtime synchronization, pending-account UI, tran…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 22 files. (6 skipped: 6 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

This replaces #11655 and fixes the reported case where a managed Codex account disappeared from the roster while its credential files stayed on disk with no way to retry cleanup. The whole branch (1 commit, 28 files) was reviewed.

  • Removal is now committed before deletion — CodexAccountSelection.remove commits the roster/selection change plus codexAccountRemovalRecovery and the pruned reset-credit ledger through the new PrimaryStateWriteOperations.updateCodexAccountStateAndFlush, so a failed commit preserves the account and a lost acknowledgement leaves a recovery record for restart.
  • Cleanup failure is a first-class pending state — safeRemove returns boolean; on success a second commit clears the recovery record, on failure the record survives and is retried by the constructor's startup loop and by Remove.
  • Ownership-safe emptying — assert/ownership gain an allowEmptyHome option (host, mounted WSL, and the generated WSL shell check) so an interrupted cleanup that left an empty, marker-less home can finish, while the marker is retained until credential-bearing entries are gone; WSL absence is confirmed through a readable ancestor.
  • Renderer — AccountsPane surfaces pending removals in the roster; the row disables selection and re-auth while keeping Remove enabled to retry.
  • Tests/translations — new durability, cleanup-recovery, WSL-script, and row tests; new codexRemovalPending/codexRemovalRetry strings in all seven locales.

Verification I ran: the 26 new/updated tests and 27 modified codex suites pass; pnpm tc:node, pnpm tc:web, and pnpm run check:code-quality:changed origin/main all pass. I traced the durability rollback/listener ordering against the existing updateSettings/async-writer contract and the deletion/ownership paths (including partial deletion, marker-gone-but-credentials-remain, empty-home recovery, WSL absent vs. unreadable, and find failure under set -euo pipefail) and found no path that deletes a non-owned home, reports a credential-bearing home as removed, or wedges an empty home.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@kazu-42 kazu-42 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.

Reviewed 5b722344671659d26148024395284e4b0f100eba independently against the changes requested on #11655. I agree with using this as the replacement.

The smaller flow preserves the relevant safety boundaries: account removal, selection and reset-credit cleanup commit together before credential deletion; a known commit failure rolls back the account fields while preserving unrelated later preferences; an unknown outcome leaves credentials for recovery; post-commit cleanup failures keep a separate pending record. Pending records stay outside the selectable roster, and ownership evidence survives partial deletion. The host/default lifecycle and WSL paths retain their existing behavior.

Local verification on this exact head, with disposable fixture homes and ORCA_BACKGROUND_LAUNCH=1:

  • Account/runtime/Settings-row tests: 58 files, 428 passed.
  • Persistence tests: 103 files, 1,022 passed, 4 skipped. Removing the one overlapping file gives 160 files and 1,445 passed tests overall.
  • Node, Web and CLI typechecks passed.
  • Changed-code quality: zero new findings across 22 code files; whitespace check passed.
  • Current-head hosted checks read back as 27 success and 13 skipped, with no unresolved review threads.

The local skips are native Windows process identity, Linux PID namespace, and two opt-in Bun/Node cross-runtime scenarios. I did not repeat the rendered Electron check or perform a live Windows/WSL/paired-SSH mutation. The two stream dependencies missing from the older local dependency tree were installed at the branch's exact versions in an isolated test overlay; shared dependencies and source files were not changed.

No remaining blocking findings in this review. I will close #11655 as superseded and keep #24944 as a separate Draft dependent on this durability change; its old Store-preview integration must not be applied to this implementation.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex account removal can leave managed credentials after cleanup failure

2 participants