Skip to content

Fix OMP fresh session isolation - #7712

Closed
mmarabel wants to merge 2 commits into
stablyai:mainfrom
mmarabel:fix/omp-fresh-session-isolation
Closed

mmarabel wants to merge 2 commits into
stablyai:mainfrom
mmarabel:fix/omp-fresh-session-isolation

Conversation

@mmarabel

@mmarabel mmarabel commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7710

Summary

  • Preserve Orca's one-shot fresh-session intent for promptless OMP launches by sending a concrete omp --session-dir "$ORCA_OMP_FRESH_SESSION_DIR" command instead of host-side agent: "omp" shorthand.
  • Fill ORCA_OMP_FRESH_SESSION_DIR in local, IPC, daemon-host, and paired/runtime PTY spawn paths with a stable per-worktree session directory.
  • Preserve omp launch ... dispatch when the wrapper injects --session-dir, and leave explicit user session selectors (--resume, --continue, --session-dir, --no-session, --fork) untouched.
  • Pass the fresh session dir through WSL with /p path conversion.

Screenshots

Before/after screen recording will be attached to this PR. No UI chrome change; behavior change is terminal launch/session state.

Testing

  • pnpm lint
  • pnpm typecheck via pnpm exec tsgo --noEmit -p config/tsconfig.node.json
  • pnpm test focused coverage:
    • pnpm exec vitest run --config config/vitest.config.ts src/shared/tui-agent-startup.test.ts src/main/pty/omp-shell-wrapper.node-pty.test.ts src/main/pty/omp-fresh-session-dir.test.ts src/renderer/src/lib/launch-agent-in-new-tab.web-runtime.test.ts src/main/pty/wsl-orca-env.test.ts passed in the source worktree.
    • pnpm exec vitest run --config config/vitest.config.ts src/main/pty/omp-fresh-session-dir.test.ts src/main/ipc/pty.test.ts src/main/providers/local-pty-provider.test.ts passed in the clean PR worktree.
    • POSIX wrapper smoke verified omp launch codex becomes omp launch --extension <status> --session-dir <fresh> codex.
  • pnpm build
  • Added or updated high-quality tests that would catch regressions: fresh-session dir derivation, daemon-host env wiring, resolved-cwd scoping, omp launch wrapper dispatch, renderer promptless OMP launches, WSL env propagation.

Additional checks:

  • pnpm exec oxlint src/main/pty/omp-shell-wrapper.ts src/main/providers/local-pty-provider.ts src/main/ipc/pty.ts src/main/pty/omp-fresh-session-dir.test.ts src/main/pty/omp-shell-wrapper.node-pty.test.ts src/main/ipc/pty.test.ts src/main/providers/local-pty-provider.test.ts

Note: the clean PR worktree's omp-shell-wrapper.node-pty.test.ts run fails locally because the temporary worktree's freshly installed node-pty cannot posix_spawnp bash. The same focused node-pty test file passed in the source worktree where the native runtime is valid; a non-PTY POSIX wrapper smoke also verified the CodeRabbit omp launch case in the clean worktree.

AI Review Report

AI review checked CodeRabbit feedback and the changed launch paths. Findings addressed:

  • CodeRabbit found the wrapper prepended --session-dir before preserving launch, which would route omp launch through the generic omp --extension ... path. Fixed by capturing the original subcommand before mutation and keeping launch first in both POSIX and PowerShell wrappers.
  • CodeRabbit found the daemon-host pty:spawn path skipped applyOmpFreshSessionDirEnv. Fixed by applying it after buildPtyHostEnv and before daemon spawn options are created.
  • CodeRabbit found local provider fresh-dir scoping used args.cwd, so omitted cwd could hash into unknown-worktree. Fixed to pass resolved cwd.
  • Cross-platform review covered macOS/Linux POSIX wrapper behavior, Windows PowerShell wrapper behavior, WSL path conversion via WSLENV /p, daemon/local/IPC PTY paths, and path construction through Node path.join.

Security Audit

Reviewed command construction, env propagation, path scoping, and IPC/daemon spawn surfaces.

  • Fresh-session directories are deterministic under the configured OMP source agent root and scoped by worktreeId or resolved cwd; no user-provided shell interpolation is introduced.
  • Wrapper injection only applies when ORCA_OMP_FORCE_NEW_SESSION=1 and an explicit session selector is absent, preserving user intent and avoiding overriding resume/session commands.
  • Daemon and local paths mutate cloned env objects before spawn; caller-provided env objects are not reused as mutable shared state.
  • WSL propagation imports only the fresh session dir with /p path conversion.
  • No dependencies, auth flows, or secrets changed.

Notes

  • This is a behavioral terminal/session fix, not a visual UI change.
  • Full project lint/build were not run; focused tests, touched-file lint, and node typecheck were run.
  • Before/after evidence media should stay on the PR only, not duplicated into the linked issue.

ELI5

Fresh OMP launches could reuse an old session instead of starting clean. Orca forces a stable per-worktree session directory so “new chat” is really new.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@gatsby74, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 242255c8-57f0-4451-ad15-8081dccd63e9

📥 Commits

Reviewing files that changed from the base of the PR and between 931cb03 and 6dcbf0f.

📒 Files selected for processing (17)
  • src/main/ipc/pty-daemon-spawn-agent-home-env.test.ts
  • src/main/ipc/pty.ts
  • src/main/providers/local-pty-provider-spawn-env.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/pty/omp-fresh-session-dir.test.ts
  • src/main/pty/omp-fresh-session-dir.ts
  • src/main/pty/omp-shell-wrapper.node-pty.test.ts
  • src/main/pty/omp-shell-wrapper.ts
  • src/main/pty/wsl-orca-env.test.ts
  • src/main/pty/wsl-orca-env.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.web-runtime.test.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts
  • src/shared/omp-fresh-session-env.ts
  • src/shared/tui-agent-startup-building.ts
  • src/shared/tui-agent-startup.test.ts
  • src/shared/tui-agent-startup.ts
📝 Walkthrough

Walkthrough

Changes

This PR adds OMP fresh-session directory environment handling and threads it through PTY spawning, runtime env assembly, WSL env passthrough, shell wrapper scripts, shared startup planning, and renderer launch behavior. It introduces shared env constants and a helper that derives a stable session directory from worktree scope. The OMP shell wrappers now avoid injecting a fresh session dir when session selectors already exist. Startup planning now uses shared helpers, and promptless OMP launches send concrete startup payloads. Tests were added and updated across these paths.

Sequence Diagram(s)

Diagrams are included in the hidden review stack artifact above for the env derivation, PTY/WSL wiring, wrapper injection, startup planning, and renderer launch flow.

Related PRs: None specified.

Suggested labels: review_needed_junior_swe, review_depth_standard

Suggested reviewers: None specified.

Poem

Fresh sessions bloom in paths anew,
Scoped by worktree, clean and true,
Wrappers, PTY, runtime too,
OMP now starts with skies of blue.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address #7710 by preserving fresh-session intent, adding a stable session dir, and keeping explicit session selectors intact.
Out of Scope Changes check ✅ Passed The changes remain focused on OMP fresh-session isolation and supporting launch paths, wrappers, and tests with no obvious unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise and clearly matches the PR’s main change: OMP fresh-session isolation.
Description check ✅ Passed The description follows the template and includes summary, screenshots, testing, AI review, security audit, and notes.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/main/pty/omp-shell-wrapper.ts (1)

72-93: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve launch before prepending --session-dir In both wrappers, the fresh-session prepend changes $1/$orcaArgs[0], so omp launch falls into the generic branch and is forwarded as omp --extension ... --session-dir ... launch ... instead of omp launch --extension ... --session-dir .... Capture the original subcommand before mutating the args, then branch on that saved value.

src/main/ipc/pty.ts (1)

2163-2180: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Add applyOmpFreshSessionDirEnv to the daemon-host PTY spawn path.
This path still skips the fresh-session env wiring, so launches that carry ORCA_OMP_FORCE_NEW_SESSION_ENV=1 can fall back to the wrapper’s default sessions dir and reuse stale OMP state.

🧹 Nitpick comments (2)
src/main/pty/omp-shell-wrapper.node-pty.test.ts (1)

183-297: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add test coverage for omp launch with forced new session.

None of the new tests exercise omp launch ... under ORCA_OMP_FORCE_NEW_SESSION_ENV=1. Given the wrapper's launch dispatch check happens after --session-dir injection (see companion comment in omp-shell-wrapper.ts), a test case with command: 'omp launch <agent>' would surface that ordering bug.

src/main/pty/omp-fresh-session-dir.ts (1)

20-33: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Function is correct and well-tested; consider one more edge-case test.

The conditional-apply logic itself (skip when not forcing new session, preserve explicit override) is correct and matches the accompanying unit tests. Consider adding a test asserting the 'unknown-worktree' fallback behavior when both worktreeId and cwd are omitted, since that path is where the cross-worktree collision risk above materializes.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 814cc609-a04a-4bbc-80ca-6e02d51c769c

📥 Commits

Reviewing files that changed from the base of the PR and between cf7fb4f and 21038cf78f8945806e97de65393e5d863a3b237a.

📒 Files selected for processing (16)
  • src/main/ipc/pty.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/pty/omp-fresh-session-dir.test.ts
  • src/main/pty/omp-fresh-session-dir.ts
  • src/main/pty/omp-shell-wrapper.node-pty.test.ts
  • src/main/pty/omp-shell-wrapper.ts
  • src/main/pty/wsl-orca-env.test.ts
  • src/main/pty/wsl-orca-env.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.web-runtime.test.ts
  • src/shared/omp-fresh-session-env.ts
  • src/shared/tui-agent-draft-startup.ts
  • src/shared/tui-agent-startup-building.ts
  • src/shared/tui-agent-startup.test.ts
  • src/shared/tui-agent-startup.ts

@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 9, 2026 16:50
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:40
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@mmarabel

Copy link
Copy Markdown
Contributor Author

Rebased onto current upstream/main (5b7f44278a).

Kept the OMP fresh-session isolation behavior on the current spawn/startup paths:

  • One-shot ORCA_OMP_FORCE_NEW_SESSION plus a worktree-scoped --session-dir still bypass auto-resume without persisting into later resume launches.
  • Main fills ORCA_OMP_FRESH_SESSION_DIR after installing the managed OMP env (daemon spawn uses resolved cwd).
  • WSLENV still translates the session dir into the guest.
  • Promptless OMP web-host launches send the concrete command/env instead of host shorthand.

Force-pushed fix/omp-fresh-session-isolation.

@nwparker

Copy link
Copy Markdown
Contributor

Superseded by #20622 (fresh OMP session isolation), which contains the current implementation and verification on . Closing this stale duplicate so review stays on the maintained PR.

@nwparker

Copy link
Copy Markdown
Contributor

Superseded by #20622.

@nwparker nwparker closed this Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OMP fresh launches can resume a previous session across new terminals/worktrees

4 participants