[codex] fix(vscode): run commands in remote terminals#12063
[codex] fix(vscode): run commands in remote terminals#12063yzlu0917 wants to merge 1 commit intocontinuedev:mainfrom
Conversation
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
💡 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".
| if (resolveIfNewTerminalExists()) { | ||
| return; |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
VsCodeIde.runCommand()through a dedicated terminal helperworkbench.action.terminal.newwhen the workspace is remote, so SSH/devcontainer/codespaces commands start on the correct machineWhy
VsCodeIde.runCommand()currently has two remote-terminal bugs:sendText(command, false)types the command but never executes itcreateTerminal()from the UI-side extension host creates a local terminal instead of a remote oneThat breaks
/cmd, Ollama/Lemonade startup helpers, and any terminal-tool fallback path in remote workspaces.Validation
npm test -- src/util/runCommandInTerminal.vitest.tsinextensions/vscodegit diff --checknpm run tsc:checkinextensions/vscodeand only hit existing repo issues unrelated to this patch:../../core/llm/llms/OpenRouter.ts: missingOPENROUTER_HEADERSexportsrc/extension.ts: missing./.buildTimestampdeclarationCloses #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.VsCodeIde.runCommand()throughrunCommandInTerminal; when remote, create terminals viaworkbench.action.terminal.newso they open on the correct host.sendText(..., true)); reuse named terminals via a small cache.Written for commit 0fe8c9c. Summary will update on new commits.