Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

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 to os.tmpdir(), a LOCAL path like /tmp) to construct overflow file paths, then passing those paths to config.runtime.writeFile(). This failed for SSH runtimes because:

  1. os.tmpdir() returns a local filesystem path (e.g., /tmp on the local machine)
  2. SSHRuntime.writeFile() expects a path on the REMOTE filesystem
  3. The path construction was local-only, breaking remote execution

The Solution

Changed the bash tool to write overflow files to a runtime-agnostic location: {cwd}/.cmux/tmp/bash-{id}.txt

Key changes:

  • bash.ts: Changed from path.join(config.tempDir, ...) to path.join(config.cwd, ".cmux", "tmp", ...)
  • bash.test.ts: Updated test to verify files are created in the new location

Why This Works

  • config.cwd is already runtime-appropriate (local path for LocalRuntime, remote path for SSHRuntime)
  • Both LocalRuntime.writeFile() and SSHRuntime.writeFile() automatically create parent directories
  • The temp file is now workspace-relative, making it accessible in both local and SSH contexts

Testing

✅ All 46 tests pass, including the test that specifically verifies tmpfile policy behavior.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

- 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
@ammario ammario added this pull request to the merge queue Oct 27, 2025
Merged via the queue into main with commit c08b7a8 Oct 27, 2025
13 checks passed
@ammario ammario deleted the rt-bash-overflow branch October 27, 2025 03:02
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