fix: detect-from-terminal no longer writes probe fragment to dbtPythonPathOverride
Problem
The Detect Python from terminal command could write a fragment of its own probe command into dbt.dbtPythonPathOverride, after which every dbt/pip invocation failed with Command not found: "); print(sys.executable); print(".
detectPythonFromShell runs a Python one-liner in the integrated terminal via the shell-integration API and recovers sys.executable by searching the captured output for unique markers:
python3 -c 'import sys; __import__("dbt"); print("__DBT_DETECT_START__"); print(sys.executable); print("__DBT_DETECT_END__")'
VS Code shell integration echoes the executed command line into the same stream that executeInTerminal reads back. Because the markers were embedded as literal strings, indexOf("__DBT_DETECT_START__") / indexOf("__DBT_DETECT_END__") matched the echoed command instead of stdout, and the extracted "path" was the code between them:
"); print(sys.executable); print("
That value was then offered as the interpreter ("Found Python with dbt at: …") and persisted to dbt.dbtPythonPathOverride. This surfaced most visibly with a Homebrew Python (which also can't pip install globally under PEP 668), but the parsing defect is not platform-specific — it triggers whenever the shell echoes the command into the integration stream, and it mis-fires even when dbt is importable (the echo match precedes the real stdout markers).
Worse, once a machine has persisted that garbage value, it stays broken on every subsequent dbt/pip call until the user clears the setting by hand — the write-side fix below prevents new poisoning but cannot recover an already-affected install.
Fix
1. Stop producing the bad value (detectPythonFromShell / executeInTerminal)
- Break the self-referential marker. Emit each marker as two string literals joined at runtime in Python (
"__DBT_DETE" + "CT_START__"), so the contiguous token only ever appears in stdout — never in the echoed command. The marker search can no longer match the echo. - Validate before persisting. Only accept an absolute path that exists on disk; otherwise return
undefined. Shell noise or a leaked echo can never again be written as the interpreter path. - Clear the 10s race timeout once the read resolves, so it doesn't keep the event loop alive after each probe.
2. Stop consuming a bad value, and self-heal already-poisoned configs (get pythonPath())
The pythonPath getter previously trusted dbt.dbtPythonPathOverride unconditionally. It now validates the override via isUsableInterpreterOverride:
- accept a bare command resolved via
PATH(python,python3,python3.11), or a filesystem path (absolute or containing a separator) that exists on disk; - reject anything else (shell noise, a leaked probe fragment),
warn(..., /* sendTelemetry */ true)so recovery is observable in telemetry, and fall back to normal interpreter detection.
This recovers the machines already carrying a poisoned setting on next launch, with no manual intervention, while leaving every legitimate override (bare command or real path) untouched.
Evidence
Parser layer — real shell, not platform-specific
The only VS-Code-specific link in the chain is "shell integration's read() includes the command echo" — which is ordinary PTY echo. Driving a real interactive bash over a PTY, typing the exact probe commands, and running the real marker-parser over the captured stream:
BEFORE FIX (literal markers, no validation)
[OLD] python has dbt: false -> command echoed into stream: yes -> result: "); print(sys.executable); print("
[OLD] python has dbt: true -> command echoed into stream: yes -> result: "); print(sys.executable); print("
AFTER FIX (split markers + absolute-path validation)
[NEW] python has dbt: false -> echo only in split form -> result: undefined
[NEW] python has dbt: true -> result: /path/to/.venv/bin/python3
The "); print(sys.executable); print(" value reproduced above is the exact string reported from the field.
End-to-end — docker code-server, poisoned setting
A code-server container (jaffle-shop-duckdb, dbt 1.11.11) with dbt.dbtPythonPathOverride set to the exact leaked fragment "); print(sys.executable); print(":
Before — the poisoned value is spawned verbatim, dbt detection fails:
DBTCoreDetectionError:Detection failed: Command not found: ""); print(sys.executable); print(""...
Starting python bridge [{"pythonPath":"\"); print(sys.executable); print(\"", ...}]
Error: spawn "); print(sys.executable); print(" ENOENT
/bin/sh: 1: ); print(sys.executable); print(: not found

After — the same poisoned value is ignored and logged, detection falls back to the real interpreter, dbt initializes (target/ compiled, status bar healthy), and 0 spawn/detection errors remain:
[warning] pythonEnvironment:pythonPath:Ignoring invalid dbtPythonPathOverride (not a usable interpreter): "); print(sys.executable); print("
[debug] Starting python bridge [{"pythonPath":"/bin/python3","cwd":"/home/coder/jaffle-shop-duckdb", ...}]

Tests
src/test/suite/pythonEnvironmentDetect.test.ts (10 cases, all passing):
Detection probe (detectPythonFromShell):
- returns the interpreter path when dbt is importable
- returns
undefined(never a probe fragment) when only the command echo is captured - rejects the exact probe-fragment value even if it lands between markers
- rejects a non-absolute value
- rejects an absolute path that doesn't exist on disk
Read-side override guard (get pythonPath()):
- keeps a valid absolute interpreter path that exists on disk
- keeps a bare command that resolves via
PATH(e.g.python3) - ignores the leaked probe-fragment value and falls back, with telemetry
- ignores an absolute override path that does not exist on disk
- falls back without warning when no override is set
tsc --noEmit, ESLint, and Prettier all clean.
Note
A separate follow-up tracks proper support for installing dbt into a PEP 668 externally-managed (Homebrew) Python — that install path is out of scope here.
🤖 Generated with Claude Code
Walkthrough
This PR hardens Python environment detection by obfuscating probe command markers to prevent matching echoed terminal output, validating extracted paths are absolute and exist on disk, refactoring terminal timeout management, and adding comprehensive regression tests covering all hardening behaviors.
Changes
Python Environment Detection Hardening
| Layer / File(s) | Summary |
|---|---|
Probe Command Obfuscation src/dbt_client/pythonEnvironment.ts |
The probe Python code now splits marker string literals into two runtime-joined pieces, preventing literal markers from appearing contiguously in the command text. OS-specific quoting handles POSIX and Windows/PowerShell environments. |
Interpreter override & extraction validation src/dbt_client/pythonEnvironment.ts |
Added imports for existsSync and isAbsolute. pythonPath now accepts dbtPythonPathOverride only when it matches a command-like token or is a separator-containing/absolute path that exists. Extracted between-marker values from terminal output must be absolute and exist on disk; otherwise they are rejected (return undefined). |
Terminal Timeout Resource Management src/dbt_client/pythonEnvironment.ts |
Timeout handling in executeInTerminal now uses an explicit timer variable (setTimeout) and clears it in a finally block after Promise.race completes to prevent lingering timers. |
Regression Test Suite src/test/suite/pythonEnvironmentDetect.test.ts |
New Jest tests with a mocked terminal that streams output in two chunks validate: successful detection when markers and sys.executable are captured; rejection when only echoed command appears; rejection of exact probe fragments and invalid extracted values (non-absolute or non-existent); and override acceptance/telemetry behaviors. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
- mdesmet
- saravmajestic
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title 'fix: detect-from-terminal no longer writes probe fragment to dbtPythonPathOverride' clearly and concisely summarizes the main fix: preventing a probe marker fragment from being incorrectly persisted. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Description check | ✅ Passed | The pull request description thoroughly covers the problem, solution, testing approach, and includes detailed evidence with examples. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
📝 Generate docstrings
- [ ] Create stacked PR
- [ ] Commit on current branch
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Commit unit tests in branch
fix/detect-python-terminal-marker-echo
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Bundle Size Report
darwin-arm64: 74.1 MB
| Category | Size | Compressed | Files |
|---|---|---|---|
| Webview JS bundles | 36.2 MB | 12.3 MB | 346 |
| Native: altimate-core | 35.1 MB | 14.0 MB | 1 |
| Media assets | 29.6 MB | 25.8 MB | 91 |
| Native: zeromq | 20.5 MB | 8.2 MB | 15 |
| Webview images | 15.3 MB | 12.2 MB | 18 |
| Extension backend (JS) | 2.7 MB | 0.6 MB | 1 |
| Python packages | 2.0 MB | 0.5 MB | 95 |
| Native: other node_modules | 1.0 MB | 0.2 MB | 139 |
| Webview CSS | 0.8 MB | 0.1 MB | 2 |
| Webview other | 0.5 MB | 0.1 MB | 5 |
| Other | 0.1 MB | 26 KB | 15 |
| Total | 143.7 MB | 74.0 MB | 728 |
linux-x64: 75.8 MB
| Category | Size | Compressed | Files |
|---|---|---|---|
| Native: altimate-core | 41.8 MB | 15.1 MB | 1 |
| Webview JS bundles | 36.2 MB | 12.3 MB | 346 |
| Media assets | 29.6 MB | 25.8 MB | 91 |
| Native: zeromq | 21.9 MB | 8.7 MB | 16 |
| Webview images | 15.3 MB | 12.2 MB | 18 |
| Extension backend (JS) | 2.7 MB | 0.6 MB | 1 |
| Python packages | 2.0 MB | 0.5 MB | 95 |
| Native: other node_modules | 1.0 MB | 0.2 MB | 139 |
| Webview CSS | 0.8 MB | 0.1 MB | 2 |
| Webview other | 0.5 MB | 0.1 MB | 5 |
| Other | 0.1 MB | 26 KB | 15 |
| Total | 151.8 MB | 75.7 MB | 729 |
win32-x64: 76.7 MB
| Category | Size | Compressed | Files |
|---|---|---|---|
| Native: altimate-core | 50.3 MB | 16.2 MB | 1 |
| Webview JS bundles | 36.2 MB | 12.3 MB | 346 |
| Media assets | 29.6 MB | 25.8 MB | 91 |
| Native: zeromq | 20.0 MB | 8.1 MB | 15 |
| Webview images | 15.3 MB | 12.2 MB | 18 |
| Extension backend (JS) | 2.7 MB | 0.6 MB | 1 |
| Native: other node_modules | 2.3 MB | 0.7 MB | 147 |
| Python packages | 2.0 MB | 0.5 MB | 95 |
| Webview CSS | 0.8 MB | 0.1 MB | 2 |
| Webview other | 0.5 MB | 0.1 MB | 5 |
| Other | 0.1 MB | 26 KB | 15 |
| Total | 159.6 MB | 76.6 MB | 736 |
✅ Tests — All Passed
cc @ralphstodomingo