Skip to content

fix(terminal): drop orphaned XTVERSION bodies; set TERM_PROGRAM on remote PTYs#7841

Closed
bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:fix/7839-remote-xtversion-reply-leak
Closed

fix(terminal): drop orphaned XTVERSION bodies; set TERM_PROGRAM on remote PTYs#7841
bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:fix/7839-remote-xtversion-reply-leak

Conversation

@bbingz

@bbingz bbingz commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes remote Grok showing >|xterm.js(6.1.0-beta.287) as the prompt (same Orca build works locally).

Root cause (investigation)

  1. xterm.js identity: Orca ships @xterm/xterm@6.1.0-beta.287. XTVERSION replies are:
    ESC P > | xterm.js(6.1.0-beta.287) ESC \
  2. Grok probes XTVERSION (CSI >0q) and has logic for “dropping stalled XTVERSION reply fragment”; when framing is lost, the printable body can land in the TUI input.
  3. Local vs remote env skew: local + daemon PTY set TERM_PROGRAM=Orca (+ version / COLORTERM / FORCE_HYPERLINK). SSH/relay spawns did not, so remote Grok leans harder on XTVERSION over a higher-latency path.

Related prior work: #7329 / #7736 (immediate query replies), #5523 (reply leak class), #6975 (Windows OSC body leak — same ESC-swallow shape).

Fix

Change Why
isOrphanedTerminalQueryReplyBody + drop on onData Do not forward ESC-stripped >|xterm.js(...) / OSC color bodies as keystrokes
SSH withRemoteCliBridgeEnv + relay buildSpawnEnv seed terminal identity Parity with local/daemon so Grok brands as Orca
Keep framed XTVERSION on sendInputImmediate Still latency-critical (#7329)

Screenshots

No visual change (terminal identity / input sanitization only).

Testing

  • src/shared/terminal-query-reply.test.ts (framed beta XTVERSION + orphan cases)
  • src/main/providers/ssh-pty-provider.test.ts (identity env on spawn)
  • pty-connection onData routing test extended for XTVERSION immediate + orphan drop
  • oxlint on touched files
  • After rebase onto latest origin/main: focused vitest 45 passed
    (terminal-query-reply + ssh-pty-provider). Full pty-connection suite load depends on renderer alias graph; core shared + SSH coverage green.

AI Review Report

  • Conservative orphan matcher: only full-chunk >\|xterm.js(...) / ]10|11;... bodies — not prefixes of normal typing.
  • Framed replies still immediate-send (not dropped).
  • Remote env forces identity even if renderer omitted keys; does not override explicit TERM when already set (TERM = TERM \|\| xterm-256color).
  • Cross-platform: SSH/relay only for env seed; orphan drop is path-agnostic (macOS / Linux / Windows clients over SSH).

Security Audit

  • No new IPC surface; drops orphaned query-reply bodies that would otherwise inject into agent TUI input.
  • Env seeding only sets terminal identity variables (TERM_PROGRAM, version, COLORTERM, etc.) already used on local/daemon paths.
  • No secrets or path handling changes.

Notes

  • Rebased onto latest origin/main (0eeac678a).
  • Primary user impact: remote/SSH Grok (and similar TUIs) no longer receive leaked XTVERSION bodies as prompt text.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@bbingz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 33 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 143c112c-d3f1-4306-8bfc-497b80c41a43

📥 Commits

Reviewing files that changed from the base of the PR and between 3e4e222 and aa27ee6.

📒 Files selected for processing (7)
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/shared/terminal-query-reply.test.ts
  • src/shared/terminal-query-reply.ts
📝 Walkthrough

Walkthrough

This PR injects Orca terminal identity environment variables into SSH and relay PTY spawn environments, with tests covering environment merging, deletion behavior, relay bridge variables, and Windows PATH handling. It also adds detection for frameless XTVERSION and OSC color reply bodies, filters them from renderer PTY input, and preserves routing for fully framed terminal replies.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: dropping orphaned XTVERSION bodies and seeding TERM_PROGRAM for remote PTYs.
Description check ✅ Passed The description matches the required template and covers summary, screenshots, testing, AI review, security audit, and notes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/main/providers/ssh-pty-provider.test.ts (1)

54-59: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use ORCA_TERMINAL_IDENTITY_ENV consistently in early tests.

Lines 54-59 and 78-84 spell out TERM_PROGRAM, COLORTERM, and FORCE_HYPERLINK individually, while all subsequent tests (102+) use ...ORCA_TERMINAL_IDENTITY_ENV. Spreading the constant here too keeps the assertions DRY and ensures a single update point if values change.

♻️ Proposed refactor for lines 54-59
         env: expect.objectContaining({
           [POWERLEVEL10K_WIZARD_DISABLE_ENV]: 'true',
-          TERM_PROGRAM: 'Orca',
-          COLORTERM: 'truecolor',
-          FORCE_HYPERLINK: '1'
+          ...ORCA_TERMINAL_IDENTITY_ENV
         })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d8230a5f-dd28-4b0e-aeec-e1a8c36d0b28

📥 Commits

Reviewing files that changed from the base of the PR and between e218bf8 and 5825875.

📒 Files selected for processing (7)
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/shared/terminal-query-reply.test.ts
  • src/shared/terminal-query-reply.ts

Comment thread src/main/providers/ssh-pty-provider.test.ts Outdated
Comment thread src/main/providers/ssh-pty-provider.ts Outdated
Comment thread src/relay/pty-handler.ts Outdated
@AmethystLiang AmethystLiang requested a review from Jinwoo-H July 8, 2026 22:45
bbingz added a commit to bbingz/orca that referenced this pull request Jul 8, 2026
Address CodeRabbit on stablyai#7841: match daemon and always force TERM=xterm-256color
on SSH/relay (avoid ambient TERM=dumb). Assert full identity env in tests
including TERM and TERM_PROGRAM_VERSION.
bbingz added a commit to bbingz/orca that referenced this pull request Jul 10, 2026
Address CodeRabbit on stablyai#7841: match daemon and always force TERM=xterm-256color
on SSH/relay (avoid ambient TERM=dumb). Assert full identity env in tests
including TERM and TERM_PROGRAM_VERSION.
@bbingz bbingz force-pushed the fix/7839-remote-xtversion-reply-leak branch from a03da2c to 0eeac67 Compare July 10, 2026 06:53
@bbingz

bbingz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest origin/main (clean). Focused vitest: terminal-query-reply + ssh-pty-provider 45/45 green. Head: 0eeac678a.

bbingz added a commit to bbingz/orca that referenced this pull request Jul 10, 2026
Address CodeRabbit on stablyai#7841: match daemon and always force TERM=xterm-256color
on SSH/relay (avoid ambient TERM=dumb). Assert full identity env in tests
including TERM and TERM_PROGRAM_VERSION.
@bbingz bbingz force-pushed the fix/7839-remote-xtversion-reply-leak branch from 0eeac67 to 3e4e222 Compare July 10, 2026 06:58
bbingz added 2 commits July 10, 2026 18:01
…mote PTYs

Remote Grok can show `>|xterm.js(6.1.0-beta.287)` as the prompt when an
XTVERSION query reply loses ESC framing or arrives late (stablyai#7839). Local PTYs
set TERM_PROGRAM=Orca so Grok feature-gates without relying on XTVERSION alone;
SSH/relay spawns did not.

- Classify and drop frameless XTVERSION/OSC color reply bodies on onData
- Seed TERM_PROGRAM/COLORTERM/FORCE_HYPERLINK on SSH + relay spawn env
- Keep framed XTVERSION on the immediate send path (stablyai#7329)

Fixes stablyai#7839
Address CodeRabbit on stablyai#7841: match daemon and always force TERM=xterm-256color
on SSH/relay (avoid ambient TERM=dumb). Assert full identity env in tests
including TERM and TERM_PROGRAM_VERSION.
@bbingz bbingz force-pushed the fix/7839-remote-xtversion-reply-leak branch from 3e4e222 to aa27ee6 Compare July 10, 2026 10:09
@Jinwoo-H

Copy link
Copy Markdown
Contributor

Superseded by #7944, which includes this XTVERSION and remote terminal fix along with the related Grok compatibility fixes and regression coverage.

@Jinwoo-H Jinwoo-H closed this Jul 10, 2026
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