Keep local cwd out of remote workspace auto-resume - #9511
austinywang wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughResume and restore flows now accept a policy that controls captured working-directory fallback. Remote workspaces use saved remote directories only, while local workspaces retain local-directory fallback behavior. Tests cover remote restores without saved directories. ChangesRemote restore working-directory handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Workspace
participant RestorableAgentSession
participant AgentRelaunchCommandBuilder
Workspace->>RestorableAgentSession: provide remote resume input
RestorableAgentSession->>RestorableAgentSession: exclude captured directory fallback
RestorableAgentSession->>AgentRelaunchCommandBuilder: build SSH resume command
AgentRelaunchCommandBuilder-->>Workspace: return command without local directory
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 25✅ Passed checks (25 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Sources/RestorableAgentSession.swift (1)
330-354: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick winApply the fallback policy to custom
{{cwd}}templates.When a custom registration uses
{{cwd}},resumeArgumentsreachescustomTemplateArguments, which still resolves it fromworkingDirectory ?? launchCommand?.workingDirectory. If remote restore passesallowCapturedWorkingDirectoryFallback: falseand has no trusted directory, this path still inserts the captured local directory into the command sent to the remote terminal.Pass the policy through
resumeArguments,customResumeArguments, andcustomTemplateArguments. When the policy is disabled, do not uselaunchCommand?.workingDirectory. Let a required{{cwd}}template value fail command generation. Add a remote custom-agent regression test for this case.As per path instructions, “When the trusted remote directory is absent, fail closed rather than reusing a captured local cwd.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Sources/RestorableAgentSession.swift` around lines 330 - 354, The custom registration resume path must honor allowCapturedWorkingDirectoryFallback when resolving {{cwd}}. Thread this flag through resumeArguments, customResumeArguments, and customTemplateArguments; when disabled, exclude launchCommand?.workingDirectory from fallback resolution so required templates fail command generation without a trusted directory. Add a regression test covering remote custom-agent restore with no trusted directory.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@Sources/RestorableAgentSession.swift`:
- Around line 330-354: The custom registration resume path must honor
allowCapturedWorkingDirectoryFallback when resolving {{cwd}}. Thread this flag
through resumeArguments, customResumeArguments, and customTemplateArguments;
when disabled, exclude launchCommand?.workingDirectory from fallback resolution
so required templates fail command generation without a trusted directory. Add a
regression test covering remote custom-agent restore with no trusted directory.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 884343c2-4a9a-4a1d-9891-f6132a82f289
📒 Files selected for processing (5)
Sources/AgentRelaunchCommandBuilder.swiftSources/RestorableAgentSession.swiftSources/SessionRestorableAgentSnapshot+Commands.swiftSources/Workspace.swiftcmuxTests/AgentSessionAutoResumeSettingsTests.swift
Summary
Fixes #7575
Testing
-only-testing:cmuxTests/AgentSessionAutoResumeSettingsTests/testRemoteWorkspaceAutoResumeKeepsRemoteStartupCommand: test-only commit failed with the local workspace cwd inrequestedWorkingDirectoryand startup input; fix commit passed 1 test with 0 failures./scripts/reload-cloud.sh --tag sym7575on the fix commit: cloud build 30874356769 (BUILD_OK; cloud path used, no local fallback)requested_working_directory: null, retained/usr/bin/ssh -tt ardrec@aws-m4pro-5as its startup command, and executed the resume command without either local cwd sentinel. The tagged app was then quit and its isolated socket/session fixtures removed.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Stop using the local working directory when auto-resuming a remote workspace. Only remote-provenance paths are used, and the SSH startup command stays intact. Fixes #7575.
Workspacenow prefers only saved remote directories and passesallowCapturedWorkingDirectoryFallback: false.allowCapturedWorkingDirectoryFallbackto resume/relaunch builders to control cwd prefixing and sanitization.ssh -ttcommand is preserved.Written for commit 1f09cd7. Summary will update on new commits.
Summary by CodeRabbit