Skip to content

fix(codex): re-land WSL direct-home cutover with counsel findings fixed - #16854

Merged
brennanb2025 merged 17 commits into
mainfrom
brennanb2025/sta-5670-wsl-cutover-reland
Aug 31, 2026
Merged

brennanb2025 merged 17 commits into
mainfrom
brennanb2025/sta-5670-wsl-cutover-reland

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2024 $\color{#cf222e}{\Huge{\mathbf{−}}}$​469 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1555
Prod 22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1882 $\color{#cf222e}{\Huge{\mathbf{−}}}$​477 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1405

ELI5

If you run Codex inside WSL, Orca used to keep your Codex sign-in in a shared spot outside the Linux
distro and copy it in and out on every launch. This change lets Codex use its own home directory
inside the distro directly, and retires the copying. On your first launch after upgrading, Orca moves
your existing credentials across once.

An earlier attempt at this was pulled back because that one-time move could, in the wrong
circumstances, delete your only good copy of the credentials. This version verifies the
destination before retiring anything, and puts the original aside rather than deleting it, restoring
it if anything goes wrong.

User-facing before / after

Before After
Running Codex under WSL Your sign-in lived in a shared mirror and was copied in and out at every launch Codex runs against its own in-distro home; the mirror is gone
Your first launch after upgrading — A one-time move brings your credentials over. If it is interrupted, the original is restored, not deleted — the earlier, reverted version could leave you with neither copy intact
Running /resume on a Codex session you started before the upgrade Those older conversations disappeared from the list Pre-upgrade history is bridged in, and only for the account it actually belongs to
Your WSL home sits on a mounted drive (/mnt/c/...) The move silently skipped those homes, so credentials never came across Matched by distro and Linux home path, so mounted-drive homes are included
macOS, Linux, SSH, folder workspaces — Unaffected

When it bites

Codex users on WSL, at the first launch after upgrading. Note the honest limit below: live WSL
validation has not been run yet, so the migration is proven by tests and real shell scripts rather
than on a physical WSL host.

Re-lands the WSL direct-home cutover reverted in #16722, with all three findings from the readiness counsel fixed.

Codex on WSL now launches against each account's own in-distro home as its live CODEX_HOME. The shared runtime mirror and its copy/read-back machinery are retired, and a one-time drain migrates credentials for anyone upgrading with a pane still routed at the old home.

What the revert was for, and what changed

P0 — the drain could destroy credentials. The delete-source path validated the source and never re-checked the destination, so with promoteAuth=0 a destination rewritten in place could be left corrupt while the only intact copy was deleted. Now the destination is pinned by inode, verified by hash and -ef, and an independent verified snapshot is swapped in atomically before the source is retired. The source is quarantined by mv rather than rm, and a trap restores it on any failure — it is removed only after the destination is re-verified.

P1 — pre-upgrade sessions vanished from /resume. The launch bridge sourced history only from the distro's ~/.codex, never the retired runtime home. It now bridges the retired home as well, guest-side, gated by a per-distro authorization so history is never linked into an account it does not belong to.

P2 (STA-5671) — mounted-drive homes were skipped. Drain matching gated on a UNC parse, so a home under /mnt/<drive> was silently excluded and never drained. Matching is now keyed on the persisted distro and Linux home path, with the UNC parse kept only as a fallback for accounts predating those fields.

Shape

One commit series, no stack. The P0 existed because a guard landed on a different PR than the code it guarded, leaving a window where main held the rescue code unprotected. Landing atomically removes that window. The prerequisite work (#16496, #16499) is already in main and was not reverted.

Verification

  • pnpm typecheck clean
  • 2123 passed across codex-accounts, codex, wsl, agent-hooks, restart preservation
  • Guest shell guards are exercised by executing the real scripts under bash, skipped on win32 — the P0 originally survived review because those guards were only ever reachable through a mocked runner
  • Rebased onto 3558cf943f; verified by name that fix(codex): heal WSL hooks before typed launches #16535's hook convergence and serialization survive, and that the mirror removal still holds

Not yet done

Live WSL validation. Every prior attempt on this feature was blocked on hardware; a working Windows host is now available and validation runs next: managed direct-home launch, one-time drain with credentials intact, pre-upgrade /resume, and a shell-typed codex picking up the right CODEX_HOME without the agent launcher.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change replaces shared WSL runtime-home synchronization with direct managed and system WSL homes. It adds asynchronous legacy authentication draining, batch authentication reads, crash recovery, session bridging, and completion markers. WSL pane ownership now supports distro and Linux home matching. Restart preservation awaits WSL drains and applies lifecycle timeouts. Codex launch preparation and hook setup now use asynchronous entry points. WSL path conversion, registry validation, and stale-pane detection are updated.

Merge Risk: 🟠 High · up to a561c

The WSL direct-home migration still has unresolved paths that can lose refreshed credentials, leave authentication unusable after rollback, reuse removed installs, or erase account attribution; a watermark edge case can also misroute later session drains. These issues can affect login, restart preservation, and account/session routing, so the PR is not ready to merge until the correctness risks are fixed or explicitly accepted.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 53 functions across 30 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description gives a detailed ELI5 explanation, change summary, rationale, before/after behavior, testing results, and known limitation. However, it does not include the required Linked Issue secti… Add the required template sections. Include a linked issue using Fixes #...; provide before/after visual attachments or write N/A with a reason; complete the Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Chec…
✅ Passed checks (3 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 identifies the main change: re-landing the WSL direct-home cutover and addressing prior findings.
Full details: Description check

Explanation

The description gives a detailed ELI5 explanation, change summary, rationale, before/after behavior, testing results, and known limitation. However, it does not include the required Linked Issue section with a Fixes #... entry, the required visual proof or explicit N/A statement, or the template checklist and review sections.

Resolution

Add the required template sections. Include a linked issue using Fixes #...; provide before/after visual attachments or write N/A with a reason; complete the Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections, including the current live WSL validation status and platform coverage.

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f6bc4786-28ad-4001-ab0e-7d7bfee85ec9

📥 Commits

Reviewing files that changed from the base of the PR and between 3558cf9 and 389d5dd.

📒 Files selected for processing (28)
  • src/main/agent-auth-restart-preservation.test.ts
  • src/main/agent-auth-restart-preservation.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-apply-script.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-exit-codes.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-shell-commands.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-finalize-script.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/codex-accounts/runtime-home-wsl-managed-accounts.test.ts
  • src/main/codex-accounts/runtime-home-wsl-retired-session-launch.test.ts
  • src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts
  • src/main/codex-accounts/runtime-home-wsl-system-default.test.ts
  • src/main/codex-accounts/wsl-codex-auth-batch-reader.ts
  • src/main/codex/codex-pane-account-registry.ts
  • src/main/codex/codex-pane-launch-account.test.ts
  • src/main/codex/codex-pane-launch-account.ts
  • src/main/codex/codex-stale-pane-accounts.test.ts
  • src/main/codex/wsl-codex-session-bridge-script.ts
  • src/main/codex/wsl-codex-session-bridge.test.ts
  • src/main/codex/wsl-codex-session-bridge.ts
  • src/main/index.ts
  • src/main/pty/codex-home-wsl-env.ts
  • src/main/wsl/__fixtures__/wsl-invocation-allowlist.txt
  • src/shared/child-process/__fixtures__/child-process-import-allowlist.txt
  • src/shared/wsl-paths.test.ts
  • src/shared/wsl-paths.ts
💤 Files with no reviewable changes (2)
  • src/shared/child-process/fixtures/child-process-import-allowlist.txt
  • src/main/wsl/fixtures/wsl-invocation-allowlist.txt

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +129 to +165
cleanup() {
if [ ! -f "$drain_marker" ]; then
rollback_session_links
else
commit_session_links || :
fi
if [ ! -f "$drain_marker" ] && [ ! -e "$source_auth" ] && [ ! -L "$source_auth" ]; then
if [ -f "$source_recovery_auth" ] && [ ! -L "$source_recovery_auth" ] && [ "$(hash_file "$source_recovery_auth")" = "$expected_source_hash" ]; then
mv -- "$source_recovery_auth" "$source_auth" || :
chmod 600 "$source_auth" || :
elif [ -f "$source_quarantine_auth" ] && [ ! -L "$source_quarantine_auth" ] && [ "$(hash_file "$source_quarantine_auth")" = "$expected_source_hash" ]; then
mv -- "$source_quarantine_auth" "$source_auth" || :
chmod 600 "$source_auth" || :
fi
elif [ ! -f "$drain_marker" ]; then
# A late writer owns the recreated path; retain verified recovery artifacts for retry.
:
elif [ -f "$drain_marker" ]; then
rm -f -- "$source_recovery_auth" "$source_quarantine_auth" "$destination_recovery_path"
fi
if [ -f "$drain_marker" ]; then
if [ -f "$destination_recovery_auth" ] && [ ! -L "$destination_recovery_auth" ]; then
chmod 600 "$destination_recovery_auth" || :
fi
rm -f -- "$destination_recovery_auth" "$destination_recovery_path"
elif [ -e "$destination_recovery_auth" ] || [ -L "$destination_recovery_auth" ]; then
if [ -f "$destination_recovery_auth" ] && [ ! -L "$destination_recovery_auth" ] && [ -f "$destination_recovery_path" ] && [ ! -L "$destination_recovery_path" ]; then
${RECOVER_DESTINATION_AUTH_COMMAND} || :
fi
elif [ -f "$destination_recovery_path" ] && [ ! -L "$destination_recovery_path" ]; then
rm -f -- "$destination_recovery_path"
fi
if [ -f "$target_auth" ]; then
chmod 600 "$target_auth" || :
fi
rm -f -- "$temporary_auth" "$temporary_credentials" "$temporary_previous_auth" "$temporary_destination_auth" "$temporary_source_auth" "$temporary_destination_snapshot" "$temporary_destination_path" "$temporary_source_snapshot" "$temporary_marker"
}

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Guard rollback_session_links inside the EXIT trap.

set -eu also applies inside cleanup. Line 131 calls rollback_session_links without || :, while line 133 guards commit_session_links. If the rollback returns non-zero (for example a manifest that is not a regular file, or a staged file whose target no longer matches), cleanup aborts at that line. The remaining recovery steps are then skipped, including the destination-recovery handling at lines 149-160 and chmod 600 "$target_auth" at lines 161-163.

The reachable consequence: the apply path installs the read-only snapshot over $target_auth at line 244 and writes the marker only at line 266. A failure in that window with a failing rollback leaves auth.json in the account home at mode 400, so Codex cannot rotate its token in that home until a later drain pass repairs the mode.

🔒️ Proposed fix
 cleanup() {
   if [ ! -f "$drain_marker" ]; then
-    rollback_session_links
+    rollback_session_links || :
   else
     commit_session_links || :
   fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cleanup() {
if [ ! -f "$drain_marker" ]; then
rollback_session_links
else
commit_session_links || :
fi
if [ ! -f "$drain_marker" ] && [ ! -e "$source_auth" ] && [ ! -L "$source_auth" ]; then
if [ -f "$source_recovery_auth" ] && [ ! -L "$source_recovery_auth" ] && [ "$(hash_file "$source_recovery_auth")" = "$expected_source_hash" ]; then
mv -- "$source_recovery_auth" "$source_auth" || :
chmod 600 "$source_auth" || :
elif [ -f "$source_quarantine_auth" ] && [ ! -L "$source_quarantine_auth" ] && [ "$(hash_file "$source_quarantine_auth")" = "$expected_source_hash" ]; then
mv -- "$source_quarantine_auth" "$source_auth" || :
chmod 600 "$source_auth" || :
fi
elif [ ! -f "$drain_marker" ]; then
# A late writer owns the recreated path; retain verified recovery artifacts for retry.
:
elif [ -f "$drain_marker" ]; then
rm -f -- "$source_recovery_auth" "$source_quarantine_auth" "$destination_recovery_path"
fi
if [ -f "$drain_marker" ]; then
if [ -f "$destination_recovery_auth" ] && [ ! -L "$destination_recovery_auth" ]; then
chmod 600 "$destination_recovery_auth" || :
fi
rm -f -- "$destination_recovery_auth" "$destination_recovery_path"
elif [ -e "$destination_recovery_auth" ] || [ -L "$destination_recovery_auth" ]; then
if [ -f "$destination_recovery_auth" ] && [ ! -L "$destination_recovery_auth" ] && [ -f "$destination_recovery_path" ] && [ ! -L "$destination_recovery_path" ]; then
${RECOVER_DESTINATION_AUTH_COMMAND} || :
fi
elif [ -f "$destination_recovery_path" ] && [ ! -L "$destination_recovery_path" ]; then
rm -f -- "$destination_recovery_path"
fi
if [ -f "$target_auth" ]; then
chmod 600 "$target_auth" || :
fi
rm -f -- "$temporary_auth" "$temporary_credentials" "$temporary_previous_auth" "$temporary_destination_auth" "$temporary_source_auth" "$temporary_destination_snapshot" "$temporary_destination_path" "$temporary_source_snapshot" "$temporary_marker"
}
cleanup() {
if [ ! -f "$drain_marker" ]; then
rollback_session_links || :
else
commit_session_links || :
fi
if [ ! -f "$drain_marker" ] && [ ! -e "$source_auth" ] && [ ! -L "$source_auth" ]; then
if [ -f "$source_recovery_auth" ] && [ ! -L "$source_recovery_auth" ] && [ "$(hash_file "$source_recovery_auth")" = "$expected_source_hash" ]; then
mv -- "$source_recovery_auth" "$source_auth" || :
chmod 600 "$source_auth" || :
elif [ -f "$source_quarantine_auth" ] && [ ! -L "$source_quarantine_auth" ] && [ "$(hash_file "$source_quarantine_auth")" = "$expected_source_hash" ]; then
mv -- "$source_quarantine_auth" "$source_auth" || :
chmod 600 "$source_auth" || :
fi
elif [ ! -f "$drain_marker" ]; then
# A late writer owns the recreated path; retain verified recovery artifacts for retry.
:
elif [ -f "$drain_marker" ]; then
rm -f -- "$source_recovery_auth" "$source_quarantine_auth" "$destination_recovery_path"
fi
if [ -f "$drain_marker" ]; then
if [ -f "$destination_recovery_auth" ] && [ ! -L "$destination_recovery_auth" ]; then
chmod 600 "$destination_recovery_auth" || :
fi
rm -f -- "$destination_recovery_auth" "$destination_recovery_path"
elif [ -e "$destination_recovery_auth" ] || [ -L "$destination_recovery_auth" ]; then
if [ -f "$destination_recovery_auth" ] && [ ! -L "$destination_recovery_auth" ] && [ -f "$destination_recovery_path" ] && [ ! -L "$destination_recovery_path" ]; then
${RECOVER_DESTINATION_AUTH_COMMAND} || :
fi
elif [ -f "$destination_recovery_path" ] && [ ! -L "$destination_recovery_path" ]; then
rm -f -- "$destination_recovery_path"
fi
if [ -f "$target_auth" ]; then
chmod 600 "$target_auth" || :
fi
rm -f -- "$temporary_auth" "$temporary_credentials" "$temporary_previous_auth" "$temporary_destination_auth" "$temporary_source_auth" "$temporary_destination_snapshot" "$temporary_destination_path" "$temporary_source_snapshot" "$temporary_marker"
}

Comment on lines +288 to +303
async prepareForCodexLaunchAsync(
target?: CodexAccountSelectionTarget,
launchEnv?: NodeJS.ProcessEnv,
options?: { unavailableManagedHomePath?: string }
): Promise<string | null> {
if (target?.runtime !== 'wsl') {
return this.prepareForCodexLaunch(target, launchEnv, options)
}
const wslTarget = this.resolveWslDefaultTarget(target)
const homePath = this.getWslCodexHomePathForSelection(wslTarget)
// Why: the retired home may hold the freshest credential, so the first
// direct-home Codex spawn must wait for its bounded guest transaction.
await this.startLegacyWslAuthDrain(wslTarget, { throwOnFailure: true })
this.finishWslLaunchPreparation(wslTarget, homePath)
return homePath
}

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect drain failure/rejection paths and completion bookkeeping.
fd -t f 'legacy-wsl-runtime-auth-drain.ts' --exec cat -n {}

Repository: stablyai/orca

Length of output: 10276


🏁 Script executed:

# Inspect the launch caller, the bound WSL runner contract, and the repository SSH boundary.
printf '%s\n' '--- review conventions ---'
head -5 /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/*/*.md 2>/dev/null || true
printf '%s\n' '--- launch method and caller ---'
sed -n '230,315p' src/main/codex-accounts/runtime-home-service.ts
rg -n -A35 -B10 'prepareCodexRuntimeHomeForLaunch|prepareForCodexLaunchAsync' src/main/index.ts src/main
printf '%s\n' '--- WSL runner binding ---'
fd -t f 'wsl-runner*' src/main --exec sh -c 'echo --- {}; sed -n "1,260p" "$1"' sh {}
printf '%s\n' '--- SSH execution boundary ---'
sed -n '1,220p' docs/reference/ssh-execution-boundary.md

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

# Read only the resolved runner implementation and the service wrapper so the rejection contract is explicit.
printf '%s\n' '--- runner files ---'
fd -t f -i 'wsl-runner' src/main
for f in $(fd -t f -i 'wsl-runner' src/main); do
  echo "--- $f"
  rg -n -A18 -B8 'export (async )?function runWslProcess|function runWslProcess|runWslProcess' "$f"
done
printf '%s\n' '--- service drain binding ---'
rg -n -A28 -B12 'startLegacyWslAuthDrain|startLegacyWslRuntimeAuthDrain' src/main/codex-accounts/runtime-home-service.ts
printf '%s\n' '--- failure-focused tests ---'
rg -n -A22 -B12 'reject|failed|timeout|throwOnFailure|wsl.exe|unavailable|drain' src/main/codex-accounts/*wsl*test.ts src/main/codex-accounts/*drain*test.ts 2>/dev/null | head -240

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

# Resolve whether WSL/process failures become drain rejections and whether the drain tests define them as recoverable.
sed -n '180,290p' src/main/wsl/wsl-runner.ts
rg -n -A45 -B10 'export (async )?function runProcess|function runProcess' src/shared/child-process/run-process.ts
sed -n '130,280p' src/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.ts
sed -n '1,240p' src/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.ts

Repository: stablyai/orca

Length of output: 23680


Do not block WSL launches on recoverable drain failures.

prepareForCodexLaunchAsync awaits startLegacyWslAuthDrain(..., { throwOnFailure: true }) before preparing the home. Non-zero inspection, finalization, or recovery results throw, and wsl.exe startup failures reject. These errors can block every subsequent WSL pane launch. Restrict rejection to unsafe states and resolve recoverable states as pending.

Comment on lines +1161 to +1167
const distro =
selectedDistroKey === getWslSelectionKey(null)
? account.wslDistro?.trim() || null
: selectedDistroKey.trim() || null
if (distro) {
drains.push(this.startLegacyWslAuthDrain({ runtime: 'wsl', wslDistro: distro }))
}

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Fall back to the default distro for the __default__ selection key.

If the selection key is getWslSelectionKey(null) and account.wslDistro is empty, distro is null and no drain runs for that lane. The launch path resolves the same lane through resolveWslDefaultTarget, so a credential refreshed in the retired home for the default distro is not preserved before restart. startLegacyWslAuthDrain already resolves the default distro when wslDistro is absent, so the target can be passed through.

♻️ Proposed change
       if (distro) {
         drains.push(this.startLegacyWslAuthDrain({ runtime: 'wsl', wslDistro: distro }))
+      } else if (selectedDistroKey === getWslSelectionKey(null)) {
+        drains.push(this.startLegacyWslAuthDrain({ runtime: 'wsl' }))
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const distro =
selectedDistroKey === getWslSelectionKey(null)
? account.wslDistro?.trim() || null
: selectedDistroKey.trim() || null
if (distro) {
drains.push(this.startLegacyWslAuthDrain({ runtime: 'wsl', wslDistro: distro }))
}
const distro =
selectedDistroKey === getWslSelectionKey(null)
? account.wslDistro?.trim() || null
: selectedDistroKey.trim() || null
if (distro) {
drains.push(this.startLegacyWslAuthDrain({ runtime: 'wsl', wslDistro: distro }))
} else if (selectedDistroKey === getWslSelectionKey(null)) {
drains.push(this.startLegacyWslAuthDrain({ runtime: 'wsl' }))
}

@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: 79237bda-7355-4814-a9fd-33a8e5df23cc

📥 Commits

Reviewing files that changed from the base of the PR and between 389d5dd and 621e411.

📒 Files selected for processing (3)
  • src/main/codex/hook-service-wsl-runtime.test.ts
  • src/main/codex/hook-service.ts
  • src/main/index.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment thread src/main/codex/hook-service.ts Outdated
Comment on lines +1204 to +1214
if (hooksEnabled) {
// Why: a managed account's launch home is its self-contained CODEX_HOME,
// so hooks/trust must install there rather than the shared mirror.
return (
(await this.installForRuntimeHomeSerialized(runtimeHomePath, target)) ??
(await this.install(runtimeHomePath ?? undefined))
)
}
return (
this.refreshRuntimeUserHooksForRuntimeHome(runtimeHomePath, target) ??
(await this.refreshRuntimeUserHooks(runtimeHomePath ?? undefined))

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Serialize disabled WSL refreshes with enabled installs.

If an enabled install is awaiting its trust grant, a disabled refresh removes its hooks. A later enabled launch reuses the old in-flight promise and starts without managed hooks. Serialize both operations per runtime home, or invalidate superseded in-flight installs. Add an enabled → disabled → enabled regression test.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 65d92891-17a4-4107-9f67-e541d9e75c47

📥 Commits

Reviewing files that changed from the base of the PR and between 621e411 and 0cf2f63.

📒 Files selected for processing (10)
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-apply-script.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-finalize-script.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts
  • src/main/codex/codex-pane-account-registry.ts
  • src/main/codex/codex-stale-pane-accounts.test.ts
  • src/main/index.ts
💤 Files with no reviewable changes (1)
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

Comment on lines +61 to +64
if [ ! -e "$source_auth" ] && [ ! -L "$source_auth" ]; then
exit ${SOURCE_AUTH_ABSENT_EXIT}
fi
[ -f "$source_auth" ] && [ ! -L "$source_auth" ] || exit 46

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Reject invalid quarantine paths before returning pending.

If source_auth is absent but source_quarantine_auth is a symlink or non-regular file, this path returns SOURCE_AUTH_ABSENT_EXIT instead of exit 46. The drain caller treats that result as pending, so migration can retry indefinitely. Reject the quarantine artifact before returning the absent-auth result.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/codex-accounts/runtime-home-service.ts (1)

1095-1100: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Drain selected system-default WSL lanes before restart.

When normalizeCodexRuntimeSelection(settings).wsl contains Ubuntu: null, this loop skips the lane and never calls startLegacyWslAuthDrain. A retained legacy pane can therefore leave refreshed auth in the retired runtime instead of the direct WSL home before restart. Run the drain for every selected lane, resolving __default__ with getDefaultWslDistro().


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fe21b5ed-d6ce-4413-83f9-2be9e22c9d35

📥 Commits

Reviewing files that changed from the base of the PR and between 0cf2f63 and 8c69c0f.

📒 Files selected for processing (10)
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-apply-script.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-rollback-script.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/codex-accounts/runtime-home-wsl-managed-accounts.test.ts
  • src/main/codex/codex-pane-account-registry-types.ts
  • src/main/codex/codex-pane-account-registry.ts
  • src/main/codex/codex-stale-pane-accounts.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +357 to +363
if (
registry.legacyWslAttributionUnknown &&
livePtyIds.every((ptyId) => ptyId in registry.panes)
) {
delete registry.legacyWslAttributionUnknown
changed = true
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- applicable repository conventions ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/*/*.md; do
  case "$f" in
    *learnings*) continue ;;
  esac
  printf '\n### %s\n' "$f"
  head -80 "$f"
done
printf '%s\n' '--- file outline ---'
ast-grep outline src/main/codex/codex-pane-account-registry.ts
printf '%s\n' '--- relevant source ---'
sed -n '1,90p' src/main/codex/codex-pane-account-registry.ts
sed -n '320,380p' src/main/codex/codex-pane-account-registry.ts
printf '%s\n' '--- symbol references ---'
rg -n -C 3 'cachedRegistryIsAuthoritative|readRegistryOrNull|reconcileCodexPaneAccountsWithLivePtys|legacyWslAttributionUnknown' src/main/codex/codex-pane-account-registry.ts src

Repository: stablyai/orca

Length of output: 38252


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- reconciliation persistence contract ---'
ast-grep outline src/main/codex/codex-pane-account-registry-mutations.ts
sed -n '1,260p' src/main/codex/codex-pane-account-registry-mutations.ts
printf '%s\n' '--- WSL drain consumers ---'
sed -n '1040,1115p' src/main/index.ts
rg -n -C 5 'hasAnyRecordedLegacyWslCodexPane|hasRecordedLegacyWslCodexPane|legacyWslAttributionUnknown|drain|retire' src/main/codex src/main/index.ts
printf '%s\n' '--- existing registry tests and filesystem setup ---'
sed -n '1,80p' src/main/codex/codex-stale-pane-accounts.test.ts
sed -n '180,345p' src/main/codex/codex-stale-pane-accounts.test.ts

Repository: stablyai/orca

Length of output: 50369


Guard reconciliation on cachedRegistryIsAuthoritative.

When parsing sets cachedRegistryIsAuthoritative to false, readRegistryOrNull() returns an empty registry with legacyWslAttributionUnknown. With [], every(...) is true, so reconciliation deletes the marker and persistReconciliation() overwrites the corrupt file. Return when !cachedRegistryIsAuthoritative, and add a regression test that preserves invalid JSON.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ad85694f-961b-4830-a86a-16c5c0936079

📥 Commits

Reviewing files that changed from the base of the PR and between 8c69c0f and a561c4d.

📒 Files selected for processing (7)
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-apply-script.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-rollback-script.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain-shell-commands.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.ts
  • src/main/codex-accounts/legacy-wsl-runtime-auth-drain.ts
  • src/main/codex/wsl-codex-session-bridge-script.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status at 1b09a21291d9963f6c438fd1542599411677cd02:

Code review: CLEAN. Live managed-WSL acceptance: OUTSTANDING.

The same-model review/fix loop completed with zero remaining in-scope P0-P2 findings. Meaningful fixes pushed during review include coalescing launch hook installation with the #16535 queue, preserving the retired-home bridge consumer, failing closed on malformed or symlinked migration state, retaining source data when pane liveness is unknown, reopening migration after rollback recreates retired auth, bounding retained-session scans with durable recovery state, handling clock rollback, and accepting valid durable state on restart/full scans. The pinned -x preflight assertion, no-launch-ownership-gate intent, and scope exclusions remain intact.

Final readiness checklist: PASS/CLEAN with no P0, P1, or P2 findings. The implementation also matches standard transactional migration precedent: validate destination before source retirement, persist bounded progress, and recover fail-closed.

Validation on the final head:

  • Changed suites run serially: 12 files, 179/179 passed.
  • Focused drain/bridge suites: 4 files, 59/59 passed.
  • Real /bin/sh apply/rollback coverage: passed.
  • pnpm tc:node, strict oxlint, oxfmt, and git diff --check: passed.
  • One earlier parallel aggregate run timed out one interruption test at 20 seconds under load; that test passed isolated, focused, and in the final serial run.

Exact-head Electron/CDP validation was retried with Codex on the Windows high-spec host and real Ubuntu-24.04 WSL. The rendered WSL account surface was reached, but the isolated profile had no managed Codex account. A reversible no-secret disposable fixture was attempted through the real Add Account service; it failed during managed-home creation before login, so it did not create a valid managed account and was not used as synthetic success evidence. Ubuntu-24.04 was restored as default and the disposable distro/processes were cleaned up.

Therefore these required live scenarios remain explicitly UNEXERCISED:

  1. Managed WSL account launch against its in-distro managed home.
  2. Exactly-once retired-home drain with destination credentials intact and source retired.
  3. Pre-upgrade conversation visible through /resume.
  4. Direct shell codex receiving the managed account CODEX_HOME without the launcher.

No source defect was proven by the hardware attempt, but the managed-account live acceptance gap remains and should not be treated as passed hardware validation.

brennanb2025 and others added 2 commits August 28, 2026 11:04
main split hook-service.ts and moved CodexHookService into
codex-hook-service-implementation.ts. Took main's file and reinstated
prepareRuntimeHomeForLaunch beside installForRuntimeHomeSerialized in its new
home; index.ts still calls it and its test still covers it, so taking main's
version alone would have left it undefined.
@greptile-apps

greptile-apps Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR re-lands direct WSL Codex account homes with a recoverable one-time credential drain and session-history bridging.

  • Replaces the shared WSL runtime mirror with account-specific in-distro homes.
  • Adds guarded migration, quarantine, recovery, and completion-marker scripts.
  • Bridges pre-cutover session history and updates restart-preservation behavior.
  • Adds extensive shell-level migration, interference, rollback, and launch tests.

Confidence Score: 2/5

The PR does not yet appear safe to merge because session history can still cross account boundaries and restart preservation can still wake stopped WSL distros.

The current launch bridge publishes every JSONL file from an account-agnostic system or override source into the selected account home, while restart preservation invokes and awaits guest commands for selected distros without checking whether they are running.

Files Needing Attention: src/main/codex-accounts/runtime-home-service.ts, src/main/codex/wsl-codex-session-bridge.ts, src/main/codex/wsl-codex-session-bridge-script.ts, src/main/agent-auth-restart-preservation.ts

Important Files Changed

Filename Overview
src/main/codex-accounts/runtime-home-service.ts Coordinates direct-home launch, migration, session bridging, and restart drains; both previously reported ownership and stopped-distro issues remain.
src/main/codex-accounts/legacy-wsl-runtime-auth-drain.ts Implements the one-time legacy-home inspection, identity matching, migration orchestration, and recovery path.
src/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.ts Adds guest-side transactional credential promotion, quarantine, verification, session linking, rollback, and durable completion behavior.
src/main/codex/wsl-codex-session-bridge.ts Bridges WSL session files into managed homes, while its caller still lacks source-account authorization.
src/main/agent-auth-restart-preservation.ts Awaits WSL migration outside the shared lifecycle deadline, leaving stopped-distro activation reachable during restart.

Sequence Diagram

sequenceDiagram
    participant R as Restart or launch
    participant H as Runtime home service
    participant W as WSL distro
    participant L as Retired runtime home
    participant A as Selected account home
    R->>H: Prepare launch or preserve restart
    H->>W: Inspect legacy runtime state
    W->>L: Verify auth and recovery state
    L->>A: Promote verified credentials
    L->>A: Bridge authorized retired sessions
    H->>W: Bridge system or configured session source
    H-->>R: Return direct account home
Loading

Reviews (3): Last reviewed commit: "fix(codex): keep the split drain harness..." | Re-trigger Greptile

Comment on lines 589 to +597
const systemCodexHomePath =
resolveWslCodexSessionSourceHome(this.store.getSettings(), distro) ??
this.getWslSystemCodexHomePath({ runtime: 'wsl', wslDistro: distro })
if (!systemCodexHomePath || systemCodexHomePath === runtimeHomePath) {
return
if (systemCodexHomePath && systemCodexHomePath !== runtimeHomePath) {
// Why: WSL history must be hardlinked inside the distro; host-side links can't bridge Windows and WSL filesystems in a resume-visible way.
void startWslCodexSessionBridgeInBackground({
distro,
systemCodexHomePath,
managedCodexHomePath: runtimeHomePath

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 security Session bridge lacks account authorization

If the distro-level system home or configured session-source override contains conversations from another account, this launches the bridge without checking source ownership and links every source JSONL into the selected account's live CODEX_HOME, exposing those conversations through /resume and allowing hardlinks to reflect later source writes.

How this was verified: The selected launch home is passed directly as the bridge target, while the source is chosen by distro or override and receives no account-identity check before all JSONL files are linked.

Knowledge Base Used:

Comment on lines +1105 to +1110
const distro =
selectedDistroKey === getWslSelectionKey(null)
? account.wslDistro?.trim() || null
: selectedDistroKey.trim() || null
if (distro) {
drains.push(this.startLegacyWslAuthDrain({ runtime: 'wsl', wslDistro: distro }))

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 Restart drain wakes stopped distros

When a managed account remains selected for a stopped WSL distro, restart preservation targets that distro without checking its running state, booting it without user intent and blocking the Electron main process during the synchronous home probe before the awaited drain can further delay relaunch.

Knowledge Base Used:

Merge Sim added 2 commits August 30, 2026 20:03
…on replacement

Removing the four `target_auth -ef temporary_destination_auth` assertions left
all 33 apply-script tests passing, so a regression deleting them would have
shipped silently. Reproduced before writing this.

A hash check cannot catch the case. The pinned hard link keeps the original
inode, so it still hashes correctly after another writer atomically renames a
different file over the destination path; only inode identity sees it. Without
the guard the script exits 0 and retires the source, leaving the user holding
bytes nothing validated. The new case asserts the source survives.

The harness is split by responsibility so no file exceeds its max-lines budget:
fixtures, the coreutils interference shims, the run types, the apply runner, and
the recovery/absent runners. The atomic-rename hook is deliberately separate
from the in-place rewrite shim because different guards catch them.
…ndaries

Extracting the harness into non-test modules moved it out of the exemptions the
single test file had: three new files import child_process, and two spawned
without windowsHide.

Adds the three to the import allowlist, and sets windowsHide on the spawns
rather than exempting them - the flag is correct for these calls regardless of
the ratchet, and they are skipped on win32 anyway.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ed (stablyai#16854)

* fix(codex): safely re-land WSL direct homes

* fix(codex): finish WSL direct-home cutover

* fix(codex): coalesce WSL launch hook installs

* perf(codex): avoid duplicate retired WSL session scan

* fix(codex): retain canonical WSL retired-home path

* fix(codex): fail closed before retiring WSL auth

* fix(codex): reopen WSL drain after rollback

* fix(codex): preserve WSL source on unknown panes

* fix(codex): harden repeated WSL runtime drains

* perf(codex): bound pending WSL session scans

* fix(codex): recover invalid WSL session watermarks

* fix(codex): validate retained WSL scan state

* fix(codex): accept durable WSL scan state

* test(codex): cover the drain's inode-identity guard against destination replacement

Removing the four `target_auth -ef temporary_destination_auth` assertions left
all 33 apply-script tests passing, so a regression deleting them would have
shipped silently. Reproduced before writing this.

A hash check cannot catch the case. The pinned hard link keeps the original
inode, so it still hashes correctly after another writer atomically renames a
different file over the destination path; only inode identity sees it. Without
the guard the script exits 0 and retires the source, leaving the user holding
bytes nothing validated. The new case asserts the source survives.

The harness is split by responsibility so no file exceeds its max-lines budget:
fixtures, the coreutils interference shims, the run types, the apply runner, and
the recovery/absent runners. The atomic-rename hook is deliberately separate
from the in-place rewrite shim because different guards catch them.

* fix(codex): keep the split drain harness inside the child-process boundaries

Extracting the harness into non-test modules moved it out of the exemptions the
single test file had: three new files import child_process, and two spawned
without windowsHide.

Adds the three to the import allowlist, and sets windowsHide on the spawns
rather than exempting them - the flag is correct for these calls regardless of
the ratchet, and they are skipped on win32 anyway.

---------

Co-authored-by: Merge Sim <sim@local>
nwparker added a commit that referenced this pull request Oct 25, 2026
…tem default

WSL launches bridged only the distro's ~/.codex into the selected account
home, so a session started on another managed WSL account was missing after
switching (regressed by the direct-home cutover in #16854). Bridge every
sibling WSL account home in the distro too, one wsl.exe at a time.

Host system-default launches on the real ~/.codex bridged nothing, so
sessions from managed accounts disappeared when switching back. Bridge
managed host account homes into the real home with the existing
account-session bridge, which also heals Codex's thread index.

Fixes #18486
Fixes #25000
nwparker added a commit that referenced this pull request Oct 28, 2026
…e loop per home

System default's own ~/.codex in the distro gets no sibling sources, so the
#24511 product decision stays out of this change. Concurrent launches join the
loop already bridging a target home. Restores #16854's drain-target assertion
with the launch bridge mocked.
nwparker added a commit that referenced this pull request Oct 28, 2026
* fix(codex): keep Codex history across WSL account switches

Bridge the distro's system home and every sibling managed WSL account home in
the same distro into the selected account's home at launch, so a session
started on account A is resumable after switching to account B (#18486).

Split from #33578 (WSL half only).

* fix(codex): bridge WSL siblings only into a selected account home, one loop per home

System default's own ~/.codex in the distro gets no sibling sources, so the
#24511 product decision stays out of this change. Concurrent launches join the
loop already bridging a target home. Restores #16854's drain-target assertion
with the launch bridge mocked.
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