Skip to content

Prevent sudo timeouts during long installs#6

Merged
ControlNet merged 3 commits intomainfrom
feature/issue-4-sudo-heartbeat
Mar 20, 2026
Merged

Prevent sudo timeouts during long installs#6
ControlNet merged 3 commits intomainfrom
feature/issue-4-sudo-heartbeat

Conversation

@ControlNet
Copy link
Copy Markdown
Owner

@ControlNet ControlNet commented Mar 20, 2026

Summary

  • add a sudo heartbeat in run.sh so long-running privileged installs keep their cached sudo session alive
  • clean up the heartbeat safely on exit and on interrupt/terminate signals so the installer still stops correctly
  • document the keep-alive behavior in README.md

Verification

  • bash -n run.sh
  • pixi run test
  • manual mocked heartbeat run confirmed one sudo -v followed by repeated sudo -n -v
  • manual SIGTERM/SIGINT process-group tests confirmed the script exits and leaves no heartbeat process behind

Closes #4


Note

Medium Risk
Touches installer execution flow by adding a background sudo keep-alive and new signal/exit traps; a bug here could leave stray processes or affect script termination, but scope is limited to setup scripting.

Overview
Prevents long run.sh installs from failing due to sudo credential timeouts by starting a background keep-alive loop after the first sudo prompt.

Adds cleanup and signal handling (EXIT/INT/TERM) to stop the heartbeat process when the script exits or is interrupted, and documents the new keep-alive behavior in README.md.

Written by Cursor Bugbot for commit 0a88c94. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings March 20, 2026 12:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a sudo “keep-alive” mechanism to the installer so long-running installs don’t fail due to sudo credential timeout, and documents the behavior for users.

Changes:

  • Add a background sudo heartbeat plus EXIT/INT/TERM cleanup traps in run.sh.
  • Start the heartbeat near the beginning of run.sh before privileged install steps.
  • Document the new keep-alive behavior in README.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
run.sh Introduces sudo heartbeat process management and signal/exit cleanup; starts heartbeat at script startup.
README.md Documents the new sudo keep-alive behavior during long installs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread run.sh

cleanup_sudo_heartbeat() {
if [ -n "${SUDO_HEARTBEAT_PID:-}" ]; then
kill "$SUDO_HEARTBEAT_PID" >/dev/null 2>&1 || true
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

cleanup_sudo_heartbeat blindly kills whatever process currently has SUDO_HEARTBEAT_PID. If the heartbeat background job exits early (e.g., sudo -n -v fails due to sudo config) and the PID gets reused, this could terminate an unrelated process during cleanup. Consider guarding the kill by verifying the PID still belongs to a live background job started by this shell (e.g., check against jobs -p / kill -0 plus job identity) and/or wait+unset the PID after stopping the job to avoid PID reuse hazards.

Suggested change
kill "$SUDO_HEARTBEAT_PID" >/dev/null 2>&1 || true
# Only attempt to kill the process if it is still a background job of this shell.
if jobs -p 2>/dev/null | grep -q "^${SUDO_HEARTBEAT_PID}\$"; then
kill "$SUDO_HEARTBEAT_PID" >/dev/null 2>&1 || true
# Wait for the process to ensure it is reaped and to reduce PID reuse hazards.
wait "$SUDO_HEARTBEAT_PID" 2>/dev/null || true
fi
unset SUDO_HEARTBEAT_PID

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread run.sh
if [ -n "${SUDO_HEARTBEAT_PID:-}" ]; then
kill "$SUDO_HEARTBEAT_PID" >/dev/null 2>&1 || true
fi
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale PID causes double-kill on signal cleanup

Low Severity

cleanup_sudo_heartbeat never unsets SUDO_HEARTBEAT_PID after killing the process. On INT/TERM, the signal handler calls cleanup_sudo_heartbeat (first kill), resets its trap, then re-raises the signal, which causes the EXIT trap to call cleanup_sudo_heartbeat a second time with the same now-stale PID. This risks sending a signal to an unrelated process if the PID has been recycled.

Additional Locations (1)
Fix in Cursor Fix in Web

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee5ec4aa09

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread run.sh
) &
SUDO_HEARTBEAT_PID=$!

trap cleanup_sudo_heartbeat EXIT
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 Badge Stop refreshing sudo after the install completes

start_sudo_heartbeat() only tears down the keepalive on shell exit via trap cleanup_sudo_heartbeat EXIT, but run.sh later hands control to an interactive shell at run.sh:609-610. In the normal success path, the background loop from run.sh:34-39 therefore keeps calling sudo -n -v every 30 seconds for as long as the user stays in that zsh session, continuously extending the sudo ticket well after the installer is done. That turns a temporary install-time workaround into an effectively unbounded sudo grace period until the user exits the shell.

Useful? React with 👍 / 👎.

@cursor
Copy link
Copy Markdown

cursor Bot commented Mar 20, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@ControlNet
Copy link
Copy Markdown
Owner Author

All requested follow-up work is now in.

Final state before merge:

  • kept sudo alive during long installs in run.sh
  • made the heartbeat CI-safe for Ubuntu/Fedora sudo test containers by using sudo true / sudo -n true
  • tightened cleanup to avoid stale PID reuse and made repeated cleanup idempotent
  • stopped the heartbeat before the final interactive zsh, so sudo keepalive is limited to install time

Verification completed:

  • local: bash -n run.sh
  • local: pixi run test (26 tests passed)
  • manual QA: cleanup idempotence and stale-PID guard passed
  • manual QA: Ubuntu/Fedora sudo heartbeat startup passed
  • GitHub Actions: Test and Lagacy Test are green on commit 99ab778

Closes #4.

@ControlNet ControlNet merged commit 06b9a92 into main Mar 20, 2026
18 checks passed
@ControlNet ControlNet deleted the feature/issue-4-sudo-heartbeat branch March 20, 2026 13:23
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.

Keep sudo permission tips

2 participants