Repository navigation
fix(codex): restored Codex panes on a managed account resume instead of failing with SUN_LEN - #23724
Conversation
Review status: ready for reviewVerdict: the change is correct and fixes the reported failure mode; no code changes were needed after review. Head What the user saw: after a reboot, Codex panes that Orca restored on a managed Codex account failed with Why: a restored pane runs The fix: every automatic resume now writes the setting into the exact folder it launches in, just before Codex starts, the same rule fresh launches already follow. The user's real Review: two independent review loops, both clean with no code findings; the PR description was corrected for three overstatements. Start- and end-of-session readiness checks: the start check's two blockers (root cause, no live test) are resolved by the evidence below. Live test (separate Mac, Codex 0.157.0, isolated profile, no real credentials; each build rebuilt and checked in its bundle):
Known limits, not caused by this PR (left for follow-up):
|
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
prepareCodexSessionResumeForLaunchnow guards the home it pins — after hook repair,resolveVerifiedResumeHomecalls the existingensureCodexDaemonSocketGuard(resumeHome)for non-system homes, so a resumed managedCODEX_HOMEgets[features] daemon_auto_start = falseeven when hook repair skips or throws before its config mirror runs (src/main/startup/codex-session-resume-launch.ts:115).- New
codex-session-resume-daemon-guard.test.ts— runs real resume launch prep against a real too-long temp account home: guard lands when hook repair throws (hooks on), when refresh early-returns (hooks off), and is never written when a migrated resume lands on the real~/.codex.
I verified the change rather than trusting the description: the new suite passes (3/3), and an ablation removing the four added lines fails exactly tests 1 and 2 while the real-home test still passes — so the tests genuinely pin the new behavior. oxlint is clean on both files. The system-home skip is reliable (resumeHome is always an element of trustedCodexHomes or systemHomePath via migration, compared after normalization), the guard helper is synchronous, best-effort and idempotent, and remote/WSL targets never reach this function.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughResume launch now applies Priority: ➖ Normal Merge Risk: 🔵 Low · up to A host resume that will be rejected can still change a WSL account’s daemon setting, affecting later WSL Codex sessions. This is a bounded issue with a localized correction. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change improves restoration of managed Codex sessions, but a host-side resume can attempt to change a WSL account’s configuration before the incompatible launch is rejected. The identified scope is limited to a discovered account home; no privilege gain is established. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 610bba44-dd44-4feb-8a59-361184e43c99
📒 Files selected for processing (2)
src/main/startup/codex-session-resume-daemon-guard.test.tssrc/main/startup/codex-session-resume-launch.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| if (!isSystemHome) { | ||
| // Why: this pins the resumed pane's CODEX_HOME, and hook repair above can skip or fail before its config mirror applies the daemon guard. | ||
| ensureCodexDaemonSocketGuard(resumeHome) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,150p' src/main/codex/codex-daemon-socket-path-guard.ts
sed -n '115,150p' src/main/codex/codex-config-mirror.ts
sed -n '1,120p' src/main/codex-accounts/runtime-home-service-home-routing.ts
rg -n "isWslCodexHomeForHost|wslInfo|wsl.localhost|daemon_auto_start" src/mainRepository: stablyai/orca
Length of output: 41349
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- resume launch ---'
sed -n '1,145p' src/main/startup/codex-session-resume-launch.ts
printf '%s\n' '--- host compatibility and target selection ---'
sed -n '1,165p' src/main/ipc/pty/host-env/codex-home.ts
printf '%s\n' '--- WSL home binding ---'
sed -n '1,135p' src/main/pty/codex-home-wsl-env.ts
printf '%s\n' '--- config mirror imports and guard path ---'
sed -n '1,35p' src/main/codex/codex-config-mirror.ts
sed -n '115,150p' src/main/codex/codex-config-mirror.ts
printf '%s\n' '--- managed WSL home construction ---'
rg -n -A18 -B8 "getManagedAccountHomesForSessionDiscovery|managedHomePath|codex-accounts/.+home|codex-accounts" src/main/codex-accounts src/main/codex | head -240
printf '%s\n' '--- focused daemon guard tests ---'
sed -n '1,155p' src/main/codex/codex-daemon-socket-path-guard.test.ts
sed -n '1,155p' src/main/startup/codex-session-resume-daemon-guard.test.tsRepository: stablyai/orca
Length of output: 42460
Skip the daemon guard for WSL homes during host resume.
Host discovery includes WSL-managed homes. A matching WSL home can reach ensureCodexDaemonSocketGuard before host PTY compatibility rejects it. On Windows, the host-visible UNC path resolves config.toml inside the WSL home. The guard can then add or remove daemon_auto_start, although the host resume cannot spawn.
Suggested fix
import { normalizeRuntimePathForComparison } from '../../shared/cross-platform-path'
+import { parseWslUncPath } from '../../shared/wsl-paths'
import { mainProcessState as state } from './main-process-state'
...
- if (!isSystemHome) {
+ if (!isSystemHome && !parseWslUncPath(resumeHome)) {Kept main's daemon socket guard on resume (#23724) beside the per-agent hooks check; its new test mocks the per-agent predicate.
…3745, #23783, #22971, #22565, #22846, #23724, #23721, #23693, #23810) into #23059 #23671 (group chat rows by the turn that produced them) is ported onto #23059's turn-scope model, so there is one grouping mechanism, not two: - A host that states each row's turn scope groups by that scope, as before. #23671's journal-order derivation (rows between one turn record and the next belong to it) moves from the timing selector into src/shared/native-chat-turn-grouping.ts and runs only for a host that states no scope, replacing the positional fallback there. - #23671's anchor rules live in structuredAgentTurnAnchors, which membership, settled timing and the live clock all read: a turn whose opener key nothing resolves yet takes the send still in flight ahead of its record (Codex before its echo), else its own record. - The live turn is one key again. #23671 made row liveness follow the owning turn, so the bar key and the liveness key are always the same; nativeChatTurnMembership now returns only liveTurnKey (barTurnKey, activeTurnOpenedBy and turnKeysByItemId are gone). - A turn with no user bubble draws its bar above its first row (nativeChatTurnBarRows, desktop and mobile), and a turn's diff rollup goes under its last row. - The Codex full-history restore writes each record ahead of its items; that also fixes the derived turn scope on #23059's journal. #23026 (Stop from the moment a message is sent) is ported onto #23059's command turns: the cancel paths ask the translator for a command's provider turn instead of the removed compaction tracker, and a Stop that names no turn still ends a running /compact through its child. performCancel moved to structured-agent-session-turns-cancel.ts to keep the turns module under the line limit. #22090's awaitingInput replaces showTurnStatus/showLiveTurnActivity; the waiting-behind-/compact rows are kept.



ELI5
Follow-up to #22878, which made Codex 0.157+ start in Orca-managed Codex homes whose path is too long for Codex's background server. Scope: automatic resume of Codex panes (restart/reboot restore, lazy restore when a worktree is opened, sleeping-agent wake) on the local host, for managed Codex accounts on macOS, Linux and Windows. Not affected: fresh Codex launches (already guarded), the system-default account (the user's real
~/.codexis never written), SSH and WSL panes.After a reboot, Codex conversations that Orca brought back on a managed Codex account could fail to start (
app server did not become ready,path must be shorter than SUN_LEN) and leave a plain shell. When Orca brings a Codex conversation back after a restart, it relaunches Codex inside the folder that belongs to the Codex account the conversation came from. For some accounts that folder's path is too long for Codex's background server, so Orca writes one setting that tells Codex not to start that server. The resume path only wrote that setting as a side effect of another step that can skip it. Now the resume path writes it itself, right when it picks the folder.What Changed
Before: after a reboot, Codex panes Orca restored on a managed Codex account could fail with
app server did not become ready/path must be shorter than SUN_LEN, and only a manualcodex resume <id> --no-daemonworked.After: the restored pane resumes normally, because Orca now writes
daemon_auto_start = false(Orca's marked line) into the account folder it resumes in, right before Codex starts.Mechanism:
prepareCodexSessionResumeForLaunch(src/main/startup/codex-session-resume-launch.ts) is where an automatic resume picks the CODEX_HOME the pane will run in. It now calls the existingensureCodexDaemonSocketGuardon that home after hook repair, skipping the user's real Codex home. The call is idempotent (no write when the line is already there or the path is short) and best-effort: it never fails the resume. Ifconfig.tomlcan't be read at that moment, or changes between read and write, it skips the write without logging (an existing limitation of this helper, shared with the startup pass).Every automatic resume goes through this one function: renderer cold restore after a reboot, sleeping-agent wake, and runtime/RPC-created terminals all reach it through
prepareCodexResumeHomein both the IPC and runtime spawn paths. Reattaching to a still-running pane starts no new Codex process, so it needs nothing.Why
Root cause: a fresh Codex launch applies the guard at the point it picks its home (
prepareSelfContainedManagedHomeForLaunchmirrors config into the account home). A resume skips that step, because it pins the home that owns the transcript. That home got the guard in only two indirect ways. (1) The account service's startup pass over every saved account. (2) The config mirror inside hook repair:installCodexHooksExclusivelywhen status hooks are on,refreshCodexRuntimeUserHooksExclusivelywhen they are off.Hook repair returns before it reaches the mirror when the account's
hooks.jsonis malformed, or when~/.codex/hooks.jsoncan't be read. It throws before the mirror if writing the hook script orhooks.jsonfails, and the resume path catches that throw and carries on. In each case the resume went ahead with no guard, unless the startup pass had already covered that home.Alternatives considered: running the full config mirror (
syncSystemConfigIntoManagedCodexHome) on resume, which would copy~/.codexsettings into an account the user isn't using and rewrite its config for every restored pane. Making hook repair always reach its mirror, which keeps a launch-critical setting tied to hook bookkeeping. Retrying or hardening the startup pass, which would still leave a restored pane depending on a one-time pass instead of on its own launch. Guarding where the resume home is chosen gives resumes the rule fresh launches already follow (the launch that picks a home guards it), and it doesn't depend on hook settings or on what happened at startup.What we checked about the reported case: it is not a startup ordering problem. The account service's startup pass runs synchronously before any window or terminal handler exists (
initializeReadyRuntimeServicesconstructs the account service beforeinitializeMainProcessRuntimeLaunchopens the window), and it visits the same accounts the resume path trusts, with the same ownership check. On the Codex side,app server did not become readyonly comes from Codex starting its background server, which Codex 0.157 skips when the config it loads has[features] daemon_auto_start = false, forcodex resumeas for a plaincodex. So the account home really had no guard when those panes resumed. The code shows how that can happen, though not which way it happened on that machine: the startup pass runs once and is never repeated, it skips a home without any log if that home'sconfig.tomlcan't be read at that moment, and it skips it with only a warning if the ownership check can't read the home. After that, a restored pane got the guard only as a side effect of hook repair, which stops early on a malformedhooks.json. The file's modified time can't settle it, because later passes rewrite the file. This PR removes the dependence: every automatic resume now applies the guard to the home it launches in, whatever happened at startup.Linked Issue
Related to #18566
Visual Proof
Live Electron QA on a separate Mac (macOS, Codex 0.157.0, isolated Orca profile, no real credentials; the account folder's server socket path was 149 bytes against macOS's 104-byte limit). Setup: a managed account that is not the selected one owns a Codex conversation, its
hooks.jsonis malformed (so hook repair stops early), itsconfig.tomlhas no guard and cannot be read while Orca starts, and the pane's worktree is opened after startup so the pane is restored then. Each build was rebuilt and relaunched, and the built main bundle was checked for the new call.Before (current main): the restored pane runs
codex resume <id>and fails withapp server did not become ready/path must be shorter than SUN_LEN; the account'sconfig.tomlstill has no guard line.After (this PR): the guard line is written into the account's
config.tomlas the pane is restored, and Codex starts its interface (here its first-run folder trust prompt, because this test account has no saved trust).Also checked: run directly (outside Orca) in a too-long account folder, Codex 0.157.0
codex resume <id>fails with SUN_LEN without the guard line and starts with it, so the guard works for resume. Without the startup miss (the account folder readable at startup), current main already resumes fine, because the startup pass guards the folder first; this PR is what covers a restored pane when that one-time pass did not.Testing
New
src/main/startup/codex-session-resume-daemon-guard.test.ts: it runs real resume launch prep against a real temp account home whose socket path is too long. It checks that the guard lands when hook repair throws (hooks on) and when it returns early (hooks off). It also checks that a resume moved onto the real Codex home never writes the guard there.Ablation: with only the guard call removed, both guard cases fail (
expected 'model = "gpt-5"\n' to contain 'daemon_auto_start = false # orca: …'). With the real-home skip removed instead, the real-home case fails. Each test fails only for the line it pins.vitest run --config config/vitest.config.ts src/main/codex src/main/codex-accounts src/main/startup src/main/ipc/pty: 3643 passed. The only failures are timeouts inbrowser-process-user-agent-ordering.test.ts, which also fail with the production change reverted (the number that time out varies with machine load).oxlinton changed files andcheck:code-quality:changedpass.Platforms: logic is platform-neutral. SSH and WSL resumes do not take this path (
prepareCodexSessionResumeForLaunchreturns early for WSL, andprepareCodexResumeHomefor remote connections).I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
The guard never writes to the user's real Codex home: that home is skipped explicitly, and the guard strips itself on short paths anyway. Performance cost is one config read and one realpath per automatic resume, with no write when the guard is already in place.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)