Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

fix: prevent conda auto-activation from hijacking terminal command output - #11149

Draft
ghost wants to merge 2 commits into
mainfrom
fix/terminal-conda-first-command-11148
Draft

fix: prevent conda auto-activation from hijacking terminal command output#11149
ghost wants to merge 2 commits into
mainfrom
fix/terminal-conda-first-command-11148

Conversation

@ghost

@ghost ghost commented Feb 2, 2026

Copy link
Copy Markdown

This PR attempts to address Issue #11148.

Problem

When a terminal is created with conda auto-activation (or any shell initialization that runs commands), a race condition could occur where VSCode fires onDidStartTerminalShellExecution events for BOTH the conda activation AND Roo's command. The previous implementation blindly set the stream when the event fired, causing Roo to pick up the wrong stream and miss its own command's output.

Solution

  1. Added an optional eventCommand parameter to setActiveStream() in BaseTerminal.ts
  2. Modified TerminalRegistry.onDidStartTerminalShellExecution to pass the command from the event
  3. Added command verification logic using flexible prefix matching to handle PowerShell workarounds
  4. When eventCommand is provided, stream_available is only emitted if it matches Roo's expected command

Changes

  • src/integrations/terminal/types.ts: Updated RooTerminal.setActiveStream signature
  • src/integrations/terminal/BaseTerminal.ts: Added commandsMatch() static method and command verification
  • src/integrations/terminal/TerminalRegistry.ts: Pass eventCommand to setActiveStream
  • src/integrations/terminal/__tests__/BaseTerminal.spec.ts: Added comprehensive tests

Testing

  • All existing terminal tests pass
  • Added 18 new tests covering:
    • Command matching logic (exact, prefix, non-matching cases)
    • Stream handling with command verification
    • Backward compatibility when eventCommand is not provided

Feedback and guidance are welcome.


Important

Fixes race condition in terminal command execution by verifying command matches before setting stream, preventing interference from auto-activation commands.

  • Behavior:
    • Adds eventCommand parameter to setActiveStream() in BaseTerminal.ts to verify command matches before setting stream.
    • Modifies TerminalRegistry.onDidStartTerminalShellExecution to pass eventCommand for verification.
    • Implements command verification using commandsMatch() to prevent interference from auto-activation commands.
  • Testing:
    • Adds 18 tests in BaseTerminal.spec.ts for command matching and stream handling.
    • Tests cover exact, prefix, and non-matching cases, ensuring backward compatibility.
  • Misc:
    • Updates RooTerminal.setActiveStream signature in types.ts.

This description was created by Ellipsis for 75501ab. You can customize this summary. It will automatically update as commits are pushed.

Interactively review PR in Roo Code Cloud

@ghost

ghost commented Feb 2, 2026

Copy link
Copy Markdown
Author

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The log level change from console.warn to console.debug is appropriate for expected command mismatch events. The test was correctly updated to match.

Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@alippai

alippai commented Feb 2, 2026

Copy link
Copy Markdown

@roomote the warn for an expected ignore happening in every terminal is a bit strong. Make it lower / less chatty.

Does this also work if conda activation takes 4-5 seconds?

@ghost

ghost commented Feb 2, 2026

Copy link
Copy Markdown
Author

Fixaroo Clock   See task on Roo Cloud

Changed console.warn to console.debug for expected command-mismatch events. All checks passed.

Regarding timing: Yes, this works regardless of how long conda activation takes. The implementation uses command-string matching (not timing-based), so it will correctly identify and ignore any shell initialization command that doesn't match Roo's expected command.

View commit | Revert commit

@alippai

alippai commented Feb 9, 2026

Copy link
Copy Markdown

@hannesrudolph what do you think, does this make sense?

@alippai

alippai commented Feb 19, 2026

Copy link
Copy Markdown

@hannesrudolph I believe this is useful in multiple use-cases

@alippai

alippai commented Mar 9, 2026

Copy link
Copy Markdown

@roomote rebase, please.

@ghost

ghost commented Mar 9, 2026

Copy link
Copy Markdown
Author

Fixaroo Clock   See task

Rebased the branch onto main. No conflicts encountered.

View latest commit

roomote added 2 commits March 9, 2026 20:33
…tput

When a terminal is created with conda auto-activation (or any shell
initialization that runs commands), a race condition could occur where
VSCode fires onDidStartTerminalShellExecution events for BOTH the conda
activation AND Roo's command. The previous implementation blindly set
the stream when the event fired, causing Roo to pick up the wrong stream
and miss its own command's output.

This fix:
1. Adds an optional eventCommand parameter to setActiveStream()
2. Passes the command from the shell execution event for verification
3. Only emits stream_available if the event command matches Roo's command
4. Uses flexible prefix matching to handle PowerShell workarounds

Fixes #11148
@ghost
ghost force-pushed the fix/terminal-conda-first-command-11148 branch from 75501ab to b869091 Compare March 9, 2026 20:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants