Repository navigation
Conversation
…ogies (STA-4746) STA-4746 reported that a remote/paired agent under a folder workspace (ORCA_WORKTREE_ID=folder:<uuid>) spawns its relay PTY in a fallback cwd because relay cwd resolution only parses repoId::path worktree ids. The relay has always taken cwd from the spawn request; splitWorktreeId() feeds only the beginPtyCreation admission key. The reported symptom comes from the remote host's own login startup files: the relay spawns POSIX login shells, so an /etc/profile.d entry that cd's wins after the shell already started in the workspace root (hence OLDPWD=<workspace> in the report). The same cd moves a plain git worktree identically. Test-only; no behavior change. Injecting the alleged id-derived cwd into pty-handler turns 4 of the 5 relay cases red.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughAdds unit and end-to-end tests for terminal cwd behavior in folder workspaces. The tests cover local PTY cwd precedence, headless remote runtimes, paired desktop clients, and SSH relay hosts. They verify working directories, workspace-root and worktree environment variables, PTY ownership, login-profile directory changes, process cwd, marker commands, Git worktree behavior, and resource cleanup. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
tests/e2e/sta4746-folder-remote-cwd.spec.ts (1)
14-17: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the temporary directory in the
finallyblock.The test creates
parentunder the OS temp directory but never removes it. Each run leaves a workspace tree behind. The paired-desktop spec removes its temp tree withrmSync; apply the same cleanup here.♻️ Proposed cleanup
-import { mkdtempSync, mkdirSync } from 'node:fs' -import { realpathSync } from 'node:fs' +import { mkdirSync, mkdtempSync, realpathSync, rmSync } from 'node:fs'test('STA-4746: folder-workspace terminal on a headless paired host', async () => { test.setTimeout(240_000) const host = await launchHeadlessPairedRuntimeHost() + let parent: string | undefined try { - const parent = realpathSync(mkdtempSync(path.join(os.tmpdir(), 'sta4746-'))) + parent = realpathSync(mkdtempSync(path.join(os.tmpdir(), 'sta4746-'))) const folderPath = path.join(parent, 'workspace')} finally { await host.dispose() + if (parent) { + rmSync(parent, { recursive: true, force: true }) + } } })Also applies to: 69-71
tests/e2e/sta4746-paired-desktop-folder-cwd.spec.ts (1)
21-64: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated
probeWorkspaceTerminalin two specs. Both specs contain a near-identical store-activation, keyboard-probe, and poll implementation. Only the probe token, the printf format, and the poll timeout differ.
tests/e2e/sta4746-paired-desktop-folder-cwd.spec.ts#L21-L64: move this implementation intotests/e2e/helpers/terminal.tswith parameters for the probe token, printf fields, and timeout, then import it here.tests/e2e/sta4746-ssh-folder-cwd.spec.ts#L25-L68: delete the local copy and call the shared helper with the SSH probe token and the 90-second timeout.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d6f1c832-5c90-456b-a783-eb12d4065934
📒 Files selected for processing (4)
src/relay/pty-handler-folder-workspace-cwd.test.tstests/e2e/sta4746-folder-remote-cwd.spec.tstests/e2e/sta4746-paired-desktop-folder-cwd.spec.tstests/e2e/sta4746-ssh-folder-cwd.spec.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Independent review flagged that the specs could pass without proving the claim. Assert exact parsed probe fields instead of substring matches (a sibling path with the expected path as a prefix would have passed), pin the PTY owner shape per topology (folder:/remote:/ssh:) so a client-local or daemon-local fallback cannot satisfy the path assertions, read /proc/$$/cwd from the probed shell itself rather than scanning every remote bash, and have the injected login profile record where each shell started so the profile-cd phases no longer rest on OLDPWD alone.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 96323276-1fd2-4104-90de-c12c70e63e15
📒 Files selected for processing (5)
src/relay/pty-handler-folder-workspace-cwd.test.tstests/e2e/helpers/sta4746-cwd-probe.tstests/e2e/sta4746-folder-remote-cwd.spec.tstests/e2e/sta4746-paired-desktop-folder-cwd.spec.tstests/e2e/sta4746-ssh-folder-cwd.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/relay/pty-handler-folder-workspace-cwd.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| expect(profiledWorktree.pwd).toBe(REMOTE_PROFILE_CD_PATH) | ||
| expect(profiledWorktree.oldpwd).toBe(DOCKER_SSH_RELAY_REMOTE_REPO_PATH) | ||
| expect(profiledWorktree.root).toBe('') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the Git-worktree process cwd and worktree ID.
Phase C emits selfcwd and wt, but does not check them. A regression can leave ORCA_WORKTREE_ID unset or report an incorrect shell process cwd while these assertions pass.
Proposed fix
expect(profiledWorktree.pwd).toBe(REMOTE_PROFILE_CD_PATH)
+expect(profiledWorktree.selfcwd).toBe(REMOTE_PROFILE_CD_PATH)
expect(profiledWorktree.oldpwd).toBe(DOCKER_SSH_RELAY_REMOTE_REPO_PATH)
expect(profiledWorktree.root).toBe('')
+expect(profiledWorktree.wt).toBe(gitWorktreeKey)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| expect(profiledWorktree.pwd).toBe(REMOTE_PROFILE_CD_PATH) | |
| expect(profiledWorktree.oldpwd).toBe(DOCKER_SSH_RELAY_REMOTE_REPO_PATH) | |
| expect(profiledWorktree.root).toBe('') | |
| expect(profiledWorktree.pwd).toBe(REMOTE_PROFILE_CD_PATH) | |
| expect(profiledWorktree.selfcwd).toBe(REMOTE_PROFILE_CD_PATH) | |
| expect(profiledWorktree.oldpwd).toBe(DOCKER_SSH_RELAY_REMOTE_REPO_PATH) | |
| expect(profiledWorktree.root).toBe('') | |
| expect(profiledWorktree.wt).toBe(gitWorktreeKey) |
CI's narrower terminal wraps the probe line, so xterm leaves cursor-motion sequences inside the rendered row and the last field arrived as `<path>ESC[1BESC[29D`. Strip escapes with the shared stripAnsiEscapeSequences, and terminate the probe with `end=1` so a half-rendered row is retried instead of asserted as the real cwd.
|
Do not merge without review — this PR is test-only and the ticket it documents is already closed as invalid. Two follow-ups from the independent review pass, both out of scope here and unverified end to end, recorded so they are not lost:
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d8881534-f65f-488e-bdfa-9e8324ad1685
📒 Files selected for processing (2)
tests/e2e/helpers/sta4746-cwd-probe.tstests/e2e/sta4746-folder-remote-cwd.spec.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Independent review found the specs could pass on the wrong host and left state behind. Bind the PTY-owner assertions to the actual SSH connection id and paired environment id instead of any `ssh:`/`remote:` prefix; bound the joined-row probe parse at its own `end=1` terminator so it cannot splice fields from unrelated rows, and delimit the phase so one phase name cannot match another's prefix. Also: share one probeWorkspaceTerminal in the helper instead of three near-copies, reuse the hardened parser in the headless spec, remove the temp dirs and the per-phase tabs in finally, skip on win32 like sibling POSIX specs, and compute the default-cwd expectation instead of reading process.env.HOME, which is unset on some CI images.
…der-remote-cwd-claude
|
CI note: the 4 red unit shards are inherited from
Evidence that they are not mine:
Reported with a repro at #15381 (comment). This PR's own coverage is green: relay unit 5/5, and the changed-e2e lane ran all three specs (headless paired, headful paired, Docker SSH relay) on Linux runners. |
Summary
STA-4746 is invalid — on current
mainand on the reported v1.4.184. This PR contains no production change, only the regression coverage that proves it and guards the contract.The report claimed that in a paired/remote setup a folder workspace (
ORCA_WORKTREE_ID=folder:<uuid>) makes the relay spawn its PTY in a fallback cwd, because "relay cwd resolution only consultsORCA_WORKTREE_ID, parses it asrepoId::path, and never falls back toORCA_WORKSPACE_ROOT."That is not how the relay resolves cwd.
PtyHandler.spawnAfterAdmissiontakes cwd from the spawn request (params.cwd);splitWorktreeId(worktreeId)feeds only thebeginPtyCreationadmission key. The client side already resolvesfolder:<uuid>throughresolveTerminalStartupCwdForWorkspace→store.getFolderWorkspace(id).folderPath.What actually produces the reported symptom
On every POSIX relay branch the host's login startup chain runs after the PTY is placed, so a remote startup file that
cds wins after the shell already started in the workspace root. Two mechanisms get there:POSIX_LOGIN_ARGS = ['-l'](src/relay/pty-shell-launch.ts:12), so/etc/profile,/etc/profile.d/*and~/.zprofileare sourced.--rcfile, not-l), but the relay's own wrapper explicitly sources/etc/profile, then~/.bash_profile/~/.bash_login/~/.profile(src/relay/pty-shell-overlay-wrappers.ts:63-70).That is exactly the reporter's own evidence:
OLDPWDis only ever set bycd. Phase B of the SSH spec reproduces that byte-shape by adding one/etc/profile.dentry to the container. Phase C shows the samecdmoves a plainrepoId::/pathgit worktree identically, so this mechanism is not folder-specific. That establishes a non-folder-specific cause for the reported signature; combined with the topology table below finding no folder-specific defect, it is why this closes as invalid.Evidence (all on clean
main@ 1b5cc00)folderPath; filesystem marker written intofolderPath; git-worktree + host-local controls greenorca servepaired hostterminal.create(folder:<uuid>)→pwd == folderPath~/.orca-remote/relay-0.1.0+…)$PWDand remote/proc/<pid>/cwdboth == folder pathVersion oracle
The cwd-resolution logic is behaviourally identical at
v1.4.184:src/shared/terminal-startup-cwd.tsandsrc/shared/workspace-scope.tsdiffer only by import-path moves (shared/worktree-id→shared/worktree/id,shared/types→shared/folder-workspace-types), andsrc/relay/pty-handler.tsstill takes cwd fromparams.cwd. Those files carry unrelated changes since the tag — the equivalence claim is about the cwd path, not the whole diff. v1.4.184 also did not sendworktreeIdas a spawn param at all (added later inssh-pty-spawn-request.tsfor shell-history isolation), so the relay could not have derived cwd from it there either. Nothing was "already fixed".Separately, on node-pty's POSIX implementation a nonexistent cwd makes the child exit 1 rather than silently inheriting the parent's cwd (
node_modules/node-pty/src/unix/pty.cc), ruling out the "fell back to the container's CMD directory" mechanism as well. Windows uses a different spawn path and was not measured.Why the proposed fix is not implemented
The proposed
ORCA_WORKSPACE_ROOTfallback would change nothing for the reporter — cwd is already correct at spawn — and it would make the relay adopt an unvalidated client-supplied path for a request that named no working directory.cwdis optional on the wire (PtySpawnOptions.cwd,src/main/providers/pty-provider-contract.ts:42), and the relay's default-cwd branch exists for requests that genuinely name none. But every relay-bound caller for a folder workspace resolves a path first viaresolveTerminalStartupCwdForWorkspace; the one in-repo caller that can omitcwd(codex-detached-pane-restart.ts:210) is local-only and never reaches the relay. So the fallback has no relay caller to serve, and promoting an env var into it would only widen what the relay trusts.Coverage added
src/relay/pty-handler-folder-workspace-cwd.test.ts— 5 deterministic cases: folder id honours request cwd, folder id with noORCA_WORKSPACE_ROOT, worktree-id precedence unchanged, legacy/mixed-version client (env-onlyORCA_WORKTREE_ID), and the default-cwd fallback pinned to not adoptORCA_WORKSPACE_ROOT.tests/e2e/sta4746-folder-remote-cwd.spec.ts— headless pairedorca servehost.tests/e2e/sta4746-paired-desktop-folder-cwd.spec.ts— headed paired desktop server + client (@headful), with git-worktree and local-only controls.tests/e2e/sta4746-ssh-folder-cwd.spec.ts— real Docker SSH relay, 3 phases (clean / login-profile cd / git-worktree control), gated onORCA_E2E_SSH_DOCKER=1like the sibling docker specs.Guard is non-vacuous: injecting the alleged id-derived cwd into
pty-handler.tsturns 4 of the 5 relay cases red; reverting the injection returns 5/5 green.Commands
Gaps
CI runs all three specs on Linux runners (the changed-e2e job picked them up and all 3 passed), and the SSH phases were additionally exercised against a Linux container from a macOS host. Windows and WSL hosts were not exercised.
Closes STA-4746 as invalid.