Conversation
* Only require setuptools when an initial probe fails * All dependencies come from workspace * Make commentary a little less specific * Fall back to doing a pinned version install only if the first one fails
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
📝 WalkthroughWalkthroughAdds a retry path for dependency installation: Changes
Sequence DiagramsequenceDiagram
participant LocalExec as Local Executor
participant Uv as Uv Service
participant Child as Child Process
LocalExec->>Uv: sync(cwd, env_vars)
Uv->>Child: spawn_requirements_install(...) (plain)
Child-->>Uv: exit_code (res)
alt res == 0
Uv-->>LocalExec: return success (child)
else res != 0
Uv->>Uv: should_use_legacy_setuptools_pin(cwd)?
alt true
LocalExec->>Uv: sync_with_legacy_setuptools_pin(cwd, env_vars)
Uv->>Child: spawn_requirements_install(...) (with setuptools<82)
Child-->>Uv: retry_exit_code (res)
Uv-->>LocalExec: return retry result
else false
Uv-->>LocalExec: return original error/result
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/tower-runtime/src/local.rs`:
- Around line 278-320: The code retries with sync_with_legacy_setuptools_pin
even when the initial wait_for_process returned due to cancellation; update the
if guard to skip the fallback if cancellation already happened by checking the
cancel token (e.g. require !cancel_token.is_cancelled() or equivalent) before
calling uv.should_use_legacy_setuptools_pin and spawning the retry; modify the
block around wait_for_process / res so that retry logic
(uv.sync_with_legacy_setuptools_pin, spawning retry_child drains and
wait_for_process on retry_child) only runs when not cancelled to prevent
terminate() restarts.
In `@crates/tower-uv/src/lib.rs`:
- Around line 367-373: The helper should_use_legacy_setuptools_pin currently
returns true if requirements.txt exists even when pyproject.toml is present;
change it to match sync()'s strategy selection by returning true only when
requirements.txt exists and pyproject.toml does not (i.e., check both
cwd.join("requirements.txt").exists() and !cwd.join("pyproject.toml").exists()).
Update the function body for should_use_legacy_setuptools_pin to reflect that
logic so a pyproject-driven project won't fall back to the legacy requirements
path.
In `@crates/tower-uv/tests/sync_test.rs`:
- Around line 19-21: The helper async fn wait(mut child: Child) -> i32 can
deadlock because child's stdout/stderr are piped and not consumed; before
calling child.wait().await you must drain both streams to EOF (use
child.stdout.take() and child.stderr.take() and spawn async readers or await
tokio::io::copy / read_to_end into a sink) so the pipes cannot fill and block
the child; after both drains complete, call child.wait().await and return the
exit code as before.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a3269712-45ae-4cce-bf08-bb2545f7f138
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
Cargo.tomlcrates/tower-runtime/src/local.rscrates/tower-uv/Cargo.tomlcrates/tower-uv/src/lib.rscrates/tower-uv/tests/sync_test.rs
| let mut res = wait_for_process(ctx.clone(), &cancel_token, child).await; | ||
|
|
||
| // If the requirements.txt install failed, retry with the legacy | ||
| // setuptools<82 pin. Some apps (those whose transitive deps rely on | ||
| // pkg_resources) need that pin to install successfully; we don't | ||
| // apply it by default because it conflicts with apps whose deps | ||
| // require setuptools>=82. | ||
| if res != 0 && uv.should_use_legacy_setuptools_pin(&working_dir) { | ||
| let _ = opts.output_sender.send(Output { | ||
| channel: Channel::Setup, | ||
| fd: FD::Stdout, | ||
| line: "tower: dependency install failed; retrying with setuptools<82 pin for pkg_resources compatibility".to_string(), | ||
| time: chrono::Utc::now(), | ||
| }); | ||
|
|
||
| match uv | ||
| .sync_with_legacy_setuptools_pin(&working_dir, &env_vars) | ||
| .await | ||
| { | ||
| Err(e) => { | ||
| return Err(e.into()); | ||
| } | ||
| Ok(mut retry_child) => { | ||
| let stdout = retry_child.stdout.take().expect("no stdout"); | ||
| tokio::spawn(drain_output( | ||
| FD::Stdout, | ||
| Channel::Setup, | ||
| opts.output_sender.clone(), | ||
| BufReader::new(stdout), | ||
| )); | ||
|
|
||
| let stderr = retry_child.stderr.take().expect("no stderr"); | ||
| tokio::spawn(drain_output( | ||
| FD::Stderr, | ||
| Channel::Setup, | ||
| opts.output_sender.clone(), | ||
| BufReader::new(stderr), | ||
| )); | ||
|
|
||
| res = wait_for_process(ctx.clone(), &cancel_token, retry_child).await; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Skip the fallback when cancellation already happened.
If the first sync exits with -1 because cancel_token fired, Line 285 still retries and spawns a second install. That makes terminate() restart work instead of stopping it.
Suggested fix
- if res != 0 && uv.should_use_legacy_setuptools_pin(&working_dir) {
+ if res != 0
+ && !cancel_token.is_cancelled()
+ && uv.should_use_legacy_setuptools_pin(&working_dir)
+ {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let mut res = wait_for_process(ctx.clone(), &cancel_token, child).await; | |
| // If the requirements.txt install failed, retry with the legacy | |
| // setuptools<82 pin. Some apps (those whose transitive deps rely on | |
| // pkg_resources) need that pin to install successfully; we don't | |
| // apply it by default because it conflicts with apps whose deps | |
| // require setuptools>=82. | |
| if res != 0 && uv.should_use_legacy_setuptools_pin(&working_dir) { | |
| let _ = opts.output_sender.send(Output { | |
| channel: Channel::Setup, | |
| fd: FD::Stdout, | |
| line: "tower: dependency install failed; retrying with setuptools<82 pin for pkg_resources compatibility".to_string(), | |
| time: chrono::Utc::now(), | |
| }); | |
| match uv | |
| .sync_with_legacy_setuptools_pin(&working_dir, &env_vars) | |
| .await | |
| { | |
| Err(e) => { | |
| return Err(e.into()); | |
| } | |
| Ok(mut retry_child) => { | |
| let stdout = retry_child.stdout.take().expect("no stdout"); | |
| tokio::spawn(drain_output( | |
| FD::Stdout, | |
| Channel::Setup, | |
| opts.output_sender.clone(), | |
| BufReader::new(stdout), | |
| )); | |
| let stderr = retry_child.stderr.take().expect("no stderr"); | |
| tokio::spawn(drain_output( | |
| FD::Stderr, | |
| Channel::Setup, | |
| opts.output_sender.clone(), | |
| BufReader::new(stderr), | |
| )); | |
| res = wait_for_process(ctx.clone(), &cancel_token, retry_child).await; | |
| } | |
| } | |
| } | |
| let mut res = wait_for_process(ctx.clone(), &cancel_token, child).await; | |
| // If the requirements.txt install failed, retry with the legacy | |
| // setuptools<82 pin. Some apps (those whose transitive deps rely on | |
| // pkg_resources) need that pin to install successfully; we don't | |
| // apply it by default because it conflicts with apps whose deps | |
| // require setuptools>=82. | |
| if res != 0 | |
| && !cancel_token.is_cancelled() | |
| && uv.should_use_legacy_setuptools_pin(&working_dir) | |
| { | |
| let _ = opts.output_sender.send(Output { | |
| channel: Channel::Setup, | |
| fd: FD::Stdout, | |
| line: "tower: dependency install failed; retrying with setuptools<82 pin for pkg_resources compatibility".to_string(), | |
| time: chrono::Utc::now(), | |
| }); | |
| match uv | |
| .sync_with_legacy_setuptools_pin(&working_dir, &env_vars) | |
| .await | |
| { | |
| Err(e) => { | |
| return Err(e.into()); | |
| } | |
| Ok(mut retry_child) => { | |
| let stdout = retry_child.stdout.take().expect("no stdout"); | |
| tokio::spawn(drain_output( | |
| FD::Stdout, | |
| Channel::Setup, | |
| opts.output_sender.clone(), | |
| BufReader::new(stdout), | |
| )); | |
| let stderr = retry_child.stderr.take().expect("no stderr"); | |
| tokio::spawn(drain_output( | |
| FD::Stderr, | |
| Channel::Setup, | |
| opts.output_sender.clone(), | |
| BufReader::new(stderr), | |
| )); | |
| res = wait_for_process(ctx.clone(), &cancel_token, retry_child).await; | |
| } | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@crates/tower-runtime/src/local.rs` around lines 278 - 320, The code retries
with sync_with_legacy_setuptools_pin even when the initial wait_for_process
returned due to cancellation; update the if guard to skip the fallback if
cancellation already happened by checking the cancel token (e.g. require
!cancel_token.is_cancelled() or equivalent) before calling
uv.should_use_legacy_setuptools_pin and spawning the retry; modify the block
around wait_for_process / res so that retry logic
(uv.sync_with_legacy_setuptools_pin, spawning retry_child drains and
wait_for_process on retry_child) only runs when not cancelled to prevent
terminate() restarts.
| /// Returns whether a failed `sync()` for this directory is eligible for a | ||
| /// retry via [`sync_with_legacy_setuptools_pin`]. Only applies to projects | ||
| /// driven by `requirements.txt`; pyproject-based projects manage their own | ||
| /// setuptools dependency. | ||
| pub fn should_use_legacy_setuptools_pin(&self, cwd: &Path) -> bool { | ||
| cwd.join("requirements.txt").exists() | ||
| } |
There was a problem hiding this comment.
Match the retry gate to sync()'s strategy selection.
sync() treats pyproject.toml as authoritative when both files exist, but this helper returns true for any directory with requirements.txt. That means a failed pyproject-based sync can fall back to the requirements path and install a different dependency set.
Suggested fix
pub fn should_use_legacy_setuptools_pin(&self, cwd: &Path) -> bool {
- cwd.join("requirements.txt").exists()
+ cwd.join("requirements.txt").exists() && !cwd.join("pyproject.toml").exists()
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /// Returns whether a failed `sync()` for this directory is eligible for a | |
| /// retry via [`sync_with_legacy_setuptools_pin`]. Only applies to projects | |
| /// driven by `requirements.txt`; pyproject-based projects manage their own | |
| /// setuptools dependency. | |
| pub fn should_use_legacy_setuptools_pin(&self, cwd: &Path) -> bool { | |
| cwd.join("requirements.txt").exists() | |
| } | |
| /// Returns whether a failed `sync()` for this directory is eligible for a | |
| /// retry via [`sync_with_legacy_setuptools_pin`]. Only applies to projects | |
| /// driven by `requirements.txt`; pyproject-based projects manage their own | |
| /// setuptools dependency. | |
| pub fn should_use_legacy_setuptools_pin(&self, cwd: &Path) -> bool { | |
| cwd.join("requirements.txt").exists() && !cwd.join("pyproject.toml").exists() | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@crates/tower-uv/src/lib.rs` around lines 367 - 373, The helper
should_use_legacy_setuptools_pin currently returns true if requirements.txt
exists even when pyproject.toml is present; change it to match sync()'s strategy
selection by returning true only when requirements.txt exists and pyproject.toml
does not (i.e., check both cwd.join("requirements.txt").exists() and
!cwd.join("pyproject.toml").exists()). Update the function body for
should_use_legacy_setuptools_pin to reflect that logic so a pyproject-driven
project won't fall back to the legacy requirements path.
| async fn wait(mut child: Child) -> i32 { | ||
| let status = child.wait().await.expect("wait failed"); | ||
| status.code().unwrap_or(-1) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
git ls-files | grep -E "sync_test|tests.*sync" | head -20Repository: tower/tower-cli
Length of output: 94
🏁 Script executed:
find crates -name "sync_test.rs" -type fRepository: tower/tower-cli
Length of output: 94
🏁 Script executed:
cat -n crates/tower-uv/tests/sync_test.rsRepository: tower/tower-cli
Length of output: 5655
🏁 Script executed:
find crates/tower-uv -name "*.rs" -type f | grep -v test | head -10Repository: tower/tower-cli
Length of output: 117
🏁 Script executed:
cat -n crates/tower-uv/src/lib.rs | head -150Repository: tower/tower-cli
Length of output: 6863
🏁 Script executed:
rg -n "fn venv\|fn sync\|fn sync_with_legacy_setuptools_pin" crates/tower-uv/src/lib.rsRepository: tower/tower-cli
Length of output: 41
🏁 Script executed:
wc -l crates/tower-uv/src/lib.rsRepository: tower/tower-cli
Length of output: 90
🏁 Script executed:
grep -n "fn venv\|fn sync" crates/tower-uv/src/lib.rs | head -20Repository: tower/tower-cli
Length of output: 167
🏁 Script executed:
sed -n '291,320p' crates/tower-uv/src/lib.rsRepository: tower/tower-cli
Length of output: 779
🏁 Script executed:
sed -n '321,384p' crates/tower-uv/src/lib.rsRepository: tower/tower-cli
Length of output: 2554
🏁 Script executed:
sed -n '385,430p' crates/tower-uv/src/lib.rsRepository: tower/tower-cli
Length of output: 1309
🏁 Script executed:
sed -n '420,450p' crates/tower-uv/src/lib.rsRepository: tower/tower-cli
Length of output: 716
Drain child output before waiting.
These tests call wait() on children whose stdout/stderr are piped by Uv, but never consume those streams. If uv writes enough output, the child can block on a full pipe and the test hangs.
Suggested fix
async fn wait(mut child: Child) -> i32 {
- let status = child.wait().await.expect("wait failed");
- status.code().unwrap_or(-1)
+ let output = child.wait_with_output().await.expect("wait failed");
+ output.status.code().unwrap_or(-1)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| async fn wait(mut child: Child) -> i32 { | |
| let status = child.wait().await.expect("wait failed"); | |
| status.code().unwrap_or(-1) | |
| async fn wait(mut child: Child) -> i32 { | |
| let output = child.wait_with_output().await.expect("wait failed"); | |
| output.status.code().unwrap_or(-1) | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@crates/tower-uv/tests/sync_test.rs` around lines 19 - 21, The helper async fn
wait(mut child: Child) -> i32 can deadlock because child's stdout/stderr are
piped and not consumed; before calling child.wait().await you must drain both
streams to EOF (use child.stdout.take() and child.stderr.take() and spawn async
readers or await tokio::io::copy / read_to_end into a sink) so the pipes cannot
fill and block the child; after both drains complete, call child.wait().await
and return the exit code as before.
Summary by CodeRabbit
Release
Chores
Bug Fixes
Tests