[Bug] Windows hook lifecycle test can overwrite live Codex runtime hooks
Summary
Running the cross-platform managed-hook stdin lifecycle test from an Orca-launched terminal can overwrite Orca's real managed Codex hooks.json with Windows hook commands, even when the host is macOS or Linux.
The test mocks homedir() and Electron app.getPath(), but it does not isolate the inherited ORCA_USER_DATA_PATH. getOrcaManagedCodexHomePath() gives that environment variable priority, so the test's simulated win32 installs write into the caller's managed runtime home instead of the test fixture.
Impact
The shared managed Codex config can end up with commands beginning with:
C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe ...
Subsequent Codex sessions on POSIX hosts then report failures such as:
SessionStart hook (failed)
error: hook exited with code 127
UserPromptSubmit hook (failed)
error: hook exited with code 127
All Orca-managed Codex events are affected because they share the same runtime hooks.json. Existing sessions may continue using the bad handlers until restarted after the config is repaired.
Safe reproduction
Use an isolated user-data root so the reproduction cannot touch a real Orca profile:
tmp_root="$(mktemp -d)"
ORCA_USER_DATA_PATH="$tmp_root/orca-user-data" \
pnpm exec vitest run --config config/vitest.config.ts \
src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts \
-t 'routes every batch guard to a shared drain epilogue' \
--maxWorkers=1
rg 'WindowsPowerShell|codex-hook\.cmd' \
"$tmp_root/orca-user-data/codex-runtime-home/home/hooks.json"
The test passes, but the isolated caller-supplied runtime home contains the simulated Windows Codex hook. In a normal Orca terminal, ORCA_USER_DATA_PATH points at the active Orca user-data root, so the same write targets the live managed runtime.
Root cause
src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts- creates a temporary home;
- temporarily changes
process.platformtowin32; - calls every local hook service's real
install()method; - isolates
GROK_HOMEandKIMI_CODE_HOME, but notORCA_USER_DATA_PATH.
src/main/codex/codex-home-paths.ts- resolves the managed Codex home from
ORCA_USER_DATA_PATHbefore consulting platform-specific home paths.
- resolves the managed Codex home from
The temporary-home mock therefore protects the generated hook script location, but not the managed Codex configuration location.
The test was introduced by c3ab805d12ff15372efe7d77fbb232cd8b2440ab and is present in v1.4.138-rc.6, v1.4.138-rc.7, and current main.
Expected behavior
Tests must never read or write the caller's active Orca user-data root. The test should scope ORCA_USER_DATA_PATH to a fixture-owned directory and restore the original value in finally/test teardown.
A regression assertion should prove that an inherited external user-data sentinel remains unchanged while the simulated Windows install writes only below the fixture root.
Related
- #8110 reports the same exit-127 symptom, but its earlier direct-exec command-shape hypothesis was overturned by official Codex runner evidence.
- #8390 was closed without merge after that hypothesis was disproved.
This issue tracks the separately confirmed test-isolation root cause.
Confirmed this also corrupts the live managed config.toml, not only hooks.json.
When the leaked test environment reaches CodexHookService.install(), the config mirror sees a missing fake system config plus the real runtime config. It rewrites the runtime file to only its preserved sections. In our live case that left:
- 844
[projects.*]tables - 6
[hooks.state.*]tables - no global settings or other tables
An isolated reproduction started with model, [features], and one project; the test passed but removed model and [features], leaving one project plus six hook-state tables.
This can happen on macOS/Linux when tests run inside an Orca terminal and simulate Windows, so the impact is not Windows-only.
Agent reproduction package (Windows orchestration 2026-07-16)
Host context: Windows 11 / Orca 1.4.143.0 / repo path used: docs/bug-reproductions/
Labels applied: see issue labels (has_repro or cannot_repro).
Security: Do not run user-uploaded binaries from issue attachments. Recreate fixtures from the steps/scripts below.
Issue 8629 — Windows hook lifecycle test can overwrite live Codex runtime hooks
Status: repro_confirmed
Host: Windows 11, Orca 1.4.143, repo main @ local checkout
Label: has_repro
Summary
managed-hook-stdin-lifecycle.test.ts temporarily sets process.platform to win32 and runs every local hook service’s real install(). It mocks homedir() / Electron app.getPath(), and isolates GROK_HOME / KIMI_CODE_HOME, but does not isolate ORCA_USER_DATA_PATH.
getOrcaManagedCodexHomePath() prioritizes ORCA_USER_DATA_PATH, so Codex hooks.json is written under the caller’s managed runtime home (in an Orca terminal: the live profile), not only under the temporary home used for scripts.
Root cause (code)
| File | Issue |
|---|---|
src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts |
withPlatform('win32', …) + LOCAL_INSTALLERS call real install(); no ORCA_USER_DATA_PATH fixture |
src/main/codex/codex-home-paths.ts |
getOrcaUserDataPath() returns process.env.ORCA_USER_DATA_PATH first |
src/main/codex/hook-service.ts |
getConfigPath() → join(getOrcaManagedCodexHomePath(), 'hooks.json') |
Repro (another agent)
Isolated user-data root — does not touch the live profile:
cd <repo>
powershell -NoProfile -ExecutionPolicy Bypass -File docs/bug-reproductions/scripts/repro-8629-hook-lifecycle-overwrite.ps1
# Expect exit 0 and bugReproduced=true
Manual equivalent:
$tmp = Join-Path $env:TEMP ("orca-repro-8629-" + [guid]::NewGuid().ToString('N').Substring(0,8))
$userData = Join-Path $tmp "orca-user-data"
New-Item -ItemType Directory -Path $userData -Force | Out-Null
$env:ORCA_USER_DATA_PATH = $userData
pnpm exec vitest run --config config/vitest.config.ts `
src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts `
-t "routes every batch guard to a shared drain epilogue" --maxWorkers=1
# Then inspect:
# $userData\codex-runtime-home\home\hooks.json
Expected vs actual
| Expected | Test only writes under its temp homedir fixture; caller ORCA_USER_DATA_PATH / live managed Codex home unchanged |
| Actual | Test passes, but $ORCA_USER_DATA_PATH/codex-runtime-home/home/hooks.json is created/overwritten with Windows if exist … codex-hook.cmd commands |
Evidence
docs/bug-reproductions/evidence/8629-meta.json—bugReproduced: truedocs/bug-reproductions/evidence/8629-hooks.json— written hooks (Windows cmd compound)docs/bug-reproductions/evidence/8629-vitest.log— test pass
Sample command written into managed hooks:
if exist "…\.orca\agent-hooks\codex-hook.cmd\." (…) else if exist "…\codex-hook.cmd" (call "…") else (…)
Fix hint
In the test try/finally:
- Save and set
process.env.ORCA_USER_DATA_PATHto a fixture-owned directory (not the caller’s). - Restore the previous value in teardown.
- Assert that an external sentinel user-data path’s
hooks.jsonis untouched while the fixture root receives the Windows install.
Repro script: repro-8629-hook-lifecycle-overwrite.ps1
# Repro #8629: Windows hook lifecycle test writes into ORCA_USER_DATA_PATH managed Codex home
# Usage: powershell -NoProfile -ExecutionPolicy Bypass -File docs/bug-reproductions/scripts/repro-8629-hook-lifecycle-overwrite.ps1
$ErrorActionPreference = "Stop"
$repo = Resolve-Path (Join-Path $PSScriptRoot "..\..\..")
Set-Location $repo
$evDir = Join-Path $repo "docs\bug-reproductions\evidence"
New-Item -ItemType Directory -Path $evDir -Force | Out-Null
$stamp = Get-Date -Format "yyyyMMdd-HHmmss"
$tmpRoot = Join-Path $env:TEMP ("orca-repro-8629-" + $stamp)
$userData = Join-Path $tmpRoot "orca-user-data"
New-Item -ItemType Directory -Path $userData -Force | Out-Null
$env:ORCA_USER_DATA_PATH = $userData
Write-Host "ORCA_USER_DATA_PATH=$userData"
$log = Join-Path $evDir "8629-$stamp-vitest.log"
pnpm exec vitest run --config config/vitest.config.ts `
src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts `
-t "routes every batch guard to a shared drain epilogue" `
--maxWorkers=1 2>&1 | Tee-Object -FilePath $log
$hooksPath = Join-Path $userData "codex-runtime-home\home\hooks.json"
$bug = $false
$content = $null
if (Test-Path $hooksPath) {
$content = Get-Content $hooksPath -Raw
Copy-Item $hooksPath (Join-Path $evDir "8629-$stamp-hooks.json")
if ($content -match "WindowsPowerShell|powershell\.exe|codex-hook\.cmd|if exist") { $bug = $true }
}
$meta = @{
issue = 8629
stamp = $stamp
userData = $userData
hooksPath = $hooksPath
hooksWritten = (Test-Path $hooksPath)
bugReproduced = $bug
vitestExit = $LASTEXITCODE
}
$metaPath = Join-Path $evDir "8629-$stamp-meta.json"
$meta | ConvertTo-Json | Set-Content $metaPath -Encoding utf8
Write-Host "bugReproduced=$bug meta=$metaPath"
if (-not $bug) { exit 2 }
exit 0
How another agent should use this
- Read this comment fully (status, expected vs actual, blockers).
- If a script is included above, copy it to a temp file and run it on a Windows 11 host with Orca installed (prefer production install under
%LOCALAPPDATA%\Programs\orca). - Capture evidence (CLI
--json, screenshots, logs) under a local folder; optionally comment results back here. - If status is
cannot_repro/ needs_setup, satisfy the listed prerequisites first, then re-attempt and flip labels: removecannot_repro, addhas_reprowhen conclusive.
Resolved by merged PR #9501 (commit e58de71f), which isolates the hook lifecycle test user-data path. Closing as completed.