Skip to content

fix(codex): restored Codex panes on a managed account resume instead of failing with SUN_LEN - #23724

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/codex-resume-daemon-guard
Sep 29, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/codex-resume-daemon-guard

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​145 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​145
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5

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 ~/.codex is 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 manual codex resume <id> --no-daemon worked.
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 existing ensureCodexDaemonSocketGuard on 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. If config.toml can'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 prepareCodexResumeHome in 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 (prepareSelfContainedManagedHomeForLaunch mirrors 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: installCodexHooksExclusively when status hooks are on, refreshCodexRuntimeUserHooksExclusively when they are off.
Hook repair returns before it reaches the mirror when the account's hooks.json is malformed, or when ~/.codex/hooks.json can't be read. It throws before the mirror if writing the hook script or hooks.json fails, 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 ~/.codex settings 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 (initializeReadyRuntimeServices constructs the account service before initializeMainProcessRuntimeLaunch opens 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 ready only comes from Codex starting its background server, which Codex 0.157 skips when the config it loads has [features] daemon_auto_start = false, for codex resume as for a plain codex. 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's config.toml can'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 malformed hooks.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.json is malformed (so hook repair stops early), its config.toml has 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 with app server did not become ready / path must be shorter than SUN_LEN; the account's config.toml still has no guard line.

Before: restored Codex pane fails with SUN_LEN

After (this PR): the guard line is written into the account's config.toml as the pane is restored, and Codex starts its interface (here its first-run folder trust prompt, because this test account has no saved trust).

After: restored Codex pane starts the Codex interface

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 in browser-process-user-agent-ordering.test.ts, which also fail with the production change reverted (the number that time out varies with machine load).

  • oxlint on changed files and check:code-quality:changed pass.

  • Platforms: logic is platform-neutral. SSH and WSL resumes do not take this path (prepareCodexSessionResumeForLaunch returns early for WSL, and prepareCodexResumeHome for remote connections).

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and 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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@brennanb2025
brennanb2025 marked this pull request as ready for review September 29, 2026 02:04
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready for review

Verdict: the change is correct and fixes the reported failure mode; no code changes were needed after review. Head b137ee5cd4c, CI fully green (typecheck, all 8 test shards, package, static analysis). Not merged.

What the user saw: after a reboot, Codex panes that Orca restored on a managed Codex account failed with app server did not become ready / path must be shorter than SUN_LEN, even on 1.4.212 (which shipped #22878).

Why: a restored pane runs codex resume in the folder of the account that owns the conversation, which is often not the selected account. Fresh launches write the "don't start the background server" setting into the selected account only. The restored pane's folder got it only from a one-time pass at startup (which silently skips a folder whose config.toml can't be read at that moment) or as a side effect of hook repair (which stops early on a malformed hooks.json). Startup ordering was checked and ruled out: the startup pass finishes before any window opens.

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 ~/.codex is never written; SSH and WSL panes don't take this path.

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):

  • Directly in a too-long folder: codex resume fails with SUN_LEN without the setting and starts with it, so the setting works for resume.
  • A restored pane whose account folder missed the startup pass: current main fails with SUN_LEN and the folder has no setting; this PR writes the setting at restore and Codex starts.
  • Without the startup miss, current main already resumes fine (the startup pass covers it), which matches the analysis.

Before: restored Codex pane fails with SUN_LEN

After: restored Codex pane starts the Codex interface

Known limits, not caused by this PR (left for follow-up):

  • We can't tell which startup skip hit the reporter's machine; the guard helper skips an unreadable config.toml without logging, so a one-line warning there would make the next report diagnosable.
  • A plain shell (not an automatic resume) opened in a non-selected account's folder still relies on the startup pass; the planned single owner for Codex home setup (or short home paths) removes that class.
  • In the test setup with a malformed hooks.json, the restored account also missed its saved folder trust and showed Codex's trust prompt; same early-return cause, same before and after this PR.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adds daemon socket guard to Codex session resume flow.

The PR appears safe to merge; no actionable issue was identified.

Summary

This PR applies the existing Codex daemon-socket guard to a verified, non-system home during automatic session resume, independently of hook repair.

  • Adds tests for hook-repair failure, early return, and the real-home exclusion.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Verify session source] --> B[Choose resume home]
  B --> C[Attempt hook repair]
  C --> D{System Codex home?}
  D -- Yes --> F[Resume Codex]
  D -- No --> E[Apply daemon socket guard]
  E --> F
Loading

Reviews (1) · Last reviewed commit: "fix(codex): guard the daemon socket in t..."

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • prepareCodexSessionResumeForLaunch now guards the home it pins — after hook repair, resolveVerifiedResumeHome calls the existing ensureCodexDaemonSocketGuard(resumeHome) for non-system homes, so a resumed managed CODEX_HOME gets [features] daemon_auto_start = false even 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

Resume launch now applies ensureCodexDaemonSocketGuard to a resumed home after hook preparation, unless that home is the system Codex home. Tests cover hook installation and refresh errors, and a migrated resume using the real Codex home.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to b137e

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 Review

Security architecture risk: 🔵 Low · up to b137e

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

  • Low · architecture · inferred: A host-targeted resume can attempt to change a managed WSL home’s persistent daemon setting before host-home compatibility rejects that home. This extends a configuration side effect across runtime ownership, although a successful write and security impact are not demonstrated.
Security review details

Security Blast Radius

  • inferred — The additional write is confined to a verified, discovered non-system account home, but that set can include a WSL-managed home. Its persistent config may affect later sessions using that account; arbitrary files, other tenants, and privilege gain are not established.

Trust Boundaries and Controls

  • observed — WSL-targeted launches return before this host preparation path, and host spawn selection rejects WSL homes. Neither control prevents the earlier guard attempt when a host-targeted resume has verified WSL-home provenance.

Resilience and Maintainability Implications

  • observed — Content comparison and guarded atomic publication limit repeated or concurrent overwrites. They do not guarantee that the daemon setting was persisted: a conflict can return false, and the caller does not check that result.

Hardening Proposals

  • proposed — Check that the verified resume home is compatible with the host runtime before mutating its configuration, rather than relying on the later spawn check.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Codex resume failure and the SUN_LEN fix. It accurately summarizes the primary change.
Description check ✅ Passed The description is complete and directly matches the implementation. It explains the user impact, mechanism, rationale, linked issue, visual evidence, testing, platform scope, and checklist status. It…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 610bba44-dd44-4feb-8a59-361184e43c99

📥 Commits

Reviewing files that changed from the base of the PR and between d0db35c and b137ee5.

📒 Files selected for processing (2)
  • src/main/startup/codex-session-resume-daemon-guard.test.ts
  • src/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.

Comment on lines +115 to +118
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)
}

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

🔎 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/main

Repository: 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.ts

Repository: 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)) {

@brennanb2025
brennanb2025 merged commit b8a7daf into main Sep 29, 2026
61 checks passed
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
Kept main's daemon socket guard on resume (#23724) beside the per-agent hooks
check; its new test mocks the per-agent predicate.
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
…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.
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
Kept #23724's daemon socket guard on resume beside the real-home wait; took
#23815's deletion of the main-thread boundary source test and its rewrite of the
trust parity test, whose export-list check this branch had edited.
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