@@ -14,7 +14,7 @@ import { expandUserPath, getConfigDir, readPid, removePid, removeRuntimePort, ve
1414import { loadConfig } from "./config" ;
1515import { restoreNativeCodex , restoreNativeCodexAsync } from "./codex/inject" ;
1616import { stripGrokConfig } from "./grok/inject" ;
17- import { isWslRuntime } from "./codex/home" ;
17+ import { isWslRuntime , resolveCodexHomeDir , type CodexHomeDeps } from "./codex/home" ;
1818import { BUN_RUNTIME_PATH_ENV , BUN_RUNTIME_SOURCE_ENV , durableBunRuntime } from "./lib/bun-runtime" ;
1919import type { BunRuntimeSource } from "./lib/bun-runtime" ;
2020import { isProcessAlive , stopProxy } from "./lib/process-control" ;
@@ -94,9 +94,11 @@ function serviceStatePaths(): string[] {
9494 return paths ;
9595}
9696
97- function currentCodexHome ( ) : string {
98- const raw = process . env . CODEX_HOME ?. trim ( ) ;
99- return raw ? resolve ( expandUserPath ( raw ) ) : join ( homedir ( ) , ".codex" ) ;
97+ function currentCodexHome ( deps : CodexHomeDeps = { } ) : string {
98+ // Service ownership must identify the same home as the runtime. In WSL an
99+ // unset CODEX_HOME can resolve to the single Windows Desktop home rather than
100+ // Linux ~/.codex; recording the fallback here creates a false foreign owner.
101+ return resolveCodexHomeDir ( deps ) ;
100102}
101103
102104function currentOpenCodexHome ( ) : string {
@@ -218,8 +220,8 @@ export function inspectServiceStateEvidence(
218220}
219221
220222/** The homes this process is actually using, for comparison against a claim. */
221- export function currentServiceHomes ( ) : { codexHome : string ; opencodexHome : string } {
222- return { codexHome : currentCodexHome ( ) , opencodexHome : currentOpenCodexHome ( ) } ;
223+ export function currentServiceHomes ( deps : CodexHomeDeps = { } ) : { codexHome : string ; opencodexHome : string } {
224+ return { codexHome : currentCodexHome ( deps ) , opencodexHome : currentOpenCodexHome ( ) } ;
223225}
224226
225227export function serviceHomeMatches ( a : string , b : string ) : boolean {
0 commit comments