fix: make Unix updates cancellable with live progress - #18
Conversation
- Stream npm and pip diagnostics while commands run - Disable unattended Homebrew and pip prompts safely
There was a problem hiding this comment.
Sorry @amanthanvi, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 18 hours and 55 minutes by commenting @sourcery-ai review. Upgrade to get a review now.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 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 |
Reviewer's GuideThis PR refactors Unix update execution to support signal-safe cancellation, owned-process cleanup, live phase/progress and package diagnostics, while preserving interactive input, exit semantics, JSONL output, and adding comprehensive subprocess-based regression coverage. Sequence diagram for cancellable Unix update executionsequenceDiagram
actor User
participant Updates
participant ManagedCommand
participant ChildProcess
participant OutputHelper
Updates->>ManagedCommand: run_command()
ManagedCommand->>ChildProcess: start with stdin preserved
ManagedCommand->>OutputHelper: start diagnostics/progress
loop while command runs
ManagedCommand->>ChildProcess: wait interruptibly
ManagedCommand->>OutputHelper: emit phase or elapsed progress
end
User-->>ManagedCommand: SIGINT or SIGTERM
ManagedCommand->>ChildProcess: terminate owned children
ManagedCommand->>OutputHelper: stop and clean up
ManagedCommand-->>Updates: return 130 or 143
Flow diagram for non-interactive Unix update behaviorflowchart TD
Start["Unix update"] --> Mode{"--non-interactive?"}
Mode -->|Yes| ScopedEnv["Set HOMEBREW_NO_ASK=1 for brew command"]
Mode -->|Yes| DisablePrompts["Disable discovery, planning, and background pip prompts"]
Mode -->|No| Interactive["Retain stdin and Homebrew confirmation guidance"]
ScopedEnv --> Execute["Run managed commands with live diagnostics"]
DisablePrompts --> Execute
Interactive --> Execute
Execute --> Cancel{"SIGINT or SIGTERM?"}
Cancel -->|No| Complete["Preserve exit status and JSONL stdout"]
Cancel -->|Yes| Cleanup["Clean owned children, helpers, and temporary resources"]
Cleanup --> Exit["Exit 130 or 143"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
| Filename | Overview |
|---|---|
| updates | Adds managed execution, progress, streaming, cancellation, and pip scheduling, but direct-PID cleanup can leave command descendants running. |
| tests/test_execution.py | Adds broad subprocess, signal, TTY, streaming, and scheduler regressions, though cancellation of spawned descendants is not covered. |
| tests/test_cli.sh | Updates npm diagnostic and non-interactive pip expectations to match the new behavior. |
| scripts/test.sh | Adds the new Python execution regression suite to the standard test runner. |
| README.md | Documents Unix cancellation, progress, streaming diagnostics, and non-interactive behavior. |
| SPEC.md | Extends the execution contract for cancellation, progress, Homebrew prompts, and npm/pip diagnostics. |
Sequence Diagram
sequenceDiagram
participant U as User or supervisor
participant R as updates
participant C as Managed command
participant D as Command descendant
U->>R: SIGINT or SIGTERM
R->>C: TERM direct recorded PID
R->>C: KILL after grace period
R-->>U: Exit 130 or 143
Note over D: Not targeted by cleanup
D->>D: May continue installation work
Prompt To Fix All With AI
### Issue 1
updates:4059-4061
**Descendants survive cancellation**
When npm lifecycle scripts or pip build backends spawn subprocesses, this cleanup only terminates the direct PID stored in `COMMAND_PIDS`. Because it does not terminate the command's process group or otherwise track descendants, those subprocesses can survive a parent-only SIGINT or SIGTERM and continue modifying the environment after `updates` exits with a cancellation status.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "fix: make Unix updates cancellable with ..." | Re-trigger Greptile
| for pid in ${COMMAND_PIDS[@]+"${COMMAND_PIDS[@]}"}; do | ||
| kill "$pid" 2>/dev/null || true | ||
| done |
There was a problem hiding this comment.
Descendants survive cancellation
When npm lifecycle scripts or pip build backends spawn subprocesses, this cleanup only terminates the direct PID stored in COMMAND_PIDS. Because it does not terminate the command's process group or otherwise track descendants, those subprocesses can survive a parent-only SIGINT or SIGTERM and continue modifying the environment after updates exits with a cancellation status.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: updates
Line: 4059-4061
Comment:
**Descendants survive cancellation**
When npm lifecycle scripts or pip build backends spawn subprocesses, this cleanup only terminates the direct PID stored in `COMMAND_PIDS`. Because it does not terminate the command's process group or otherwise track descendants, those subprocesses can survive a parent-only SIGINT or SIGTERM and continue modifying the environment after `updates` exits with a cancellation status.
**Knowledge Base Used:**
- [Update command execution](https://app.greptile.com/amanthanvi/-/custom-context/knowledge-base/amanthanvi/updates/-/docs/update-command.md)
- [Test automation](https://app.greptile.com/amanthanvi/-/custom-context/knowledge-base/amanthanvi/updates/-/docs/test-automation.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
SIGINT/SIGTERMwhile preserving interactive stdin and exit statuses.HOMEBREW_NO_ASK=1to non-interactive Homebrew commands while retaining interactive confirmation guidance.updates, execution and CLI tests, the test runner, and README/SPEC/PLAN/CHANGELOG documentation.Checklist
./scripts/lint.shpasses./scripts/test.shpassesSummary by Sourcery
Make Unix updates cancellable and observable while preserving interactive behavior, output contracts, and reliable cleanup.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: