Skip to content

Conversation

@mr-ryan-james
Copy link
Contributor

@mr-ryan-james mr-ryan-james commented May 26, 2025

Problem

I discovered an Encoding::CompatibilityError when running commands like pod install (CocoaPods/Ruby) within Roo Code's integrated terminal when the "Disable terminal shell integration" setting is enabled. The root cause was identified as the ExecaTerminalProcess not being configured with UTF-8 encoding, leading to character encoding compatibility issues in Ruby scripts.

The error message specifically suggested setting export LANG=en_US.UTF-8.

Root Cause Analysis

When users enable the "Disable terminal shell integration" setting, Roo Code switches from VSCode's built-in terminal to the ExecaTerminal implementation. This fallback path uses Node.js execa library via ExecaTerminalProcess, which was not inheriting proper UTF-8 locale settings.

Code Path When "Disable Terminal Shell Integration" is Enabled:

  1. executeCommandTool.ts:149provider = "execa"
  2. TerminalRegistry.ts:133new ExecaTerminal()
  3. ExecaTerminal.ts:21new ExecaTerminalProcess()
  4. ExecaTerminalProcess.ts → 🎯 Where UTF-8 fix is applied

Solution

This PR resolves the UTF-8 encoding issue by ensuring the ExecaTerminalProcess sets proper UTF-8 locale environment variables when creating subprocesses.

Changes Made:

Updated ExecaTerminalProcess Environment Configuration (src/integrations/terminal/ExecaTerminalProcess.ts):

  • Added LANG: "en_US.UTF-8" to the subprocess environment variables
  • Added LC_ALL: "en_US.UTF-8" to the subprocess environment variables
  • This ensures consistent UTF-8 encoding for all commands executed through the ExecaTerminal path

Scope and Impact

✅ What this fixes:

  • UTF-8 encoding issues for users with "Disable terminal shell integration" enabled
  • Ruby/CocoaPods commands that fail due to encoding compatibility
  • Locale-related command execution problems in the ExecaTerminal fallback path

✅ What this doesn't affect:

  • Default VSCode terminal behavior (shell integration enabled)
  • Users who use the default terminal settings
  • VSCode's built-in terminal API and shell integration features

Testing

The fix has been tested and resolves the Encoding::CompatibilityError that was preventing Ruby/CocoaPods commands from executing successfully when the "Disable terminal shell integration" setting is enabled.

Alignment with Project Goals

This change aligns with the Reliability First roadmap goal by:

  • Ensuring command execution is consistently reliable across different terminal configurations
  • Guaranteeing smooth operation across different locale configurations
  • Reducing friction points for users who utilize the ExecaTerminal implementation

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Technical Details

This fix specifically targets the ExecaTerminal code path which is only used when:

  1. User has the "Disable terminal shell integration" setting enabled
  2. Roo Code uses Node.js execa instead of VSCode terminal API
  3. Commands are executed through ExecaTerminalProcess subprocess creation

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • My changes are targeted to the specific ExecaTerminal implementation
  • My changes align with the project roadmap

Fixes #4033

@mr-ryan-james mr-ryan-james requested review from cte and mrubens as code owners May 26, 2025 08:14
@mr-ryan-james mr-ryan-james changed the title Fix UTF-8 encoding issue in integrated terminal Fix UTF-8 encoding in ExecaTerminalProcess for disabled shell integration May 26, 2025
@mr-ryan-james mr-ryan-james force-pushed the fix/terminal-utf8-encoding branch from 72b6a44 to e976075 Compare May 27, 2025 10:03
@mr-ryan-james mr-ryan-james changed the title Fix UTF-8 encoding in ExecaTerminalProcess for disabled shell integration Fix UTF-8 encoding in ExecaTerminalProcess May 27, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label May 27, 2025
@mr-ryan-james mr-ryan-james force-pushed the fix/terminal-utf8-encoding branch from e976075 to 34ee039 Compare May 28, 2025 11:14
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 28, 2025
@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Preliminary Review] in Roo Code Roadmap May 28, 2025
@daniel-lxs
Copy link
Member

Hey @mr-ryan-james, this makes sense, I'll try to repro the issue and see if this is a correct fix.

@daniel-lxs daniel-lxs added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels May 28, 2025
@daniel-lxs
Copy link
Member

Hey @mr-ryan-james. Just tested this and can confirm the fix works as intended.

I created a test script that simulates the encoding issue, without the UTF-8 env vars, Ruby defaults to US-ASCII which would break CocoaPods. With your fix setting LANG/LC_ALL to en_US.UTF-8, everything works.

I think it might be worth adding a unit test for this. I noticed ExecaTerminalProcess doesn't have test coverage yet. Could help catch any future regressions. What do you think?

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap May 29, 2025
@mr-ryan-james
Copy link
Contributor Author

Hey @mr-ryan-james. Just tested this and can confirm the fix works as intended.

I created a test script that simulates the encoding issue, without the UTF-8 env vars, Ruby defaults to US-ASCII which would break CocoaPods. With your fix setting LANG/LC_ALL to en_US.UTF-8, everything works.

I think it might be worth adding a unit test for this. I noticed ExecaTerminalProcess doesn't have test coverage yet. Could help catch any future regressions. What do you think?

Thanks for taking the time to test thsi! I will start iterating a bit on tesing my functionality.

- Set LANG and LC_ALL environment variables to en_US.UTF-8
- Resolves Encoding::CompatibilityError in Ruby/CocoaPods commands
- Ensures consistent UTF-8 encoding across all terminal sessions

This change addresses the terminal encoding issue where commands like
'pod install' would fail due to incompatible character encoding. The
fix ensures all integrated terminals are initialized with proper
UTF-8 locale settings.
- Tests verify LANG and LC_ALL are set to en_US.UTF-8
- Tests ensure existing environment variables are preserved
- Tests confirm UTF-8 settings override conflicting locale values
- Addresses PR feedback requesting test coverage for encoding fix
- All 7 tests passing with proper mocking of execa and ps-tree
@mr-ryan-james mr-ryan-james force-pushed the fix/terminal-utf8-encoding branch from 34ee039 to ac674a1 Compare May 30, 2025 14:40
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels May 30, 2025
@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap May 30, 2025
@daniel-lxs
Copy link
Member

Hey @mr-ryan-james, Thanks for adding the tests so quickly!

Everything looks good to me now.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap May 30, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label May 30, 2025
@mrubens mrubens merged commit 177e7a8 into RooCodeInc:main May 30, 2025
15 checks passed
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap May 30, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap May 30, 2025
SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

UTF-8 encoding issue in ExecaTerminalProcess

4 participants