Skip to content

fix(serve): save Codex auth before a headless serve update restart - #28001

Merged
OrcaWin merged 2 commits into
mainfrom
np/d1e-serve-codex-auth
Oct 12, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
np/d1e-serve-codex-auth

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​23 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17

ELI5

Before the desktop app restarts to install an update, it saves the signed-in Codex account's login files so the restart doesn't lose them. A headless orca serve that installs an update skipped that step and only saved Orca's own state. Now both run the same steps, in the same order.

What Changed

  • Before:
    • The desktop's update restart ran preserveAgentAuthBeforeRestart (sync the selected Codex account's auth.json, including WSL homes) and then a full store checkpoint.
    • Headless Electron serve (fix(serve): initialize the updater in headless Electron serve #27771 started its updater) ran only the store checkpoint. A Codex token refreshed by an agent on that server could stay in the managed runtime home and never be copied back to the account, so after the update the account could hold a stale, already-rotated refresh token.
  • After:
    • One function, preserveStateBeforeUpdateRestart (new update-restart-preservation.ts), runs the auth save and then the full checkpoint.
    • The desktop window path and the headless serve path both call it. A failed checkpoint still aborts the install, as before. The auth step keeps its existing bounded, log-and-continue behavior.
  • orcad serve has no app updater and is unchanged.

Why

The two paths had drifted: the desktop added the auth step, and serve's hook was written separately. One shared function, called from both places, keeps them from drifting again. I considered moving the auth save into the updater itself, but the updater doesn't own Codex state, and the hook is the existing seam for "work before an update quit".

Linked Issue

Part of the headless-serve robustness work (D1, B1 follow-up). No separate issue.

Visual Proof

N/A. This changes background behavior before an update restart, with no UI.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • main-process-runtime-launch-activation.test.ts: a new case starts a windowless serve, takes the hooks it passes to the headless updater, and runs the pre-install hook. It asserts that the Codex sync (host and WSL) runs first, the full checkpoint runs last, and the hook keeps its abort-on-failure mode. It failed before the change: the Codex sync was never called.

  • The existing auth-preservation, window updater and startup suites still pass.

  • pnpm tc, oxlint, pnpm run check:code-quality:changed and pnpm lint pass locally. No real update was installed.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Compatibility: no wire or file-format change.
  • SSH / WSL: the WSL Codex sync is the same one the desktop runs. Nothing is routed to SSH hosts.
  • Cross-platform: the hook runs on every platform where headless Electron serve installs updates.

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)

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough
📝 Walkthrough

Walkthrough

Windowed and headless startup update quit callbacks now use a shared function to preserve agent authentication before a full store checkpoint. The headless-serve test checks updater configuration, preservation ordering, and that startup does not open a window.


Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 7c256

Headless updates currently wait for WSL auth preservation before checkpointing. The test does not protect that ordering, so a future regression could leave auth state unsaved during an update restart; the change is mergeable with a small test follow-up.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the main change: preserving Codex authentication before a headless serve update restart.
Description check Passed The description is complete and directly addresses the required sections. It explains the user impact, implementation, rationale, testing, compatibility considerations, and the absence of UI changes. …

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · 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.

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

🧹 Nitpick comments (1)
src/main/startup/main-process-runtime-launch-activation.test.ts (1)

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

Defer WSL sync and assert before starting the full checkpoint.

The WSL mock resolves immediately and is not recorded in order. The current assertions run only after the hook completes, so they would pass if the full checkpoint started before WSL synchronization finished.

Suggested test change
     const order: string[] = []
+    let resolveWslSync!: () => void
+    const wslSync = new Promise<void>((resolve) => {
+      resolveWslSync = resolve
+    })
     const store = {
...
-      syncActiveWslSelectionsBeforeRestart: vi.fn(async () => {})
+      syncActiveWslSelectionsBeforeRestart: vi.fn(() => wslSync)
...
-      await hooks.onBeforeUpdateQuit()
+      const updateQuit = hooks.onBeforeUpdateQuit()
+      await vi.waitFor(() => {
+        expect(order).toContain('store-flush')
+      })
+      expect(store.flushPendingOrThrowAsync).not.toHaveBeenCalledWith({
+        fullCheckpoint: true
+      })
+      resolveWslSync()
+      await updateQuit
+      expect(store.flushPendingOrThrowAsync).toHaveBeenCalledWith({
+        fullCheckpoint: true
+      })

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0c2bc3f5-ebfc-47bc-a7ac-a40e4889eaa8
📥 Commits

Reviewing files that changed from the base of the PR and between cef4d29 and f9a158e.

📒 Files selected for processing (4)
  • src/main/agent-auth-restart-preservation.ts
  • src/main/startup/main-process-runtime-launch-activation.test.ts
  • src/main/startup/main-process-runtime-launch.ts
  • src/main/startup/main-window-core-services.ts

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

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

🧹 Nitpick comments (1)
src/main/startup/main-process-runtime-launch-activation.test.ts (1)

349-352: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Assert WSL completion before the full checkpoint.

The WSL mock resolves immediately and records no completion. The test can pass if the full checkpoint starts before WSL synchronization completes. Defer WSL completion, allow the helper’s preliminary non-full flush, and distinguish it from the { fullCheckpoint: true } call.

Suggested fix
     const order: string[] = []
+    let resolveWsl!: () => void
+    const wslCompletion = new Promise<void>((resolve) => {
+      resolveWsl = resolve
+    })
     const store = {
-      flushPendingOrThrowAsync: vi.fn(async (options?: { fullCheckpoint?: boolean }) => {
-        order.push(options?.fullCheckpoint ? 'store-checkpoint' : 'store-flush')
-      })
+      flushPendingOrThrowAsync: vi.fn(
+        async (options?: {
+          drainToStableGeneration?: boolean
+          fullCheckpoint?: boolean
+        }) => {
+          order.push(options?.fullCheckpoint ? 'store-checkpoint' : 'store-flush')
+        }
+      )
     }
@@
-      syncActiveWslSelectionsBeforeRestart: vi.fn(async () => {})
+      syncActiveWslSelectionsBeforeRestart: vi.fn(async () => {
+        await wslCompletion
+        order.push('codex-auth-wsl-complete')
+      })
@@
-      await hooks.onBeforeUpdateQuit()
+      const updateQuit = hooks.onBeforeUpdateQuit()
+      await Promise.resolve()
+      expect(store.flushPendingOrThrowAsync).toHaveBeenNthCalledWith(1, {
+        drainToStableGeneration: false
+      })
+      expect(store.flushPendingOrThrowAsync).not.toHaveBeenCalledWith({
+        fullCheckpoint: true
+      })
+      resolveWsl()
+      await updateQuit
       expect(codexRuntimeHome.syncForCurrentSelection).toHaveBeenCalledTimes(1)
       expect(codexRuntimeHome.syncActiveWslSelectionsBeforeRestart).toHaveBeenCalledTimes(1)
-      expect(order.at(0)).toBe('codex-auth')
-      expect(order.at(-1)).toBe('store-checkpoint')
+      expect(store.flushPendingOrThrowAsync).toHaveBeenNthCalledWith(2, {
+        fullCheckpoint: true
+      })
+      expect(order.indexOf('codex-auth-wsl-complete')).toBeLessThan(
+        order.indexOf('store-checkpoint')
+      )

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 54462d28-38cf-4884-ac39-9e8d4fba014a
📥 Commits

Reviewing files that changed from the base of the PR and between f9a158e and 7c2562f.

📒 Files selected for processing (4)
  • src/main/agent-auth-restart-preservation.ts
  • src/main/startup/main-process-runtime-launch.ts
  • src/main/startup/main-window-core-services.ts
  • src/main/update-restart-preservation.ts

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

@OrcaWin
OrcaWin merged commit baaef1b into main Oct 12, 2026
30 checks passed
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