Skip to content

fix: make Unix updates cancellable with live progress - #18

Merged
amanthanvi merged 1 commit into
mainfrom
t3code/fix-mac-update-hangs
Sep 7, 2026
Merged

amanthanvi merged 1 commit into
mainfrom
t3code/fix-mac-update-hangs

Conversation

@amanthanvi

@amanthanvi amanthanvi commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Make managed Unix commands, captures, npm preflights, and parallel pip workers interruptible; clean up updater-owned children, helpers, and temporary resources on SIGINT/SIGTERM while preserving interactive stdin and exit statuses.
  • Add phase announcements and 30-second elapsed-time heartbeats for slow Unix work, preserving JSONL-only stdout and allowing long-running installations to continue until explicitly cancelled.
  • Stream npm and guarded pip diagnostics, improve parallel pip completion reporting, and disable background/discovery prompts appropriately under non-interactive execution.
  • Scope HOMEBREW_NO_ASK=1 to non-interactive Homebrew commands while retaining interactive confirmation guidance.
  • Update updates, execution and CLI tests, the test runner, and README/SPEC/PLAN/CHANGELOG documentation.

Checklist

  • ./scripts/lint.sh passes
  • ./scripts/test.sh passes
  • Updated docs (if behavior changed)

Summary by Sourcery

Make Unix updates cancellable and observable while preserving interactive behavior, output contracts, and reliable cleanup.

New Features:

  • Add cancellable Unix update execution with live phase announcements, elapsed-time progress, and streamed package diagnostics.
  • Preserve interactive input while supporting signal-aware cleanup and explicit cancellation statuses for long-running updates.

Bug Fixes:

  • Prevent interrupted Unix commands, captures, npm preflights, and parallel pip workers from leaving owned processes or temporary resources behind.
  • Disable inappropriate prompts during non-interactive and background package operations, including scoped Homebrew confirmation suppression.
  • Prevent inherited output descriptors from blocking command completion and retain accurate cancellation and failure propagation.

Enhancements:

  • Improve parallel pip progress reporting with per-package logs and completion notifications while preserving JSONL output behavior.

Documentation:

  • Document Unix cancellation, live progress, diagnostics, non-interactive behavior, and Homebrew confirmation handling in the README, specification, plan, and changelog.

Tests:

  • Add subprocess and pseudo-terminal coverage for signal cleanup, stdin preservation, live heartbeats and diagnostics, scoped Homebrew behavior, pip scheduling, and JSONL/logging guarantees.
  • Extend the test runner to execute the Unix execution regression suite.

- Stream npm and pip diagnostics while commands run
- Disable unattended Homebrew and pip prompts safely

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 18aa9002-825d-41bd-8176-952253df2a61


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Reviewer's Guide

This 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 execution

sequenceDiagram
    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
Loading

Flow diagram for non-interactive Unix update behavior

flowchart 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"]
Loading

File-Level Changes

Change Details Files
Centralize Unix command execution around cancellable, cleanup-aware helpers with progress reporting.
  • Interrupt managed commands and captures on SIGINT/SIGTERM while preserving exit statuses and interactive stdin.
  • Terminate and reap owned children/helpers and remove temporary command resources without broad process-name kills.
  • Announce phases and emit 30-second elapsed heartbeats at appropriate log levels without contaminating JSONL stdout.
  • Prevent later modules from running after cancellation and preserve 130/143 signal-derived exits.
updates
SPEC.md
README.md
PLAN.md
Make npm and pip update workflows observable, non-blocking, and safer under parallel execution.
  • Stream npm stderr and guarded pip diagnostics live while retaining logs for retries and failures.
  • Schedule parallel pip workers as slots become available, report completions, and preserve per-package logs and statuses.
  • Disable pip prompts for background installs and for discovery/planning in non-interactive mode.
updates
SPEC.md
README.md
CHANGELOG.md
tests/test_cli.sh
tests/test_execution.py
Scope Homebrew unattended behavior and retain interactive confirmation guidance.
  • Set HOMEBREW_NO_ASK=1 only around non-interactive brew commands.
  • Keep interactive prompts enabled and explain the confirmation behavior to users.
updates
SPEC.md
README.md
PLAN.md
CHANGELOG.md
tests/test_execution.py
Expand regression coverage and integrate execution tests into the standard test runner.
  • Add isolated subprocess, signal, process-group, pseudo-terminal, heartbeat, streaming-output, descriptor-inheritance, pip scheduling, and prompt-behavior tests.
  • Update existing assertions for streamed retry diagnostics and non-interactive pip flags.
  • Run the new Python execution suite from scripts/test.sh.
tests/test_execution.py
tests/test_cli.sh
scripts/test.sh
Document the new Unix cancellation, progress, diagnostics, and non-interactive semantics.
  • Update user and behavioral specifications, implementation plan, and changelog without changing public flags, JSONL event types, or summary fields.
README.md
SPEC.md
PLAN.md
CHANGELOG.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@amanthanvi
amanthanvi merged commit 5b4db4d into main Sep 7, 2026
10 checks passed
@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR introduces managed Unix command execution with cancellation, phase announcements, periodic progress, live npm/pip diagnostics, dynamic parallel pip scheduling, and scoped non-interactive behavior.

  • Routes human progress away from JSONL stdout and adds interrupt-aware command/capture helpers.
  • Streams npm and guarded pip logs while preserving command outcomes and temporary-resource cleanup.
  • Adds Homebrew and pip prompt controls for unattended execution.
  • Adds subprocess regression coverage and updates the user-facing execution contract.
  • Cancellation remains incomplete for subprocesses spawned by managed package tools because cleanup targets only direct PIDs.

Confidence Score: 4/5

This PR is not yet safe to merge because parent-only cancellation can leave updater-spawned installation subprocesses running after the updater exits.

The managed execution layer records and terminates only each command's direct PID, so descendants created by npm lifecycle scripts or pip build backends are outside cleanup and may continue mutating the environment after cancellation.

Files Needing Attention: updates

Important Files Changed

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
Loading

Fix all with Greploop Fix All in Codex Fix All in Claude Code Fix All in Cursor

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

Comment thread updates
Comment on lines +4059 to 4061
for pid in ${COMMAND_PIDS[@]+"${COMMAND_PIDS[@]}"}; do
kill "$pid" 2>/dev/null || true
done

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Fix in Codex Fix in Claude Code Fix in Cursor

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant