Skip to content

fix(pip): fall back to uv when pip is on PATH but cannot start - #4055

Closed
obrienciaran wants to merge 4 commits into
rtk-ai:developfrom
obrienciaran:fix/pip-dead-shim-uv-fallback-4054
Closed

obrienciaran wants to merge 4 commits into
rtk-ai:developfrom
obrienciaran:fix/pip-dead-shim-uv-fallback-4054

Conversation

@obrienciaran

@obrienciaran obrienciaran commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

use_uv only asked whether a pip file exists on PATH and doesn't check if it can actually run. Right now, a stale console script whose shebang names a deleted interpreter passes the check, so rtk exec'd it, gets ENOENT, and never tries uv; even though the same machine works via uv pip once the dead script is removed.

Keep the routing rule from #3389 (pip wins whenever it is present) but retry through uv pip when the spawn itself fails with NotFound and uv is available. Nothing ran on a spawn failure, so the retry is safe for install too. A one-line stderr notice says why the switch happened.

Fixes #4054

Summary

  • rtk pip ... now retries via uv pip when pip is on PATH but the OS can't start it (e.g. a stale shebang). Previously it failed with a bare "No such file or directory" and never tried uv.
  • Routing is unchanged otherwise. A working pip still wins whenever present (pip install silently installed nothing on 0.40.0 (uv routed without a venv); regression test + docs still describe the old rule #3389). The fallback only kicks in after a failed spawn, so the normal path costs nothing new. When it does trigger, the cost is one failed exec (which was going to happen anyway), one extra PATH lookup for uv, and the uv pip run itself; plus one extra stderr line in the output.
  • Moved subcommand dispatch into a dispatch() helper, and added is_spawn_not_found().
  • Also updated the stale "Auto-detect uv" line in docs/contributing/ARCHITECTURE.md.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test
    • clean, 0 clippy warnings. Three new unit tests, including a #[cfg(unix)] one that writes a real dead-shebang script to a tempdir, spawns it, and checks it's classified as not-found.
  • Manual testing with a sandbox PATH and a stub uv that echoes its arguments:
    • Dead pip + uv: prints rtk: pip is on PATH but could not be started — falling back to uv pip, then pip list and pip install succeed via uv (exit 0).
    • No pip + uv: unchanged, falls back the same as always.
    • Dead pip, no uv: same as alway, error kept, exit 1.
    • Working pip + uv: pip runs, uv is never called

Important: All PRs must target the develop branch (not master).
See CONTRIBUTING.md for details.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working pip uv-fallback labels Sep 14, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes pip command routing so that when pip is present on PATH but fails to spawn (e.g. a stale console script with a dangling shebang), rtk now retries via uv pip instead of failing outright. Subcommand dispatch was refactored into a shared dispatch() helper, and a new is_spawn_not_found() helper detects ENOENT-style spawn failures to trigger the fallback safely.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4054


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@obrienciaran

Copy link
Copy Markdown
Contributor Author

Both this and #4053 both touch src/cmds/python/pip_cmd.rs near run() and will conflict. Whichever merges second needs a rebase. Both are mine; ping me once one lands and I'll rebase the other.

`use_uv` only asked whether a `pip` file exists on PATH. A stale console
script whose shebang names a deleted interpreter passes that check, so
rtk exec'd it, got ENOENT, and never tried `uv` — even though the same
machine works via `uv pip` once the dead script is removed.

Keep the routing rule from rtk-ai#3389 (pip wins whenever it is present) but
retry through `uv pip` when the spawn itself fails with NotFound and uv
is available. Nothing ran on a spawn failure, so the retry is safe for
`install` too. A one-line stderr notice says why the switch happened.

Fixes rtk-ai#4054
@obrienciaran
obrienciaran force-pushed the fix/pip-dead-shim-uv-fallback-4054 branch from 124aec5 to ce98db3 Compare September 28, 2026 00:36
@obrienciaran

obrienciaran commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@KuSh Thanks for approving #4053! Maybe you could take a quick look at this related PR too? 🙏

Basically this PR introduces a new fallback. If pip is on the PATH but broken (for example it points at a Python that's been deleted), rtk now tries uv pip instead of just failing.

Note: rebased since #4053 was merged.

@KuSh

KuSh commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the detailed write-up in #4054 and for the tests here. I'd rather not take this one, because it extends a mechanism that should go away instead of fixing it.

Measured against develop @720d2764, with stub pip/uv that record their argv (rtk rewrite first, then the rewritten command):

Typed PATH develop runs this PR runs without rtk
pip install requests dead pip + uv nothing, exit 1 uv pip install requests, exit 0 pip fails to start
uv pip list dead pip + uv nothing, exit 1 uv pip list uv pip list
uv pip list working pip + uv pip list pip list uv pip list

The first row runs a program the caller did not name. For install it writes into whatever environment uv discovers, which is the divergence #3389 reverted: nothing ran before the retry, but the target environment still changes. The second row is the real bug in #4054, and the third row shows it's only fixed when pip happens to be broken. The cause is upstream of pip_cmd: the rewriter turns uv pip into rtk pip, and the handler then has to guess the runner back.

#4315 tracks fixing that once for every runner: pick the filter from the final tool and run the command as typed. I've added #4054's case there. With that in place uv pip runs uv, a dead pip fails the same way it does without rtk, and the existing "no pip on PATH" fallback can go too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working pip uv-fallback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A pip that exists but can't run blocks the uv fallback

2 participants