Skip to content

fix(daemon): gate agent startup cwd after safe default fallback - #10035

Merged
nwparker merged 1 commit into
stablyai:mainfrom
innocarpe:fix/daemon-agent-startup-cwd-fallback
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
innocarpe:fix/daemon-agent-startup-cwd-fallback

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

fix(daemon): gate agent startup cwd after safe default fallback

Summary

Launching a recognized agent (e.g. OpenCode) through the daemon PTY path with no explicit workspace cwd no longer fails with "Automatic agent startup command … requires a non-root workspace working directory."

ELI5

Orca can auto-start coding agents in a terminal, and refuses to do so at the filesystem root because that's unsafe. When you don't pass a folder, it's supposed to fall back to your home directory first and then check safety — but the background daemon checked safety first, so "no folder" was mistaken for "root" and got rejected.

Root cause & fix

createPtySubprocess called assertSafeAgentStartupCwd(opts.cwd, …) before applying the opts.cwd || getDefaultCwd() fallback. An omitted/undefined cwd is treated as root-like, so the guard threw even though the post-fallback default (safe HOME/USERPROFILE) would pass. The fix computes requestedCwd = opts.cwd || getDefaultCwd() first and validates that effective cwd — matching the order the in-process LocalPtyProvider already uses. Explicit root (cwd: '/') still rejects agent auto-start.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.

  • pty-subprocess.test.ts passes on branch: Test Files 1 passed, Tests 109 passed.
  • New regression test: "falls back to the safe default cwd for daemon agent startup without an explicit cwd".
  • Reverting the fix (git checkout origin/main -- pty-subprocess.ts) while keeping the test makes it fail, proving the test captures the bug:
1 failed: "falls back to the safe default cwd for daemon agent startup without an explicit cwd"
AssertionError: expected [Function] to not throw an error but
'Error: Automatic agent startup command "opencode" requires a non-root
 workspace working directory.' was thrown
  • Lint clean: npx oxlint src/main/daemon/pty-subprocess.ts → no warnings/errors.
  • Rebase clean onto origin/main; changed files: src/main/daemon/pty-subprocess.ts (fix), src/main/daemon/pty-subprocess.test.ts (test).

Trade-offs

None — pure fix. Omitted-cwd agent startup now succeeds only when the default home is safe; explicit root-like paths still throw and plain shells at root are unchanged.

Regression risk

Effectively zero. The change only reorders fallback and guard so the daemon path validates the same effective cwd the in-process LocalPtyProvider already does; root rejection remains intact and is covered by the retained test. The one flipped test expectation previously encoded the bug itself.


Credit to original author @innocarpe (Wooseong Kim). Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Daemon agent startup now resolves an omitted cwd through getDefaultCwd() before safety validation and process spawning. The POSIX/Linux test sets HOME to /home/testuser, verifies startup does not throw, and asserts that the spawned process receives /home/testuser as its working directory.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix well, but it omits several required template sections like Screenshots, Testing, AI Review Report, Security Audit, and Notes. Add the missing template sections, including testing results, screenshots or 'No visual change', an AI review report, a security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 matches the core fix: daemon agent startup now validates after falling back to a safe cwd.

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.

createPtySubprocess asserted assertSafeAgentStartupCwd on the raw
opts.cwd before applying opts.cwd || getDefaultCwd(). An omitted cwd
was treated as root-like and threw even though the post-fallback home
default is safe — while LocalPtyProvider already gates the effective
cwd after fallback.

Compute requestedCwd first, then gate. Update the daemon unit test to
assert omitted-cwd agent launch uses the safe default (stablyai#9578).
@nwparker
nwparker force-pushed the fix/daemon-agent-startup-cwd-fallback branch from b02027d to f2134eb Compare July 23, 2026 11:49
@nwparker
nwparker merged commit 559f04d into stablyai:main Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much @innocarpe — verified the daemon now gates the agent-startup cwd on the effective cwd (matching LocalPtyProvider), and an explicit '/' still correctly throws. Proven + merged. 🙏

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…lyai#10035)

createPtySubprocess asserted assertSafeAgentStartupCwd on the raw
opts.cwd before applying opts.cwd || getDefaultCwd(). An omitted cwd
was treated as root-like and threw even though the post-fallback home
default is safe — while LocalPtyProvider already gates the effective
cwd after fallback.

Compute requestedCwd first, then gate. Update the daemon unit test to
assert omitted-cwd agent launch uses the safe default (stablyai#9578).
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.

2 participants