Skip to content

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

Open
yzlu0917 wants to merge 6 commits intocontinuedev:mainfrom
yzlu0917:codex/issue-10542-remote-terminal
Open

[codex] fix(vscode): run commands in remote terminals#12063
yzlu0917 wants to merge 6 commits 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 across remote workspaces and restores /cmd, Ollama/Lemonade helpers, and terminal-tool fallbacks. Adds default OpenRouter metadata headers in the core OpenRouter client.

  • Bug Fixes

    • Route VsCodeIde.runCommand() through runCommandInTerminal; in remote workspaces create terminals via workbench.action.terminal.new, wait until the new terminal is active, and ignore unrelated terminals (5s timeout).
    • Always send commands with a trailing newline; cache and reuse named terminals.
    • Add tests for local reuse, remote creation, named remote reuse, and ignoring unrelated remote terminals.
  • Dependencies

    • Export OPENROUTER_HEADERS from @continuedev/openai-adapters and apply them in core OpenRouter (adds HTTP-Referer, X-OpenRouter-Title, and X-OpenRouter-Categories).

Written for commit abd96ca. 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.

Comment thread extensions/vscode/src/util/runCommandInTerminal.ts Outdated
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 👍 / 👎.

@yzlu0917 yzlu0917 force-pushed the codex/issue-10542-remote-terminal branch from 0fe8c9c to e36d9ec Compare April 9, 2026 11:26
@1mt4y
Copy link
Copy Markdown

1mt4y commented Apr 19, 2026

Does anyone have a workaround for this while we wait for the PR to be merged?

I tried hooking up an external MCP terminal server (@dillip285/mcp-terminal) and wrapping the command in SSH inside the config.yaml to force it to run on the remote machine but it completely failed 😭

If anyone has a reliable way to get terminal commands actually executing on the remote host in the meantime, I'd appreciate it!

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

2 participants