Skip to content

fix(codex): Codex 0.157+ starts in Orca-managed homes instead of failing with SUN_LEN - #22878

Merged
brennanb2025 merged 7 commits into
mainfrom
fix/scan24-mac-codex-socket-sun-len
Sep 25, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
fix/scan24-mac-codex-socket-sun-len

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​407 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​403
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​317 $\color{#cf222e}{\Huge{\mathbf{−}}}$​87 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​230

ELI5

Newer Codex (0.157 and later) starts a helper program in the background and talks to it through a special file called a socket. The operating system limits how long a socket's path can be: 104 bytes on macOS, 108 on Linux. Orca keeps each Codex account in a deeply nested folder, so that socket path ends up around 145 bytes and Codex fails with "path must be shorter than SUN_LEN". This PR tells Codex not to start the background helper, but only in folders whose path is too long. Codex then runs the way it did before 0.157. No account data is moved.

What Changed

Before: on macOS, typing codex (0.157+) in an Orca terminal that uses a managed Codex account, or Orca's own runtime home, fails right away:
Error: app server did not become ready on …/home/app-server-control/app-server-control.sock … path must be shorter than SUN_LEN.

After: Codex starts normally (banner and sign-in screen) in those homes.

Mechanism:

  • New src/main/codex/codex-daemon-socket-path-guard.ts measures realpath(home) + /app-server-control/app-server-control.sock in bytes. Codex canonicalizes CODEX_HOME, so the real path is what counts. It compares that length with the sun_path size of the host that runs Codex. The sun_path sizes now live in src/shared/unix-socket-path-limit.ts and are reused by relay-socket-path-limit.ts.
  • When the path is too long, the guard adds daemon_auto_start = false # orca: … under [features] in that home's mirrored config.toml. It merges into an existing [features] table without disturbing its bytes, using the table upsert that previously handled only [tui] and is now generic.
  • The guard runs from every place that writes a mirrored config: managed and per-account homes, the legacy shared home, and WSL homes (measured with Linux limits on the distro path). It also covers the case where the user has no ~/.codex/config.toml: Orca then has nothing to mirror, but it still adds the guard to every host managed account home at startup and when accounts are added or switched, so resuming a session or typing codex in an account home that was not freshly launched also works. WSL account homes are guarded when a terminal launches into them instead, because checking a WSL home's ownership is a blocking wsl.exe call that must not run before the window opens. It still lands when the settings write-back or mirror stalls (for example an unreadable baseline or a failed write to ~/.codex), because a stalled settings sync must not also stop Codex from starting.
  • The marked line is Orca-owned. It is stripped before settings are promoted back into ~/.codex/config.toml, so the user's real config never gets it. getCodexConfigSyncStatus treats a runtime config that holds only this override as "synced", so no false "missing ~/.codex/config.toml" warning appears.
  • If the user's config defines features inline or as an array, so the key can't be placed, Orca logs one warning per home.

Why

Codex (0.157 through 0.158.0-alpha.9) turns daemon_auto_start on by default. The daemon server binds a short /tmp/codex-daemon-<uid>/<hash> path, but the client connects through the long <CODEX_HOME>/app-server-control/… symlink, and the sockaddr_un length check rejects that path before connect() runs. On macOS the ceiling is a 60-byte canonical CODEX_HOME (64 on Linux). Orca's homes are well over it for every username.

Alternatives considered and rejected:

  • Moving homes to a short path would break existing account data and sessions.
  • A short symlink alias for CODEX_HOME was tried and still fails, because Codex canonicalizes the path.
  • Injecting --no-daemon or -c into launch commands does not help when the user types codex into a terminal themselves.

The config key is the one lever that covers every entry point. We will also report the client-side path issue to Codex upstream.

Linked Issue

No GitHub issue. Crash report from the Help menu, listed below.

Crash reports

Report Version / OS Diagnosis
F0C4J4H6CAV Orca 1.4.211, macOS 27 Codex 0.157 TUI fails with path must be shorter than SUN_LEN on …/orca/codex-accounts/<uuid>/home/app-server-control/app-server-control.sock (about 145 bytes, over the 104-byte macOS limit). Reproduced.

Fix evidence

Repro (before), macOS arm64, Codex 0.157.0 installed with npm into /tmp, using a throwaway home shaped like the real one (/tmp/orca-sunlen-repro/Library/Application Support/orca/codex-accounts/<uuid>/home, 155-byte socket path):

  • The interactive codex TUI prints the user's exact error: Installing daemon from CLI version 0.157.0 … Error: app server did not become ready on …/app-server-control.sock … failed to connect to …/app-server-control.sock: path must be shorter than SUN_LEN.
  • codex app-server daemon start fails the same way on 0.156.1, 0.157.0 and 0.158.0-alpha.9, so it is not fixed upstream.
  • The limit is exact: a 60-byte canonical CODEX_HOME gives {"status":"started"}, and 61 bytes gives path must be shorter than SUN_LEN.
  • A symlink alias (CODEX_HOME=/tmp/cxalias) still fails, because Codex canonicalizes the path.

After, with the same long home: adding [features]\ndaemon_auto_start = false to the home's config.toml (the exact key this PR writes) brings the 0.157 TUI up normally, with the banner and sign-in screen and no daemon error. codex features list on 0.157 shows daemon_auto_start stable true, which confirms it is the default that changed.

Tests fail on the old code and pass with the fix. With only the changed source files reverted, pnpm test src/main/codex/codex-daemon-socket-path-guard.test.ts gives 3 failed | 15 passed:

  • still guards a long home when the user has no ~/.codex/config.toml: expected 'stalled' to be 'synced'
  • keeps the guard in the legacy shared home: expected 'model = "gpt-5"\n' to contain 'daemon_auto_start = false # orca: …'
  • warns once … inline features: expected "warn" to be called 1 times, but got 0 times

With the fix: 18 passed (18). A later test covers the stalled-sync path: with that path's guard call removed it fails, and with it the suite gives 19 passed (19). The guard suite also covers the length gate just under and just over the limit, darwin vs linux, multibyte usernames, merging into an existing [features] table, idempotence, and stripping before promotion.

Wider run: pnpm test src/main/codex src/main/codex-accounts src/main/ipc gives Test Files 626 passed | 4 skipped, Tests 6250 passed | 23 skipped. pnpm tc exits 0, oxlint is clean, and pnpm run check:code-quality:changed reports 0 new finding(s) across 30 changed file(s).

Visual Proof

N/A. There is no UI change. The fix changes the content of Codex's config file. The before/after terminal output is in "Fix evidence" above.

Testing

  • I manually tested these changes locally (macOS arm64: Codex 0.157 TUI in a long home, before and after the daemon_auto_start = false key)
  • Automated tests added/updated (codex-daemon-socket-path-guard.test.ts, 19 tests; codex-accounts/codex-config-mirror.test.ts, 3 tests: two fail without the account-home fix, one fails if a WSL home runs its blocking ownership check). Nine existing suites mock the guard to the identity function, so their exact byte comparisons don't depend on the length of the host's temp path.

Platforms: macOS tested for real. Linux is covered by unit tests of the length gate. Windows: the test machine has Codex 0.155 from npm, which cannot run the daemon, so this is unverified there. The guard uses the same 108-byte AF_UNIX limit, and Codex strips the \\?\ prefix from the canonical path (normalize_windows_device_path), so the measurement matches what Codex builds. SSH remotes use the host's own short ~/.codex, so they are not affected.

Trade-offs

  • The Codex background daemon is off in long homes. That covers nearly every managed or per-account home on macOS, Linux and Windows. Those sessions run in-process, so codex agents and daemon-backed resume or continuation are not available there. This is how every Codex version before 0.157 behaved. Before this fix, in those homes the TUI did not start at all.
  • Legacy shared-home refresh now writes. It can write when ~/.codex/config.toml is blank or missing, but it writes only the guard line, and only into a long home. A fresh mirror that comes out empty no longer writes a 0-byte file.
  • The stall check sees a guard-only runtime config as "synced". That is correct, because no user settings are being held back.
  • The "could not guard" warning uses a heuristic regex. It is logged once per home per process. Only the diagnostic log line is affected.

Adversarial review

4 loops.

  1. Not clean. The mechanism was confirmed against the upstream Codex source. Five findings: a false "missing ~/.codex/config.toml" warning for users with no source config (medium); the legacy shared-home refresh dropping the guard (low); the Windows \\?\ prefix not being counted (low, rebutted with Codex's normalize_windows_device_path and its test); inline features blocking the guard silently (low); and TUI-specific names in the generic upsert (low). All valid ones are fixed, with tests.
  2. Clean. No medium-or-higher issues. All round-1 fixes were verified. Leak, idempotence, WSL, SSH and folder-workspace checks passed. The remaining items are low-severity notes that affect only the log line or are theoretical, plus the trade-off listed above.
  3. One fix. An independent architecture review found that managed account homes were skipped entirely when ~/.codex/config.toml did not exist, so a resumed session or a codex typed in a non-selected account home could still fail. Those passes now add the guard alone. Two reset-credit tests were adjusted so their "touches nothing" checks cover the retry, not service startup.
  4. One fix. That startup pass ran the WSL ownership check, a blocking wsl.exe call per account, before the window opened for Windows users with WSL accounts and no WSL-side ~/.codex/config.toml. The pass now skips WSL homes, which WSL launch prep already guards.

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

  • No remote wire change. Nothing on mobile is affected. The user's real ~/.codex/config.toml is never modified. Re-applying the guard is idempotent, so repeat launches don't rewrite the file.

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)

m4air added 2 commits September 25, 2026 07:24
…th exceeds sun_path

Codex >= 0.157 auto-starts a background app-server daemon and connects to
<CODEX_HOME>/app-server-control/app-server-control.sock. Orca's managed homes
under userData make that path longer than sun_path (104 bytes on macOS, 108 on
Linux/Windows), so every interactive codex in an Orca terminal failed with
'path must be shorter than SUN_LEN'. The config mirror now writes a marked
[features] daemon_auto_start = false into only those homes, removes it when the
home fits, and never promotes it into ~/.codex.
- A runtime config.toml holding only Orca's daemon override no longer reads as a
  config-sync stall, so users without ~/.codex/config.toml get no false
  "missing" warning in the accounts pane.
- The legacy shared-home refresh re-applies the guard, so retained pre-rollout
  panes keep daemon auto-start off after a system-default launch.
- Warn once when an inline `features = {...}` or `[[features]]` blocks the
  override instead of failing silently.
- Rename the upsert's TUI-specific internals now that it serves any table.
@coderabbitai

coderabbitai Bot commented Sep 25, 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

The change adds platform-aware Codex daemon socket-path checks and applies a marked feature override when a path exceeds its platform limit. Config mirroring applies the guard to legacy and managed runtime configs. Sync-status and ordinary-settings handling recognize or remove the override. The TOML settings updater now supports arbitrary single-segment tables, and SSH relay code uses the shared Unix socket limit helper.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 2e505

A managed WSL home with a long path may still fail to start Codex if system-home discovery fails. Cover that fallback before merging.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 2e505

No new security exposure was established. The main remaining uncertainty is whether WSL launch preparation applies the socket-path guard when there is no readable source configuration.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed configuration path acts on selected managed Codex homes. The examined WSL bypass does not provide a write route to an unasserted home.

Trust Boundaries and Controls

  • observed — For paths that synchronize canonical config, the expected account's managed-home assertion precedes the configuration write. For a WSL UNC path with no canonical config, the changed path neither asserts nor writes.

Resilience and Maintainability Implications

  • observed — The guard helper does not treat an indeterminate runtime-config observation as absence, and catches and logs guard-application errors.

Hardening Proposals

  • proposed — Verify that WSL launch preparation applies the guard to the home actually launched when source config is missing or unreadable, including retry after an interrupted launch.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 22 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the Codex version issue and the SUN_LEN startup failure fix.
Description check ✅ Passed The description is detailed and covers the required explanation, mechanism, rationale, testing, platform impact, trade-offs, and checklist. The Linked Issue section does not provide a GitHub issue, an…
  • 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: 33ab8178-7b66-40b0-bf4a-bf7df03445f8

📥 Commits

Reviewing files that changed from the base of the PR and between 646e9a5 and 8625d5a.

📒 Files selected for processing (20)
  • config/tsconfig.cli.json
  • src/main/codex-accounts/legacy-shared-config-compatibility.test.ts
  • src/main/codex-accounts/runtime-home-managed-auth-recovery.test.ts
  • src/main/codex-accounts/runtime-home-real-home-lane-routing.test.ts
  • src/main/codex-accounts/runtime-home-retained-auth-provenance.test.ts
  • src/main/codex-accounts/runtime-home-system-resource-materialization.test.ts
  • src/main/codex-accounts/service-account-add-login.test.ts
  • src/main/codex-accounts/service-wsl-accounts.test.ts
  • src/main/codex-accounts/service.test.ts
  • src/main/codex/codex-config-mirror.test.ts
  • src/main/codex/codex-config-mirror.ts
  • src/main/codex/codex-config-settings-upsert.ts
  • src/main/codex/codex-daemon-socket-path-guard.test.ts
  • src/main/codex/codex-daemon-socket-path-guard.ts
  • src/main/codex/config-settings-promotion.test.ts
  • src/main/codex/config-sync-stall.test.ts
  • src/main/codex/config-sync-stall.ts
  • src/main/codex/config-toml-runtime-owned-sections.ts
  • src/main/ssh/relay-socket-path-limit.ts
  • src/shared/unix-socket-path-limit.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment on lines +53 to +82
const unguardableHomesWarned = new Set<string>()

/** Applies (or removes) Orca's daemon override so it tracks the home's current path. */
export function applyCodexDaemonSocketGuard(
config: string,
homePath: string,
platform = process.platform
): string {
if (!codexDaemonSocketPathExceedsLimit(homePath, platform)) {
return stripCodexDaemonOverride(config)
}
// Why: upsert rewrites an existing daemon_auto_start line in place, so re-applying is a no-op.
const guarded = upsertTableSettingsInContent(
config,
'features',
new Map([['daemon_auto_start', DAEMON_OVERRIDE_RAW]])
)
if (
!guarded.includes(CODEX_DAEMON_OVERRIDE_MARKER) &&
!/\bdaemon_auto_start\s*=\s*false\b/.test(guarded) &&
!unguardableHomesWarned.has(homePath)
) {
// Why: an inline `features = {...}` or `[[features]]` blocks the upsert; say so once instead of failing silently.
unguardableHomesWarned.add(homePath)
console.warn(
`[codex-config] Could not turn off Codex daemon auto-start in ${homePath}: its config defines features in a form Orca cannot extend. Codex may fail with "path must be shorter than SUN_LEN"; add daemon_auto_start = false to features in ~/.codex/config.toml.`
)
}
return guarded
}

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '45,145p' src/main/codex/codex-daemon-socket-path-guard.ts
sed -n '125,230p' src/main/codex/codex-config-mirror.ts
sed -n '120,180p' src/main/codex/config-toml-runtime-owned-sections.ts

Repository: stablyai/orca

Length of output: 10937


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- guard declarations and imports ---'
sed -n '1,110p' src/main/codex/codex-daemon-socket-path-guard.ts
printf '%s\n' '--- bound helper definitions ---'
rg -n -C 8 "function upsertTableSettingsInContent|export function upsertTableSettingsInContent|DAEMON_OVERRIDE_RAW|preserveRuntimeConflictValues|extractOrdinaryCodexSettings|syncSystemConfigIntoManagedCodexHomeUnsafe" src/main
printf '%s\n' '--- focused usages ---'
rg -n -C 6 "extractOrdinaryCodexSettings|preserveRuntimeConflictValues|daemon_auto_start|applyCodexDaemonSocketGuard" src test tests 2>/dev/null || true

Repository: stablyai/orca

Length of output: 41921


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings

Length of output: 37122


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- upsert helper ---'
sed -n '1,240p' src/main/codex/codex-config-settings-upsert.ts
printf '%s\n' '--- preservation helper ---'
cat -n src/main/codex/codex-config-settings-preservation.ts
printf '%s\n' '--- promotion flow ---'
sed -n '1,280p' src/main/codex/config-settings-promotion.ts
printf '%s\n' '--- mirror entrypoints and promotion callers ---'
rg -n -C 12 "promoteCodexRuntimeSettingsToSystem|syncSystemConfigIntoLegacySharedCodexHome|syncSystemConfigIntoManagedCodexHome|planCodexSettingsPromotion|runtimeValuesToPreserve" src/main/codex
printf '%s\n' '--- daemon-related tests beyond initial excerpt ---'
sed -n '130,360p' src/main/codex/codex-daemon-socket-path-guard.test.ts

Repository: stablyai/orca

Length of output: 45649


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- mirror merge and entrypoints ---'
rg -n "function mergeSystemCodexConfigIntoRuntime|export function mergeSystemCodexConfigIntoRuntime|syncSystemConfigIntoLegacySharedCodexHome|syncSystemConfigIntoManagedCodexHome|function prepareSystemConfigFor" src/main/codex/codex-config-mirror.ts
sed -n '1,170p' src/main/codex/codex-config-mirror.ts
sed -n '230,430p' src/main/codex/codex-config-mirror.ts
printf '%s\n' '--- promoted keys and value readers ---'
rg -n -C 8 "PROMOTED_STRUCTURED_KEYS|readPromotedSettingValues|features" src/main/codex/config-toml-promoted-setting-values.ts
printf '%s\n' '--- focused base-to-head diff ---'
git diff --unified=30 646e9a5b02514795af5139961ccca225dfa01b12 8625d5aba3b5e7f43389b4b14a919daebe1f7ed9 -- src/main/codex/codex-daemon-socket-path-guard.ts src/main/codex/codex-config-mirror.ts src/main/codex/config-toml-runtime-owned-sections.ts src/main/codex/codex-daemon-socket-path-guard.test.ts

Repository: stablyai/orca

Length of output: 44621


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- numbered decisive source ranges ---'
nl -ba src/main/codex/codex-config-mirror.ts | sed -n '105,155p;164,225p;238,285p'
nl -ba src/main/codex/config-settings-promotion.ts | sed -n '175,225p;265,330p'
nl -ba src/main/codex/config-toml-promoted-setting-values.ts | sed -n '1,42p;90,125p'
nl -ba src/main/codex/config-toml-runtime-owned-sections.ts | sed -n '154,170p'
nl -ba src/main/codex/codex-daemon-socket-path-guard.ts | sed -n '15,82p;84,145p'

Repository: stablyai/orca

Length of output: 22708


Preserve the original daemon_auto_start value when removing the override.

When features.daemon_auto_start = true exists, applyCodexDaemonSocketGuard replaces it with the marked false line. A later short-home guard removes that marked line, but it cannot restore true.

This loss can occur when the managed or legacy mirror receives a blank or missing system config, because those branches apply the guard without merging the system config. Promotion also cannot recover the value because daemon_auto_start is not a promoted setting, and extractOrdinaryCodexSettings removes the marked line when it seeds a missing system config.

Preserve the replaced boolean value in the Orca override metadata, and restore it when stripCodexDaemonOverride removes the override. Keep deleting the table only when Orca inserted the override for a previously absent setting. Add coverage for existing true values through short-home cleanup, blank-source mirroring, and promotion seeding.

@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 — initial review of the Codex daemon socket guard and the mirror/promotion plumbing it needs, across all 20 changed files.

  • Daemon socket path guard (src/main/codex/codex-daemon-socket-path-guard.ts) — measures realpath(home) + /app-server-control/app-server-control.sock in UTF-8 bytes against the host sun_path budget, then adds or removes the Orca-owned daemon_auto_start = false line under [features]; WSL homes are measured by their Linux path against the Linux limit, and inline/array features warns once instead of failing silently.
  • Shared sun_path budget (src/shared/unix-socket-path-limit.ts) — extracts the per-OS 104/108 constant and reuses it in the SSH relay path limit, preserving that path's prior behavior.
  • Generic table upsert (src/main/codex/codex-config-settings-upsert.ts) — generalizes the existing [tui] placement rule to any single-segment table so the guard can target [features]; upsertTuiSettingsInContent now delegates to it.
  • Mirror integration (src/main/codex/codex-config-mirror.ts) — applies the guard on every config write: fresh mirror, merge path, the previously no-op empty-source branch, and the legacy shared home (whose early return for a blank source was removed).
  • Sync status and promotion (config-sync-stall.ts, config-toml-runtime-owned-sections.ts) — a guard-only runtime config reads as synced (no user settings withheld), and the marked line is stripped before settings are seeded into ~/.codex, so it never reaches the user's real config.
  • Tests — a new 18-case guard suite with exact byte/limit boundaries and round-trips, plus identity mocks in 11 existing suites so their byte assertions stay host-independent.

ℹ️ The guard has no exit path once Codex fixes the upstream socket path

The override is keyed only on the home's path length, so there is no condition under which it stops being written — not a Codex version floor, not an upstream-fix check. When Codex eventually fixes the client-side socket path (the PR says it will be reported upstream), Orca will keep turning the daemon off in every long managed home until this code is removed, so daemon-backed codex agents/resume stays unavailable there longer than the bug requires. Not a blocker for this fix, just worth a tracked follow-up.

Technical details
# Daemon guard outlives the upstream bug

## Affected sites
- `src/main/codex/codex-daemon-socket-path-guard.ts:61` — the only gate is `codexDaemonSocketPathExceedsLimit`; there is no Codex-version or expiry condition.
- `src/main/codex/codex-daemon-socket-path-guard.ts:15-20` — the JSDoc frames the override as scoped to Codex >= 0.157, but the code never checks the installed version.

## Required outcome
- A tracked follow-up (issue or in-code TODO) that removes the guard once the supported Codex range no longer needs it, so the capability loss does not outlive the bug.

## Open questions for the human
- Is there a Codex version floor below which Orca must keep the guard? If so, gating on that version would let a fixed Codex keep the daemon enabled in long homes.

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

…or stalls

When the settings write-back or mirror refused (unreadable baseline, failed
write to ~/.codex, unreadable source), the whole pass returned before the
daemon guard was applied. A home whose config.toml predates the guard then
kept failing with SUN_LEN on every launch for as long as the stall lasted.
The guard now lands on those paths too; the mirror itself is unchanged.

@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 — the delta since the prior pullfrog review (8625d5a): one commit that makes the daemon socket guard land even when the settings mirror stalls, plus the regression test that pins it.

  • Guard survives a stalled mirror (src/main/codex/codex-config-mirror.ts) — syncSystemConfigIntoManagedCodexHome now delegates to a boolean-returning mirrorSystemConfigIntoManagedCodexHome and calls ensureCodexDaemonSocketGuard whenever it returns false. That covers the write-back refusal, a mirror throw, and refused-indeterminate, which previously returned before the guard — so a long home whose settings sync stalled could still fail to start Codex. The true paths (skipped-missing-source, mirrored) already applied the guard inside the unsafe mirror, so there is no double-write.
  • Extracted writeCodexDaemonSocketGuard — the managed blank-source branch shares the same guarded compare-and-swap helper instead of duplicating it inline.
  • Regression test (codex-daemon-socket-path-guard.test.ts) — forces an unreadable baseline so promotion refuses, then asserts the runtime config gains the override while ~/.codex/config.toml is untouched. It genuinely exercises the new wrapper path: the guard cannot be written anywhere else once promotion has returned null.

Verified locally: pnpm test src/main/codex/codex-daemon-socket-path-guard.test.ts src/main/codex/codex-config-mirror.test.ts → 53 passed (19 + 34). I also traced the promotion/baseline state machine: the override is not a promoted key and is stripped before seeding ~/.codex, so applying it on the stall path cannot be stranded or leaked, and isOnlyCodexDaemonOverride still reports guard-only configs as synced.

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

…d pass

Guarding account homes with no ~/.codex/config.toml ran the WSL ownership
check, a synchronous wsl.exe call per account, at startup before the window
opens and on every account switch. WSL homes are guarded by WSL launch prep,
so that pass now covers host homes only.

@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 — the delta since the prior pullfrog review (e2c8dd9): three commits that close the last account-home gap in the daemon guard and re-scope two tests.

  • Guard-only pass for managed account homes with no source config (src/main/codex-accounts/codex-config-mirror.ts) — syncIntoManagedHome now asserts the home path first and, when ~/.codex/config.toml is absent, calls the newly exported ensureCodexDaemonSocketGuard instead of returning. A resumed session or a codex typed in a non-selected account home now gets the override even though there was nothing to mirror.
  • Exported ensureCodexDaemonSocketGuard (src/main/codex/codex-config-mirror.ts) — the previously-private stall-path helper is shared with the account mirror, and the constructor's store parameter is narrowed to Pick<Store, 'getSettings'> to match actual usage.
  • New regression test (src/main/codex-accounts/codex-config-mirror.test.ts) — covers both safeSyncToManagedHomes and safeSyncIntoManagedHome with a missing ~/.codex/config.toml, asserting the exact [features] bytes land in a long home without creating a real ~/.codex. It genuinely fails without the source change (the config read would ENOENT).
  • Reset-credit test re-scoping (service-reset-credit-home-ownership.test.ts) — service construction now happens before the fault is held/reset, so the ownership-read assertions measure the retry, not construction-time mirror IO.

Verified locally: pnpm test on the changed suites → 26 passed; pnpm tc:node exits 0; pnpm test src/main/codex src/main/codex-accounts → 196 files passed with one unrelated process-teardown integration failure (codex-app-server-teardown.integration.test.ts) that this PR does not touch.

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

@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 — the delta since the prior pullfrog review (20d7d59): one commit that keeps the startup guard-only pass from running WSL ownership checks before the window opens, plus the regression test that pins it.

  • WSL homes skip the startup guard-only pass (src/main/codex-accounts/codex-config-mirror.ts) — syncIntoManagedHome now checks a missing source config before asserting the home path, and applies the guard only to non-WSL homes in that branch. WSL homes run Linux Codex and their ownership check is a blocking wsl.exe call; WSL launch prep already applies the guard to any home a terminal launches into (syncWslConfigAndGlobalInstructionsForLaunch → syncSystemConfigIntoManagedCodexHome), so the skip costs no coverage there and avoids reintroducing the pre-window stall the previous commit risked.
  • Regression test (codex-accounts/codex-config-mirror.test.ts) — asserts the injected ownership assert is never called for a WSL UNC home with a missing ~/.codex/config.toml. I confirmed it is not theatre: reverting the source locally makes it fail (expected "vi.fn()" to not be called at all, but actually been called 1 times), and it passes with the change.

Verified locally: pnpm test src/main/codex-accounts/codex-config-mirror.test.ts src/main/codex/codex-daemon-socket-path-guard.test.ts → 22 passed.

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

@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: 9a505dcc-9b19-4f96-b84d-e1c045cf29bf

📥 Commits

Reviewing files that changed from the base of the PR and between 20d7d59 and 2e505eb.

📒 Files selected for processing (2)
  • src/main/codex-accounts/codex-config-mirror.test.ts
  • src/main/codex-accounts/codex-config-mirror.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Comment on lines +112 to +116
// Why: with no ~/.codex/config.toml there is nothing to mirror, but Codex still cannot start in a long home without the daemon guard.
// WSL homes are skipped: their ownership check is a blocking wsl.exe call (startup, account switch), and WSL launch prep guards the home it launches.
if (!parseWslUncPath(managedHomePath)) {
ensureCodexDaemonSocketGuard(this.assertManagedHomePath(managedHomePath, expectedAccountId))
}

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

rg -n 'ensureCodexDaemonSocketGuard|safeSyncIntoManagedHome|syncIntoManagedHome|applyCodexDaemonSocketGuard' src/main/codex-accounts src/main/codex
sed -n '90,145p' src/main/codex-accounts/codex-config-mirror.ts

Repository: stablyai/orca

Length of output: 7862


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- candidate files ---'
git ls-files 'src/main/codex-accounts' 'src/main/codex' | rg '(service|runtime-home|wsl|config-mirror|socket-path|launch|codex)' | head -120
printf '%s\n' '--- outlines ---'
ast-grep outline src/main/codex-accounts/codex-config-mirror.ts
ast-grep outline src/main/codex/codex-config-mirror.ts
printf '%s\n' '--- account mirror and codex guard ---'
cat -n src/main/codex-accounts/codex-config-mirror.ts | sed -n '1,145p'
cat -n src/main/codex/codex-config-mirror.ts | sed -n '1,280p'
printf '%s\n' '--- WSL and launch references ---'
rg -n -C 5 'parseWslUncPath|wsl\.exe|WSL|launch|runtimeHomePath|ensureCodexDaemonSocketGuard|Codex.*start|start.*Codex' src/main/codex-accounts src/main/codex -g '*.ts'

Repository: stablyai/orca

Length of output: 45654


🏁 Script executed:

#!/bin/bash
set -eu
for f in \
  src/main/codex-accounts/runtime-home-service-launch.ts \
  src/main/codex-accounts/runtime-home-service-wsl-core.ts \
  src/main/codex-accounts/runtime-home-service-wsl.ts \
  src/main/codex-accounts/runtime-home-service.ts \
  src/main/codex-accounts/wsl-codex-command.ts \
  src/main/codex-accounts/codex-account-registration.ts \
  src/main/codex-accounts/service.ts \
  src/main/codex/codex-daemon-socket-path-guard.ts \
  src/shared/wsl-paths.ts
do
  if [ -f "$f" ]; then
    printf '\n--- %s ---\n' "$f"
    wc -l "$f"
    rg -n -C 4 'launch|prepare|wsl|WSL|runtimeHome|config\.toml|socket|guard|Codex|command|exec|spawn' "$f" || true
  fi
done
printf '\n--- cross-file call sites ---\n'
rg -n -C 3 'runtime-home-service-launch|prepare.*Wsl|prepare.*WSL|launch.*Wsl|launch.*WSL|ensureCodexDaemonSocketGuard|wsl-codex-command|safeSyncIntoManagedHome' src/main src/shared -g '*.ts'

Repository: stablyai/orca

Length of output: 42374


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- finishWslLaunchPreparation ---'
rg -n -C 12 'finishWslLaunchPreparation' src/main/codex-accounts
printf '%s\n' '--- WSL shell preflight files ---'
git ls-files src/main/codex src/main/runtime/rpc/methods | rg 'managed-wsl|agent-hooks'
for f in \
  src/main/codex/managed-wsl-home-shell-preflight.ts \
  src/main/runtime/rpc/methods/agent-hooks.ts \
  src/main/providers/local-pty-windows-spawn-environment.ts
do
  if [ -f "$f" ]; then
    printf '\n--- %s ---\n' "$f"
    cat -n "$f" | sed -n '1,260p'
  fi
done
printf '%s\n' '--- guard implementation and focused tests ---'
cat -n src/main/codex/codex-daemon-socket-path-guard.ts | sed -n '1,220p'
rg -n -C 8 'long|overlong|socket|daemon_auto_start|missing|absent|config' \
  src/main/codex/codex-daemon-socket-path-guard.test.ts \
  src/main/codex-accounts/runtime-home-wsl-managed-accounts.test.ts \
  src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts \
  src/main/codex-accounts/codex-config-mirror.test.ts

Repository: stablyai/orca

Length of output: 42800


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- WSL launch sync delegation ---'
cat -n src/main/codex-accounts/runtime-home-service-home-routing.ts | sed -n '230,310p'
printf '%s\n' '--- socket guard implementation ---'
cat -n src/main/codex/codex-daemon-socket-path-guard.ts | sed -n '14,180p'
printf '%s\n' '--- mirror tests around missing source/config ---'
cat -n src/main/codex-accounts/codex-config-mirror.test.ts | sed -n '1,125p'
printf '%s\n' '--- direct launch and missing config references ---'
rg -n -C 8 'config\.toml|missing source|no source|no.*config|daemon_auto_start|socket|guard' \
  src/main/codex-accounts/runtime-home-wsl-managed-accounts.test.ts \
  src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts \
  src/main/codex-accounts/codex-config-mirror.test.ts \
  src/main/codex/codex-daemon-socket-path-guard.test.ts

Repository: stablyai/orca

Length of output: 41905


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- WSL system-home resolution ---'
rg -n -C 12 'getWslSystemCodexHomePath|joinWslPath|getWslHome' \
  src/main/codex-accounts/runtime-home-service-home-routing.ts \
  src/main/codex-accounts/runtime-home-service-wsl.ts \
  src/main/wsl.ts \
  src/main/wsl/index.ts \
  src/main/wsl/*.ts 2>/dev/null || true
printf '%s\n' '--- launch preparation callers ---'
rg -n -C 8 'prepareForCodexLaunchAsync|prepareForCodexLaunch\(' src/main src/shared -g '*.ts' \
  | head -240
printf '%s\n' '--- selected WSL account test context ---'
cat -n src/main/codex-accounts/runtime-home-wsl-managed-accounts.test.ts | sed -n '150,235p'

Repository: stablyai/orca

Length of output: 41953


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- getWslHome implementation ---'
cat -n src/main/wsl.ts | sed -n '250,330p'
printf '%s\n' '--- production launch callers ---'
rg -n -C 6 'prepareForCodexLaunchAsync|prepareForCodexLaunch' \
  src/main --glob '*.ts' --glob '!**/*.test.ts' | head -180

Repository: stablyai/orca

Length of output: 16968


Guard the selected WSL home when system-home discovery fails.

When getWslHome() returns null, WSL launch preparation returns before calling syncSystemConfigIntoManagedCodexHome. The no-canonical-config branch also skips the guard. An overlong managed WSL home with no runtime config can then start Codex without daemon_auto_start = false, which can cause the SUN_LEN socket-path startup failure.

Apply the guard in WSL launch preparation when the selected managed home has no resolvable system home.

Suggested fix
-import { syncSystemConfigIntoManagedCodexHome } from '../codex/codex-config-mirror'
+import {
+  ensureCodexDaemonSocketGuard,
+  syncSystemConfigIntoManagedCodexHome
+} from '../codex/codex-config-mirror'
...
-    if (!systemHomePath || systemHomePath === runtimeHomePath) {
+    if (!systemHomePath) {
+      ensureCodexDaemonSocketGuard(runtimeHomePath)
+      return
+    }
+    if (systemHomePath === runtimeHomePath) {
       return
     }

@brennanb2025

Copy link
Copy Markdown
Contributor

Review status: ready to merge (head 2e505eb9b4)

The PR fixes the reported crash. Typing codex (0.157+) in an Orca terminal that uses an Orca-managed Codex home no longer fails with path must be shorter than SUN_LEN. It was checked live on macOS, Linux and Windows. All 36 CI checks are green, and no documentation files were added.

Review loops

Four review loops ran. Each of the first three found and fixed a real gap:

  1. The guard was skipped when the settings sync stalled or refused (e2c8dd9dec).
  2. Account homes were never guarded when the user has no ~/.codex/config.toml. This mattered for resumed panes and for accounts that weren't selected (36fd3d1930, with test follow-ups c7a03956bb and 20d7d59bcb).
  3. Fix 2 put a blocking wsl.exe ownership check at app startup, before the window opens, once per WSL account. That pass now covers host homes only. WSL homes are still guarded when a terminal launches into them (2e505eb9b4).
  4. Clean, with no changes.

A separate architecture review agreed with keeping this as a focused fix. A follow-up could move the guard to whatever owns each Codex home's lifecycle, or move managed homes to a shorter path so the Codex daemon keeps working there.

Readiness checklist: passed at the start and at the end, with no P0 or P1 findings.

Live QA (before = origin/main, after = this PR, Codex 0.157.0)

Each platform used an isolated Orca dev profile, a fake home so the real ~/.codex was never touched, and a managed Codex account.

Platform Account-home socket path Before After
macOS 178 bytes (limit 103) SUN_LEN error Codex starts, and the guard line is in that home's config.toml
Linux 151 bytes (limit 107) SUN_LEN error Codex starts, and the guard line is written
Windows 130 bytes (limit 107) SUN_LEN error Codex starts, and the guard line is written

Also verified:

  • A home whose socket path fits under the limit gets no guard, and Codex still starts there with its daemon on. This covered Windows' 97-byte shared runtime home and short homes on macOS and Linux.
  • The user's ~/.codex/config.toml never gets the guard line, on any platform.
  • Relaunching Orca doesn't rewrite a guarded config.toml.
  • On macOS, a real Codex prompt ran to completion in a guarded account home that had mirrored provider settings.
  • Windows QA ran at 20d7d59bcb. The only later commit, 2e505eb9b4, changes behaviour only for WSL paths.

macOS, before and after:
macOS before
macOS after

Linux, before and after:
Linux before
Linux after

Windows, before and after:
Windows before
Windows after

Known trade-offs and remaining gaps

  • In a guarded home the Codex background daemon is off, so daemon-only features such as the agents overview aren't available there. Before this PR, Codex didn't start at all in those homes. Turning the daemon back on from Codex's /experimental menu gets reverted on the next sync.
  • One gap remains, and it is narrow. A WSL pane opened before this update, on an account that is no longer selected and has no WSL-side config.toml, stays unguarded until a new WSL terminal opens for that account. Closing that gap would bring back the blocking wsl.exe call at startup.
  • The Codex daemon on Windows can't detach from inside an Orca terminal (the terminal's job object blocks it). The TUI still starts in short homes, so users aren't affected, and it is unrelated to this PR.

@brennanb2025
brennanb2025 merged commit c220d92 into main Sep 25, 2026
36 checks passed
cis2042 pushed a commit to cis2042/orca that referenced this pull request Sep 26, 2026
…ing with SUN_LEN (stablyai#22878)

* fix(codex): turn off Codex daemon auto-start in homes whose socket path exceeds sun_path

Codex >= 0.157 auto-starts a background app-server daemon and connects to
<CODEX_HOME>/app-server-control/app-server-control.sock. Orca's managed homes
under userData make that path longer than sun_path (104 bytes on macOS, 108 on
Linux/Windows), so every interactive codex in an Orca terminal failed with
'path must be shorter than SUN_LEN'. The config mirror now writes a marked
[features] daemon_auto_start = false into only those homes, removes it when the
home fits, and never promotes it into ~/.codex.

* fix(codex): address review of the daemon socket guard

- A runtime config.toml holding only Orca's daemon override no longer reads as a
  config-sync stall, so users without ~/.codex/config.toml get no false
  "missing" warning in the accounts pane.
- The legacy shared-home refresh re-applies the guard, so retained pre-rollout
  panes keep daemon auto-start off after a system-default launch.
- Warn once when an inline `features = {...}` or `[[features]]` blocks the
  override instead of failing silently.
- Rename the upsert's TUI-specific internals now that it serves any table.

* fix(codex): apply the daemon socket guard even when the settings mirror stalls

When the settings write-back or mirror refused (unreadable baseline, failed
write to ~/.codex, unreadable source), the whole pass returned before the
daemon guard was applied. A home whose config.toml predates the guard then
kept failing with SUN_LEN on every launch for as long as the stall lasted.
The guard now lands on those paths too; the mirror itself is unchanged.

* fix(codex): guard managed account homes when ~/.codex/config.toml is missing

* test(codex): keep reset-credit ownership checks scoped to the retry, not service construction

* test(codex): build the account mirror test without a type cast

* fix(codex): keep blocking WSL ownership checks off the no-config guard pass

Guarding account homes with no ~/.codex/config.toml ran the WSL ownership
check, a synchronous wsl.exe call per account, at startup before the window
opens and on every account switch. WSL homes are guarded by WSL launch prep,
so that pass now covers host homes only.

---------

Co-authored-by: m4air <m4air@m4airs-Air.localdomain>
Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
(cherry picked from commit c220d92)
@thuanhuynhh

Copy link
Copy Markdown

Hello not working Error: start the Windows daemon from a non-elevated terminal; shared clients must not inherit administrator privileges
To work without the background server, rerun the same command with --no-daemon (including resume or fork and its arguments).

machamy added a commit to machamy/orca that referenced this pull request Sep 26, 2026
Upstream never bumps the version on main; releases are tagged on side
branches. machamy.14 merged main and so kept the 1.4.197 label while being
mostly newer than v1.4.212. This catches main up again (including the Codex
0.157+ SUN_LEN startup fix, stablyai#22878, the one substantive change v1.4.212 had
that main lacked) and labels the base 1.4.212.

Folder project roots count as the default workspace (upstream) while git
repos keep the fork's repo-path anchor. The Unity editor lookup reads the
Windows process table directly now that upstream removed the helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OmarHung pushed a commit to OmarHung/orca that referenced this pull request Sep 26, 2026
…ing with SUN_LEN (stablyai#22878)

* fix(codex): turn off Codex daemon auto-start in homes whose socket path exceeds sun_path

Codex >= 0.157 auto-starts a background app-server daemon and connects to
<CODEX_HOME>/app-server-control/app-server-control.sock. Orca's managed homes
under userData make that path longer than sun_path (104 bytes on macOS, 108 on
Linux/Windows), so every interactive codex in an Orca terminal failed with
'path must be shorter than SUN_LEN'. The config mirror now writes a marked
[features] daemon_auto_start = false into only those homes, removes it when the
home fits, and never promotes it into ~/.codex.

* fix(codex): address review of the daemon socket guard

- A runtime config.toml holding only Orca's daemon override no longer reads as a
  config-sync stall, so users without ~/.codex/config.toml get no false
  "missing" warning in the accounts pane.
- The legacy shared-home refresh re-applies the guard, so retained pre-rollout
  panes keep daemon auto-start off after a system-default launch.
- Warn once when an inline `features = {...}` or `[[features]]` blocks the
  override instead of failing silently.
- Rename the upsert's TUI-specific internals now that it serves any table.

* fix(codex): apply the daemon socket guard even when the settings mirror stalls

When the settings write-back or mirror refused (unreadable baseline, failed
write to ~/.codex, unreadable source), the whole pass returned before the
daemon guard was applied. A home whose config.toml predates the guard then
kept failing with SUN_LEN on every launch for as long as the stall lasted.
The guard now lands on those paths too; the mirror itself is unchanged.

* fix(codex): guard managed account homes when ~/.codex/config.toml is missing

* test(codex): keep reset-credit ownership checks scoped to the retry, not service construction

* test(codex): build the account mirror test without a type cast

* fix(codex): keep blocking WSL ownership checks off the no-config guard pass

Guarding account homes with no ~/.codex/config.toml ran the WSL ownership
check, a synchronous wsl.exe call per account, at startup before the window
opens and on every account switch. WSL homes are guarded by WSL launch prep,
so that pass now covers host homes only.

---------

Co-authored-by: m4air <m4air@m4airs-Air.localdomain>
Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
(cherry picked from commit c220d92)
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.

3 participants