Skip to content

Take machine offline and notify when dpkg is corrupted during prereq install - #5267

Open
DrewScoggins wants to merge 1 commit into
dotnet:mainfrom
DrewScoggins:dpkg-offline-detection
Open

Take machine offline and notify when dpkg is corrupted during prereq install#5267
DrewScoggins wants to merge 1 commit into
dotnet:mainfrom
DrewScoggins:dpkg-offline-detection

Conversation

@DrewScoggins

@DrewScoggins DrewScoggins commented Jul 29, 2026

Copy link
Copy Markdown
Member

Generated by Copilot

Summary

Some prerequisite-install failures are not transient but indicate a broken host. The canonical case is the apt/dpkg database getting stuck in an interrupted state:

E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

Today this just fails the run repeatedly on the same bad machine. This PR detects that specific state during prerequisite installation and:

  • Takes the machine out of Helix rotation by creating the offline sentinel file in $HELIX_CONFIG_ROOT (Helix stops sending work to a machine with that file).
  • Notifies the team by writing a semaphore blob named after the machine to a new offline-machines container in pvscmdupload.

The semaphore blob is cleared only when the machine next uploads results successfully, so a machine has to actually be working to have its semaphore removed.

The notification write is best effort: it first uses the already-available azure libraries, then falls back to bootstrapping a throwaway venv with the dependencies, and if both fail the machine is still taken offline and a message is printed to the console.

Changes

  • scripts/machine_health.py (new): dpkg-state detection, offline sentinel creation, semaphore write (with venv fallback), and semaphore clear.
  • scripts/performance/constants.py: add OFFLINE_MACHINES_CONTAINER.
  • scripts/run_performance_job.py: run the health check on prerequisite failure.
  • scripts/benchmarks_ci.py: clear the semaphore after a successful results upload.

Detection

Detection mirrors exactly what triggers the failure: a read-only sudo apt-get check is probed for the dpkg was interrupted / dpkg --configure -a signatures, so only this non-transient condition takes a machine offline (flaky network failures do not).

Notes

  • A companion change in dotnet-performance-infra (PerfMonitor) consumes the offline-machines container and alerts the team.
  • The upload identity needs write/create permission on the new offline-machines container; PerfMonitor's identity needs read.

…install

Some prerequisite-install failures are not transient but indicate a broken
host. The canonical case is the apt/dpkg database getting stuck in an
interrupted state ("dpkg was interrupted, you must manually run
'sudo dpkg --configure -a'"), which currently just fails the run repeatedly.

When this specific state is detected during prerequisite installation:
- The machine is taken out of Helix rotation by creating the `offline`
  sentinel file in $HELIX_CONFIG_ROOT.
- A semaphore blob named after the machine is written to the new
  `offline-machines` container in pvscmdupload so the perf team is notified.

The semaphore blob is cleared only when the machine next uploads results
successfully, guaranteeing a machine must actually be working to have its
semaphore removed.

The notification blob write is best effort: it uses the already-available
azure libraries, falls back to bootstrapping a throwaway venv with the
dependencies, and if both fail the machine is still taken offline and a
message is printed to the console.

- scripts/machine_health.py: detection, offline sentinel, semaphore
  write (with venv fallback) and clear.
- scripts/performance/constants.py: add OFFLINE_MACHINES_CONTAINER.
- scripts/run_performance_job.py: run the check on prereq failure.
- scripts/benchmarks_ci.py: clear the semaphore after a successful upload.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 418ccfe4-f031-42ad-92d8-38130011c784
Copilot AI review requested due to automatic review settings July 29, 2026 20:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a machine-health hook to detect a specific non-transient prereq install failure mode (corrupted/interrupted apt/dpkg state), then automatically removes the affected Helix machine from rotation and emits an external “offline machine” signal via Azure Storage until the machine proves healthy again by successfully uploading results.

Changes:

  • Add scripts/machine_health.py to detect interrupted dpkg state, create Helix offline sentinel, and write/clear an “offline semaphore” blob.
  • Add OFFLINE_MACHINES_CONTAINER constant for the new Azure Storage container.
  • Invoke the health check on prereq-install failure and clear the semaphore after successful results upload.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
scripts/run_performance_job.py Runs machine health check after prereq install failure (without affecting exit code).
scripts/performance/constants.py Adds OFFLINE_MACHINES_CONTAINER constant for offline-machine semaphores.
scripts/machine_health.py Implements dpkg corruption detection, Helix offline sentinel creation, and Azure blob semaphore write/clear.
scripts/benchmarks_ci.py Clears the offline semaphore after a successful results upload.
Comments suppressed due to low confidence (1)

scripts/machine_health.py:132

  • The fallback sentinel creation path uses sudo tee without -n, which can block on an interactive sudo password prompt (up to the 30s timeout) and delay/offline-marking in the exact failure scenario this script is meant to handle. Adding -n makes the operation non-interactive and fail fast.
    try:
        subprocess.run(
            ["sudo", "tee", offline_path],
            input=content,
            text=True,
            stdout=subprocess.DEVNULL,
            check=True,
            timeout=30,
        )

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

Comment on lines 330 to +334
combined_prequisites = " && ".join(install_prerequisites)
helix_pre_commands += [
'echo "** Installing prerequistes **"',
f"{combined_prequisites} || export PERF_PREREQS_INSTALL_FAILED=1",
'test "x$PERF_PREREQS_INSTALL_FAILED" = "x1" && echo "** Error: Failed to install prerequites **"'
'test "x$PERF_PREREQS_INSTALL_FAILED" = "x1" && echo "** Error: Failed to install prerequites **"',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would be good to fix.

Comment thread scripts/machine_health.py
Comment on lines +82 to +89
try:
result = subprocess.run(
["sudo", "apt-get", "check"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
timeout=120,
)
@DrewScoggins
DrewScoggins requested a review from LoopedBard3 July 29, 2026 20:53
@LoopedBard3

Copy link
Copy Markdown
Member

We should fix the typos in the names, and to double check, deleting the helix offline file will be a manual thing we do?

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.

3 participants