Skip to content

ci: enforce macOS runner disk reserve#4189

Open
vivekgsharma wants to merge 1 commit into
v4.1-devfrom
ci/swift-disk-preflight
Open

ci: enforce macOS runner disk reserve#4189
vivekgsharma wants to merge 1 commit into
v4.1-devfrom
ci/swift-disk-preflight

Conversation

@vivekgsharma

@vivekgsharma vivekgsharma commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • check free disk before the Swift SDK build
  • discard generated Rust/Swift output only when free space drops below 120 GiB
  • fail early with an explicit infrastructure error if cleanup cannot restore 100 GiB

Context

Job 88561517581 failed in rustc/LLVM with ENOSPC while the workflow preserved a large Rust target directory. Host-level idle-only disk guards are now also installed on both self-hosted Macs.

Verification

  • git diff --check
  • workflow YAML parsed successfully
  • embedded Bash preflight passed bash -n

Summary by CodeRabbit

  • Bug Fixes

    • Improved build reliability by proactively managing available disk space during macOS SDK builds.
    • Builds now clean up temporary and generated files when storage is low and stop with a clear error if sufficient space cannot be restored.
  • Chores

    • Existing build, caching, cleanup, and test processes remain unchanged.

@github-actions github-actions Bot added this to the v4.1.0 milestone Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Swift SDK macOS workflow now checks available workspace disk space, conditionally removes generated build artifacts and temporary files, re-checks capacity, and fails early when the minimum reserve is unavailable.

Changes

Swift SDK CI

Layer / File(s) Summary
Enforce macOS disk reserve
.github/workflows/swift-sdk-build.yml
The workflow checks free space, cleans selected Rust/Swift outputs and temporary runner files below 120 GiB, then fails below 100 GiB after cleanup.

Estimated code review effort: 2 (Simple) | ~5 minutes

Possibly related PRs

Suggested reviewers: quantumexplorer

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: a macOS CI disk-space reserve enforcement step.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/swift-disk-preflight

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.

@thepastaclaw

thepastaclaw commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

⛔ Blockers found — Sonnet deferred (commit c2f0082)
Canonical validated blockers: 1

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/swift-sdk-build.yml:
- Around line 30-40: Update the cleanup flow in the Swift SDK workflow to remove
the RUNNER_TEMP deletion entirely, preserving runner-managed files and command
directories. Move the unconditional Xcode DerivedData and Swift package cache
cleanup step before the first free-space calculation, then remove the later
duplicate “Clean Xcode derived data and Swift package caches” step. Keep the
existing threshold-based Rust target and xcframework cleanup behavior after the
accurate disk measurement.
🪄 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: 753bfc03-6780-4503-a967-4c286fc6f7a6

📥 Commits

Reviewing files that changed from the base of the PR and between 8b466ab and c2f0082.

📒 Files selected for processing (1)
  • .github/workflows/swift-sdk-build.yml

Comment on lines +30 to +40
cleanup_at_kib=$((120 * 1024 * 1024))
minimum_free_kib=$((100 * 1024 * 1024))
free_before_kib=$(df -Pk "$GITHUB_WORKSPACE" | awk 'NR == 2 { print $4 }')
free_before_gib=$((free_before_kib / 1024 / 1024))

if (( free_before_kib < cleanup_at_kib )); then
echo "::warning::Only ${free_before_gib}GiB is free; removing generated Swift and Rust build output"
rm -rf target
rm -rf packages/swift-sdk/DashSDKFFI.xcframework
find "$RUNNER_TEMP" -mindepth 1 -delete 2>/dev/null || true
fi

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.

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Prevent runner corruption and avoid unnecessary cache eviction.

There are two significant issues in this cleanup block:

  1. Critical: Deleting the contents of $RUNNER_TEMP is dangerous and will corrupt the GitHub Actions runner state. This directory contains internal runner files, including the currently executing shell script and the _runner_file_commands directory which hosts $GITHUB_ENV and $GITHUB_PATH. If deleted, subsequent steps attempting to export environment variables (such as the Verify protoc and export env step) will fail with a "No such file or directory" error.
  2. Major (Performance): Xcode DerivedData caches are unconditionally deleted in a later step. Because these large directories remain on disk during this check, they artificially inflate the used space. This can cause the workflow to unnecessarily evict the valuable Rust target/ cache or fail the build entirely.

Recommendation: Remove the $RUNNER_TEMP deletion. Instead, move the unconditional cleanup of Xcode and Swift caches from the later step to before the first disk space calculation. This ensures a safe and accurate measurement of free space before deciding whether to drop the Rust cache.

(Note: Remember to also remove the duplicate Clean Xcode derived data and Swift package caches step on lines 109-114 if you apply this fix.)

🛠️ Proposed fix to accurately clean and measure disk space
-          cleanup_at_kib=$((120 * 1024 * 1024))
-          minimum_free_kib=$((100 * 1024 * 1024))
-          free_before_kib=$(df -Pk "$GITHUB_WORKSPACE" | awk 'NR == 2 { print $4 }')
-          free_before_gib=$((free_before_kib / 1024 / 1024))
-
-          if (( free_before_kib < cleanup_at_kib )); then
-            echo "::warning::Only ${free_before_gib}GiB is free; removing generated Swift and Rust build output"
-            rm -rf target
-            rm -rf packages/swift-sdk/DashSDKFFI.xcframework
-            find "$RUNNER_TEMP" -mindepth 1 -delete 2>/dev/null || true
-          fi
+          # Clean unconditionally-deleted caches first to accurately reflect free space
+          rm -rf ~/Library/Developer/Xcode/DerivedData/* || true
+          rm -rf packages/swift-sdk/.build || true
+          rm -rf packages/swift-sdk/SwiftExampleApp/.build || true
+
+          cleanup_at_kib=$((120 * 1024 * 1024))
+          minimum_free_kib=$((100 * 1024 * 1024))
+          free_before_kib=$(df -Pk "$GITHUB_WORKSPACE" | awk 'NR == 2 { print $4 }')
+          free_before_gib=$((free_before_kib / 1024 / 1024))
+
+          if (( free_before_kib < cleanup_at_kib )); then
+            echo "::warning::Only ${free_before_gib}GiB is free; removing generated Swift and Rust build output"
+            rm -rf target
+            rm -rf packages/swift-sdk/DashSDKFFI.xcframework
+          fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/swift-sdk-build.yml around lines 30 - 40, Update the
cleanup flow in the Swift SDK workflow to remove the RUNNER_TEMP deletion
entirely, preserving runner-managed files and command directories. Move the
unconditional Xcode DerivedData and Swift package cache cleanup step before the
first free-space calculation, then remove the later duplicate “Clean Xcode
derived data and Swift package caches” step. Keep the existing threshold-based
Rust target and xcframework cleanup behavior after the accurate disk
measurement.

@vivekgsharma
vivekgsharma requested a review from ktechmidas July 21, 2026 13:59

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Preliminary review — Codex only

The disk-reserve preflight uses appropriate binary-unit thresholds, but it can fail before reclaiming Xcode DerivedData that the workflow already treats as disposable. Move that cleanup into the low-space recovery block so the 100 GiB failure represents an actually unrecoverable runner state.

Validated blockers were found in the Codex precheck. Sonnet is deferred until a fresh Codex revalidation clears the blocker gate.

Review provenance

  • Codex reviewers: gpt-5.6-sol — general (completed)
  • Verifier: gpt-5.6-sol — verifier
  • Sonnet: not run (deferred by blocker gate)

🔴 1 blocking

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `.github/workflows/swift-sdk-build.yml`:
- [BLOCKING] .github/workflows/swift-sdk-build.yml:37-39: Clean DerivedData before declaring the disk reserve unrecoverable
  The low-space recovery omits `$HOME/Library/Developer/Xcode/DerivedData`, even though this workflow unconditionally deletes that directory later at lines 109-113. On this self-hosted macOS setup, Xcode DerivedData and the workspace normally reside on the same data volume, and DerivedData can consume enough space to raise the workspace filesystem above the 100 GiB minimum. The preflight currently exits before reaching that existing cleanup, producing an avoidable infrastructure failure. Deleting it in the recovery block is safe because the workflow already discards it before the build, and none of the intervening Rust, cache, or Protobuf setup steps require it.

Comment on lines +37 to +39
rm -rf target
rm -rf packages/swift-sdk/DashSDKFFI.xcframework
find "$RUNNER_TEMP" -mindepth 1 -delete 2>/dev/null || true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🔴 Blocking: Clean DerivedData before declaring the disk reserve unrecoverable

The low-space recovery omits $HOME/Library/Developer/Xcode/DerivedData, even though this workflow unconditionally deletes that directory later at lines 109-113. On this self-hosted macOS setup, Xcode DerivedData and the workspace normally reside on the same data volume, and DerivedData can consume enough space to raise the workspace filesystem above the 100 GiB minimum. The preflight currently exits before reaching that existing cleanup, producing an avoidable infrastructure failure. Deleting it in the recovery block is safe because the workflow already discards it before the build, and none of the intervening Rust, cache, or Protobuf setup steps require it.

Suggested change
rm -rf target
rm -rf packages/swift-sdk/DashSDKFFI.xcframework
find "$RUNNER_TEMP" -mindepth 1 -delete 2>/dev/null || true
rm -rf target
rm -rf packages/swift-sdk/DashSDKFFI.xcframework
rm -rf "$HOME/Library/Developer/Xcode/DerivedData"/* || true
find "$RUNNER_TEMP" -mindepth 1 -delete 2>/dev/null || true

source: ['codex']

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.

2 participants