Terminal suggest spawns runaway bash processes when npm/yarn package.json lookup reaches /
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
Does this issue occur when all extensions are disabled?: No. It is caused by the built-in `vscode.terminal-suggest` extension/provider; disabling that provider stops the issue.
- VS Code Version: 1.129.1, commit `8a7abeba6e03ea3af87bfbce9a1b7e48fed567b8`, x64
- OS Version: Linux x64, Debian bookworm/sid compatible environment, kernel `5.15.152.bsk.4-amd64`
Steps to Reproduce:
1. Use VS Code Server / Remote on Linux with terminal suggest enabled. This is enabled by default via `terminal.integrated.suggest.enabled`.
2. Open a terminal in a directory that has no `package.json` in that directory or in any parent directory up to `/`.
3. Trigger npm or yarn terminal suggestions, for example while typing an npm/yarn command that requests package script or dependency completions.
4. Observe child processes spawned by the extension host like:
```bash
bash -c "until [[ -f package.json ]] || [[ $PWD = ' / ' ]]; do cd ..; done; cat package.json"
```
5. The processes do not terminate after reaching `/`. Repeated suggestion requests can accumulate many `bash` processes and cause high CPU usage.
Expected:
The package.json lookup should stop at the filesystem root and return no suggestions when no `package.json` is found.
Actual:
The root check compares `$PWD` with `' / '` instead of `'/'`:
```bash
[[ $PWD = ' / ' ]]
```
When the loop reaches `/`, `cd ..` is a no-op, `$PWD` remains `/`, and the condition never becomes true. The command loops forever:
```bash
until [[ -f package.json ]] || [[ $PWD = ' / ' ]]; do cd ..; done; cat package.json
```
This came from the bundled `vscode.terminal-suggest` extension. In the installed VS Code Server bundle I found the same command under:
```text
server/extensions/terminal-suggest/dist/terminalSuggestMain.js
```
The corresponding current source locations are:
```text
extensions/terminal-suggest/src/completions/npm.ts
extensions/terminal-suggest/src/completions/yarn.ts
```
Regression note:
PR #240128 originally added the upstream npm/yarn specs with the correct check:
```bash
[[ $PWD = '/' ]]
```
The bad spacing appears to have been introduced later in PR #284595 (`Move npm spec out of upstream`) during the double-quote to single-quote conversion:
- npm: commit `e0e5e8b489a935bd4299d69333bcb7036b902338`
- yarn: commit `0be0a9efb8a34c1b4f547d8b6d941694c438e002`
A minimal fix would be to change both generated commands back to:
```bash
until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json
```
There may also be a process cleanup issue: the terminal-suggest execution path appears to apply a timeout around the promise, but the spawned child process is not killed when the timeout wins. Fixing the root check addresses this specific infinite loop, but cancelling/killing timed-out child processes would make this class of bug less severe.
Workaround:
Disable the built-in provider:
```json
"terminal.integrated.suggest.providers": {
"vscode.terminal-suggest": false
}
```
or disable terminal suggest entirely:
```json
"terminal.integrated.suggest.enabled": false
```
Existing issue search:
I searched open and closed VS Code issues for the exact command/root-check terms, `vscode.terminal-suggest`, `terminal-suggest package.json CPU`, the relevant commits, and PR #284595. I did not find a direct duplicate.
Related but different issues include #256746, which also involves terminal-suggest spawning many processes, but that report is for PowerShell `Get-Command` completions rather than the npm/yarn `package.json` lookup loop.
Contributor guide
Assessment
This issue has not been assessed yet.