Repository navigation
fix(codex): re-land WSL direct-home cutover with counsel findings fixed - #16854
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe 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 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)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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 Resolution Add the required template sections. Include a linked issue using ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (28)
src/main/agent-auth-restart-preservation.test.tssrc/main/agent-auth-restart-preservation.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-apply-script.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-exit-codes.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-shell-commands.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-finalize-script.tssrc/main/codex-accounts/runtime-home-service.tssrc/main/codex-accounts/runtime-home-wsl-managed-accounts.test.tssrc/main/codex-accounts/runtime-home-wsl-retired-session-launch.test.tssrc/main/codex-accounts/runtime-home-wsl-session-bridge.test.tssrc/main/codex-accounts/runtime-home-wsl-system-default.test.tssrc/main/codex-accounts/wsl-codex-auth-batch-reader.tssrc/main/codex/codex-pane-account-registry.tssrc/main/codex/codex-pane-launch-account.test.tssrc/main/codex/codex-pane-launch-account.tssrc/main/codex/codex-stale-pane-accounts.test.tssrc/main/codex/wsl-codex-session-bridge-script.tssrc/main/codex/wsl-codex-session-bridge.test.tssrc/main/codex/wsl-codex-session-bridge.tssrc/main/index.tssrc/main/pty/codex-home-wsl-env.tssrc/main/wsl/__fixtures__/wsl-invocation-allowlist.txtsrc/shared/child-process/__fixtures__/child-process-import-allowlist.txtsrc/shared/wsl-paths.test.tssrc/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.
| 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" | ||
| } |
There was a problem hiding this comment.
🩺 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.
| 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" | |
| } |
| 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 | ||
| } |
There was a problem hiding this comment.
🩺 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.mdRepository: 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 -240Repository: 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.tsRepository: 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.
| const distro = | ||
| selectedDistroKey === getWslSelectionKey(null) | ||
| ? account.wslDistro?.trim() || null | ||
| : selectedDistroKey.trim() || null | ||
| if (distro) { | ||
| drains.push(this.startLegacyWslAuthDrain({ runtime: 'wsl', wslDistro: distro })) | ||
| } |
There was a problem hiding this comment.
🗄️ 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.
| 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' })) | |
| } |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
src/main/codex/hook-service-wsl-runtime.test.tssrc/main/codex/hook-service.tssrc/main/index.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| 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)) |
There was a problem hiding this comment.
🎯 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.
There was a problem hiding this comment.
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
📒 Files selected for processing (10)
src/main/codex-accounts/legacy-wsl-runtime-auth-drain-apply-script.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-finalize-script.tssrc/main/codex-accounts/runtime-home-service.tssrc/main/codex-accounts/runtime-home-wsl-session-bridge.test.tssrc/main/codex/codex-pane-account-registry.tssrc/main/codex/codex-stale-pane-accounts.test.tssrc/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.
| if [ ! -e "$source_auth" ] && [ ! -L "$source_auth" ]; then | ||
| exit ${SOURCE_AUTH_ABSENT_EXIT} | ||
| fi | ||
| [ -f "$source_auth" ] && [ ! -L "$source_auth" ] || exit 46 |
There was a problem hiding this comment.
🩺 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.
There was a problem hiding this comment.
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 winDrain selected system-default WSL lanes before restart.
When
normalizeCodexRuntimeSelection(settings).wslcontainsUbuntu: null, this loop skips the lane and never callsstartLegacyWslAuthDrain. 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__withgetDefaultWslDistro().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fe21b5ed-d6ce-4413-83f9-2be9e22c9d35
📒 Files selected for processing (10)
src/main/codex-accounts/legacy-wsl-runtime-auth-drain-apply-script.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-rollback-script.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain.tssrc/main/codex-accounts/runtime-home-service.tssrc/main/codex-accounts/runtime-home-wsl-managed-accounts.test.tssrc/main/codex/codex-pane-account-registry-types.tssrc/main/codex/codex-pane-account-registry.tssrc/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.
| if ( | ||
| registry.legacyWslAttributionUnknown && | ||
| livePtyIds.every((ptyId) => ptyId in registry.panes) | ||
| ) { | ||
| delete registry.legacyWslAttributionUnknown | ||
| changed = true | ||
| } |
There was a problem hiding this comment.
🗄️ 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 srcRepository: 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.tsRepository: 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.
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
src/main/codex-accounts/legacy-wsl-runtime-auth-drain-apply-script.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-rollback-script.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-scripts.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain-shell-commands.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain.test.tssrc/main/codex-accounts/legacy-wsl-runtime-auth-drain.tssrc/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.
|
Review status at 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 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:
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:
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. |
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 SummaryThe PR re-lands direct WSL Codex account homes with a recoverable one-time credential drain and session-history bridging.
Confidence Score: 2/5The 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
|
| 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
Reviews (3): Last reviewed commit: "fix(codex): keep the split drain harness..." | Re-trigger Greptile
| 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 |
There was a problem hiding this comment.
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:
| const distro = | ||
| selectedDistroKey === getWslSelectionKey(null) | ||
| ? account.wslDistro?.trim() || null | ||
| : selectedDistroKey.trim() || null | ||
| if (distro) { | ||
| drains.push(this.startLegacyWslAuthDrain({ runtime: 'wsl', wslDistro: distro })) |
There was a problem hiding this comment.
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:
…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.
…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>
…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
* 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.
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
/resumeon a Codex session you started before the upgrade/mnt/c/...)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=0a 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 bymvrather thanrm, 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
mainheld the rescue code unprotected. Landing atomically removes that window. The prerequisite work (#16496, #16499) is already inmainand was not reverted.Verification
pnpm typecheckcleancodex-accounts,codex,wsl,agent-hooks, restart preservationbash, skipped on win32 — the P0 originally survived review because those guards were only ever reachable through a mocked runner3558cf943f; 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 holdsNot 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-typedcodexpicking up the rightCODEX_HOMEwithout the agent launcher.