-
Notifications
You must be signed in to change notification settings - Fork 14
Fix bash tool to use runtime-appropriate temp directory #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
0fad4fe to
bf46af4
Compare
- Changed overflow file path from config.tempDir to {cwd}/.cmux/tmp/
- This fixes SSH runtime support where config.tempDir was a local path
- Runtime.writeFile() expects runtime-appropriate paths (remote for SSH)
- Updated test to verify files are created in .cmux/tmp subdirectory
The bash tool overflow feature writes large outputs to temp files when they
exceed display limits. The previous implementation broke with SSH runtimes
because temp directories were created using local filesystem operations
(fs.mkdirSync) but passed to runtime.writeFile() which needs runtime-appropriate
paths.
Changes:
- Renamed 'tempDir' to 'runtimeTempDir' throughout for clarity
- StreamManager.createTempDirForStream() now uses runtime.exec('mkdir -p')
- Stream cleanup now uses runtime.exec('rm -rf') for temp directory removal
- Pass Runtime parameter through startStream() to enable temp dir operations
- Store Runtime in WorkspaceStreamInfo for cleanup access
- Updated ToolConfiguration interface (tempDir -> runtimeTempDir)
- Updated all tests to use runtimeTempDir
This ensures temp directories are created and cleaned up in the correct
location (local for LocalRuntime, remote for SSHRuntime) while preserving
the existing cleanup guarantees when streams end.
The test 'should use tmpfile policy by default' was checking for files in .cmux/tmp subdirectory, which was the path used in the initial (incorrect) fix. Now that overflow files are written directly to runtimeTempDir, the test needs to check the tempDir.path directly.
The previous implementation returned '~/.cmux-tmp/{token}' which is not
an absolute path. This would fail when passed to runtime.writeFile() in
LocalRuntime, as fs operations don't expand tilde.
Solution: Use 'mkdir -p ~/.cmux-tmp/{token} && cd ... && pwd' to get the
absolute path after creation. This works for both LocalRuntime and SSHRuntime:
- LocalRuntime: returns '/home/user/.cmux-tmp/{token}'
- SSHRuntime: returns '/home/remoteuser/.cmux-tmp/{token}' (remote path)
Also switched to execBuffered() helper for cleaner code.
TypeScript compilation errors revealed four places that still used tempDir: - aiService.ts: Early tool creation for sentinel detection - ipcMain.ts: executeBash IPC handler - todo.ts: Todo write tool (2 locations) All now use runtimeTempDir to match the ToolConfiguration interface.
Fixes Windows + SSH runtime compatibility. config.runtimeTempDir is always a POSIX path (e.g., /home/user/.cmux-tmp/token) even when cmux runs on Windows. Using path.join() would convert it to backslash form on Windows, breaking SSHRuntime.writeFile() which expects forward slashes. Solution: Always use path.posix.join() when constructing paths for runtime operations, regardless of host OS. Addresses Codex review comment PRRT_kwDOPxxmWM5fYEbF
Removed unused imports: fs, path (first occurrence), os These were left over after switching to execBuffered() for temp dir creation.
- Replaced all tempDir: with runtimeTempDir: in test files - Added runtime parameter to all streamManager.startStream() calls in tests - Imported createRuntime() and created runtime instance for tests
- Added runtime constant to StreamManager tests - Fixed todo.test.ts to use runtimeTempDir variable instead of tempDir
731fa00 to
49314d4
Compare
Summary
Fixes a bug where the bash tool wasn't using the Runtime to store bash overflow files properly, causing issues with SSH runtimes.
The Problem
The bash tool was using
config.tempDir(set toos.tmpdir(), a LOCAL path like/tmp) to construct overflow file paths, then passing those paths toconfig.runtime.writeFile(). This failed for SSH runtimes because:os.tmpdir()returns a local filesystem path (e.g.,/tmpon the local machine)SSHRuntime.writeFile()expects a path on the REMOTE filesystemThe Solution
Changed the bash tool to write overflow files to a runtime-agnostic location:
{cwd}/.cmux/tmp/bash-{id}.txtKey changes:
bash.ts: Changed frompath.join(config.tempDir, ...)topath.join(config.cwd, ".cmux", "tmp", ...)bash.test.ts: Updated test to verify files are created in the new locationWhy This Works
config.cwdis already runtime-appropriate (local path for LocalRuntime, remote path for SSHRuntime)LocalRuntime.writeFile()andSSHRuntime.writeFile()automatically create parent directoriesTesting
✅ All 46 tests pass, including the test that specifically verifies tmpfile policy behavior.