Skip to content

[codex] fix(vscode): run commands in remote terminals#12063

Open
yzlu0917 wants to merge 1 commit intocontinuedev:mainfrom
yzlu0917:codex/issue-10542-remote-terminal
Open

[codex] fix(vscode): run commands in remote terminals#12063
yzlu0917 wants to merge 1 commit intocontinuedev:mainfrom
yzlu0917:codex/issue-10542-remote-terminal

Conversation

@yzlu0917
Copy link
Copy Markdown

@yzlu0917 yzlu0917 commented Apr 7, 2026

Summary

  • route VsCodeIde.runCommand() through a dedicated terminal helper
  • create new terminals with workbench.action.terminal.new when the workspace is remote, so SSH/devcontainer/codespaces commands start on the correct machine
  • always send commands with a trailing newline and add regression tests for local reuse, remote creation, and named remote terminal reuse

Why

VsCodeIde.runCommand() currently has two remote-terminal bugs:

  • sendText(command, false) types the command but never executes it
  • createTerminal() from the UI-side extension host creates a local terminal instead of a remote one

That breaks /cmd, Ollama/Lemonade startup helpers, and any terminal-tool fallback path in remote workspaces.

Validation

  • ran npm test -- src/util/runCommandInTerminal.vitest.ts in extensions/vscode
  • ran git diff --check
  • ran npm run tsc:check in extensions/vscode and only hit existing repo issues unrelated to this patch:
    • ../../core/llm/llms/OpenRouter.ts: missing OPENROUTER_HEADERS export
    • src/extension.ts: missing ./.buildTimestamp declaration

Closes #10542


Summary by cubic

Fixes command execution in VS Code terminals for remote workspaces by creating remote-aware terminals and ensuring commands run. Restores /cmd, Ollama/Lemonade startup helpers, and terminal tool fallbacks in SSH/devcontainers/Codespaces.

  • Bug Fixes
    • Route VsCodeIde.runCommand() through runCommandInTerminal; when remote, create terminals via workbench.action.terminal.new so they open on the correct host.
    • Always execute commands by sending a trailing newline (sendText(..., true)); reuse named terminals via a small cache.
    • Add tests for local reuse, remote creation, and named remote reuse.

Written for commit 0fe8c9c. Summary will update on new commits.

@yzlu0917 yzlu0917 requested a review from a team as a code owner April 7, 2026 05:35
@yzlu0917 yzlu0917 requested review from sestinj and removed request for a team April 7, 2026 05:35
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 7, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="extensions/vscode/src/util/runCommandInTerminal.ts">

<violation number="1" location="extensions/vscode/src/util/runCommandInTerminal.ts:64">
P2: Remote terminal creation is race-prone and can resolve to an unrelated concurrently opened terminal, causing commands to run in the wrong terminal session.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

return true;
};

const terminalListener = vscode.window.onDidOpenTerminal((terminal) => {
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 7, 2026

Choose a reason for hiding this comment

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

P2: Remote terminal creation is race-prone and can resolve to an unrelated concurrently opened terminal, causing commands to run in the wrong terminal session.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At extensions/vscode/src/util/runCommandInTerminal.ts, line 64:

<comment>Remote terminal creation is race-prone and can resolve to an unrelated concurrently opened terminal, causing commands to run in the wrong terminal session.</comment>

<file context>
@@ -0,0 +1,118 @@
+      return true;
+    };
+
+    const terminalListener = vscode.window.onDidOpenTerminal((terminal) => {
+      if (settled || existingTerminals.has(terminal)) {
+        return;
</file context>
Fix with Cubic

Copy link
Copy Markdown

@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.

Reviewed commit: 0fe8c9c462

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +84 to +85
if (resolveIfNewTerminalExists()) {
return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove pre-open scan for "new" remote terminals

The early resolveIfNewTerminalExists() check can select an unrelated terminal that was opened by the user/another extension after existingTerminals is captured but before workbench.action.terminal.new is executed. In that race, this function returns immediately, skips creating its own terminal, and then sends the command to the wrong terminal, which makes /cmd and startup helpers non-deterministic in busy remote workspaces.

Useful? React with 👍 / 👎.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

VsCodeIde.runCommand() doesn't execute commands in remote terminals

1 participant