Skip to content

fix(server): fall back to a UTF-8 locale in terminal spawn env - #4827

Open
Kaidstor wants to merge 1 commit into
pingdotgg:mainfrom
Kaidstor:fix/terminal-utf8-locale-fallback
Open

fix(server): fall back to a UTF-8 locale in terminal spawn env#4827
Kaidstor wants to merge 1 commit into
pingdotgg:mainfrom
Kaidstor:fix/terminal-utf8-locale-fallback

Conversation

@Kaidstor

@Kaidstor Kaidstor commented Jul 29, 2026

Copy link
Copy Markdown

What Changed

The terminal manager now falls back to a UTF-8 locale when spawning a PTY whose environment defines neither LANG nor LC_ALL: en_US.UTF-8 on macOS, C.UTF-8 on Linux (the only one guaranteed to exist), nothing on Windows. An explicitly configured locale — even a non-UTF-8 one — and per-session runtime env overrides are left untouched. Two tests cover the fallback and the "explicit locale wins" case.

Why

GUI apps launched from the macOS Dock/Finder get no LANG/LC_* from launchd (Terminal.app and iTerm inject their own; the integrated terminal inherits the server process env instead). The PTY shell therefore starts in the single-byte C locale, and zsh's line editor mangles any multibyte input — typing non-ASCII text (e.g. Cyrillic) renders as raw bytes instead of characters:

❯ for�
❯ ???????<0080>??      # typing "фор…" — <0080> is the 2nd byte of UTF-8 "р"

Repro on macOS: launch the packaged app from the Dock, open the integrated terminal, run localeLANG="", LC_CTYPE="C"; then type any non-ASCII character.

VS Code works around the same launchd behavior with terminal.integrated.detectLocale; this is the minimal equivalent.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (terminal transcript above; no app UI changed)

Note

Low Risk
Localized change to PTY spawn environment with conservative defaults and no override when the user already set locale variables.

Overview
Fixes integrated terminals starting in the C locale when the server inherits a bare environment (e.g. macOS Dock/Finder via launchd), which broke multibyte shell input.

createTerminalSpawnEnv now runs withUtf8LocaleFallback after AppImage scrubbing: if neither LANG nor LC_ALL is set, it sets LANG to en_US.UTF-8 on macOS and C.UTF-8 on Linux; Windows is unchanged. Existing LANG / LC_ALL values (including non-UTF-8 locales) are not overridden.

Tests assert the macOS fallback and that an explicit LANG is preserved.

Reviewed by Cursor Bugbot for commit 83d4050. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fall back to a UTF-8 locale in terminal spawn env on non-Windows platforms

Introduces withUtf8LocaleFallback in Manager.ts to inject a LANG fallback when LC_ALL and LANG are absent from the spawn environment. On macOS the fallback is en_US.UTF-8; on other non-Windows platforms it is C.UTF-8. Windows and envs with an explicit locale are left unchanged. createTerminalSpawnEnv now accepts a platform argument and pipes the env through this fallback after stripping AppImage variables.

Macroscope summarized 83d4050.

GUI apps launched from the macOS Dock/Finder inherit no LANG/LC_* from
launchd, so the integrated terminal's PTY shell starts in the single-byte
C locale and zsh's line editor renders multibyte input (any non-ASCII
text) as raw bytes like `<0080>`. Default LANG to en_US.UTF-8 on macOS
and C.UTF-8 on Linux when neither LANG nor LC_ALL is present; explicitly
configured locales and runtime env overrides stay untouched.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c30e127f-6722-452d-9abc-c2ad9c9d76ac

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Jul 29, 2026
@macroscopeapp

macroscopeapp Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved 83d4050

Straightforward bug fix that adds a UTF-8 locale fallback for terminal spawning when no locale is configured. The change is defensive, respects existing user settings, and includes test coverage for both the fallback and preservation behaviors.

You can customize Macroscope's approvability policy. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant