Repository navigation
Description
A Note from the User
This is a message from me, a human user. I asked AI to handle the rest of the issue report.
I tried to patch the problems I encountered while using Zoo Code myself. The patches may be incomplete or may not work correctly. Please, the bug fix team, judge them directly. I hope Zoo Code continues to grow and mature.
Problem
After long sessions (30+ minutes), execute_command repeatedly returns "Command failed to execute in terminal due to a shell integration error." The failure rate increases dramatically as the session progresses.
Context
- OS: Windows 11, PowerShell 5.1
- Zoo Code Version: v3.63.100188
- API Provider: OpenAI Compatible
- Model: mimo-v2.5-pro
- Affected: Multiple projects (ZooChat, Emebala, myownsettings)
Reproduction Steps
- Open Zoo Code and execute multiple commands (works normally)
- Maintain session for 30+ minutes with repeated command execution
- Create multiple terminal instances
- Subsequent commands trigger "shell integration error"
Expected Result
Commands should execute successfully.
Actual Result
"Command failed to execute in terminal due to a shell integration error" is returned. Retrying the same command does not help.
Relevant Logs
[PATCH] execa fallback attempted. Original message: Command failed to execute in terminal due to a shell integration error.
Root Cause Analysis
The getOrCreateTerminal() method at byte offset 14,562,575 in extension.js reuses dead terminals:
static async getOrCreateTerminal(e, r, a="vscode") {
let o = this.getAllTerminals(),
s = a === "vscode" ? Pn.getReuseKey() : a,
n;
return r && (n = o.find(u =>
u.busy || u.taskId !== r || u.provider !== a || u.reuseKey !== s ? !1 : ...
));
// If busy=false and taskId/reuseKey match, dead terminals are also reused
}When a terminal loses its internal state (PID gone, shell integration timeout), Zoo Code still reuses it because taskId + reuseKey match.
Minified Alias Mapping (extension.js)
| Original | Minified | Byte Offset |
|---|---|---|
selectTerminalProvider |
MZs |
14,717,666 |
canRetryShellIntegrationError |
BZs |
14,717,646 |
ShellIntegrationError |
JM |
14,717,640 |
executeCommandInTerminal |
zyi |
14,720,177 |
vscodeTerminal |
Pn |
12,889,514 |
TerminalRegistry |
h0 |
14,560,517 |
Applied Patch
We applied a community patch that adds a forceNewTerminal option:
Change 1: MZs() — add forceNewTerminal parameter
function MZs(t, e) {
let r = !t && Pn.isActiveShellCmdExe();
return { terminalProvider: t || r || e ? "execa" : "vscode", isCmdExeFallback: r }
}Change 2: zyi() — add forceNewTerminal to destructure
async function zyi(t, {executionId: e, command: r, customCwd: a,
terminalShellIntegrationDisabled: o = !0,
forceNewTerminal: __fn = !1,
commandExecutionTimeout: s = 0, agentTimeout: n = 0}) {Change 3-6: Pass forceNewTerminal through the call chain
let Y = await h0.getOrCreateTerminal(c, t.taskId, E, __fn);
// In catch/retry branches:
await zyi(r, {...y, terminalShellIntegrationDisabled: !0, forceNewTerminal: !0})Change 7: Pn constructor — explicit PowerShell shellPath fallback
let explicitShell = process.platform === "win32"
? (process.env.SystemRoot || "C:\\Windows") + "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
: (process.env.SHELL || "/bin/bash");
n.shellPath = explicitShell;Patch Verification
| Check | Result |
|---|---|
Node.js --check |
✅ PASSED |
| Size change | +365 bytes |
Recommended Official Fix
Add terminal validity check in getOrCreateTerminal():
static async getOrCreateTerminal(e, r, a="vscode", forceNew=false) {
if (forceNew) return this.createTerminal(e, a);
let o = this.getAllTerminals(),
s = a === "vscode" ? Pn.getReuseKey() : a, n;
if (r) {
n = o.find(u => {
if (u.busy || u.taskId !== r || u.provider !== a || u.reuseKey !== s) return false;
if (u.terminal?.exitStatus !== undefined) return false;
return true;
});
}
return n || this.createTerminal(e, a);
}
Activity
myk1yt commentedon Jun 24, 2026
Likely Resolved via Inline Terminal PowerShell Fix (#705)
Analysis
This issue reports that after long sessions (30+ minutes),
execute_commandrepeatedly returns "shell integration error" becausegetOrCreateTerminal()reuses dead terminals whose internal state (PID, shell integration) has expired.The original problem code (
extension.jsoffset ~14,562,575):Why Inline Terminal ON resolves this:
When "Use Inline Terminal (recommended)" is ON, the
execaprovider is used instead of the VS Code integrated terminal:With Inline Terminal ON:
Related Fix
Issue #705 was resolved by making the Inline Terminal use PowerShell on Windows instead of cmd.exe:
With both Inline Terminal ON and PowerShell working correctly, the conditions that trigger #704 (dead terminal reuse + shell integration dependency) are eliminated.
Recommendation
We recommend using Inline Terminal ON with the PowerShell fix from #705. This sidesteps the
getOrCreateTerminal()dead-reuse issue entirely. However, if the VS Code terminal mode is still needed, theexitStatuscheck ingetOrCreateTerminal()should be added as described in the original issue.gh311 commentedon Dec 5, 2026
Reproduced at the logic level and fixed in PR #2862.
Root cause:
TerminalRegistry.getOrCreateTerminal()filtered candidates only throughisClosed(), which readsexitStatus !== undefined— a value VS Code sets only when the close event fires. A terminal whose shell died in a long session (integration probe dead/stale) keepsexitStatus === undefined, so it passed every check (busy=false, matchingtaskId/reuseKey) and was re-selected for every following command; each command replayed the 5 s shell-integration timeout and failed. A unit-level repro on the pre-fix tree selects the identical dead terminal object back:expected Terminal{...} not to be Terminal{...} — Compared values have no visual difference.Fix (selection/revalidation scope only): terminals now track whether their integration was ever confirmed;
getOrCreateTerminal()revalidates idle candidates before reuse and recycles failures (dispose + remove viaTerminalRegistry.recycleTerminal()), so the freed selection spawns a replacement. Cold terminals (never integrated) and busy terminals are never recycled, so slow-starting shells and in-flight commands are unaffected.Evidence:
docs/architecture/tla/TerminalReuse.tla:TerminalReuse.cfgpasses (121 distinct states); sabotage cfgsNoRecycleSweep/NoStallSweepeach failNoDeadSelection(the model-level form of this repro: spawn → activate → die → reuse).src/integrations/terminal/__tests__/TerminalRegistry.spec.ts; 5 verified RED on the pre-fix tree, then green after the fix; the 2 guard tests sabotage-verified (seen-guard removal → 3 failures; busy-guard removal → busy test fails).test:core5316 passed,test:api6417 passed, scoped vitest 26 passed,tsc --noEmitclean,eslint --max-warnings=0clean,prettier --checkclean.The fix is designed independently of the
forceNewTerminalpatch quoted in the issue body: that patch required a caller opt-in per command and itsexitStatuscheck already exists on this tree viaisClosed(); the registry now carries its own liveness signal, so recovery needs no per-call flag.gh311 commentedon Dec 5, 2026
@coderabbitai review
coderabbitai commentedon Dec 5, 2026
Analysis chain
Script executed:
Length of output: 37592
Script executed:
Length of output: 66900
Script executed:
Length of output: 41583
@gh311I found two issues in PR#2862:A stale integration object can still cause repeated failures.
Terminal.ts, Line 167 marks integration as lost only when the initial wait times out. IfshellIntegrationremains present but the execution stream never starts,TerminalProcess.ts, Line 94 emitsno_shell_integrationwithout setting that flag. The registry can then select the same terminal again. Handle this failure signal and add a regression test. Do not automatically retry a command that was submitted.Recycling can discard unread output.
TerminalRegistry.ts, Line 228 sweeps every idle terminal, including terminals from other tasks. Removing one also removes access to itscompletedProcessesoutput beforegetEnvironmentDetails()can read it. Preserve unread output when recycling, and test a terminal with pending output.I reviewed the code at commit
7ff5d481. I did not run the tests or reproduce the failure in VS Code.Learnings used
You are interacting with an AI system.
fix(terminal): record stream-start failures and keep unread output on…
fix(terminal): keep a terminal with a running submitted execution out…