Repository navigation
fix(serve): save Codex auth before a headless serve update restart - #28001
Conversation
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to 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 |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/startup/main-process-runtime-launch-activation.test.ts (1)
340-340: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDefer 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
📒 Files selected for processing (4)
src/main/agent-auth-restart-preservation.tssrc/main/startup/main-process-runtime-launch-activation.test.tssrc/main/startup/main-process-runtime-launch.tssrc/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.
…auth mocks still apply
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/startup/main-process-runtime-launch-activation.test.ts (1)
349-352: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAssert 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
📒 Files selected for processing (4)
src/main/agent-auth-restart-preservation.tssrc/main/startup/main-process-runtime-launch.tssrc/main/startup/main-window-core-services.tssrc/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.
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 servethat 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
preserveAgentAuthBeforeRestart(sync the selected Codex account'sauth.json, including WSL homes) and then a full store checkpoint.preserveStateBeforeUpdateRestart(newupdate-restart-preservation.ts), runs the auth save and then the full checkpoint.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:changedandpnpm lintpass locally. No real update was installed.Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)