Skip to content

fix: refresh stale runner PATH snapshots - #75

Merged
Peyton-Spencer merged 1 commit into
mainfrom
codex/refresh-stale-runner-path
Jul 1, 2026
Merged

fix: refresh stale runner PATH snapshots#75
Peyton-Spencer merged 1 commit into
mainfrom
codex/refresh-stale-runner-path

Conversation

@Peyton-Spencer

@Peyton-Spencer Peyton-Spencer commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • detect stale runner .path snapshots that are missing Homebrew tool directories
  • restart only idle process-based runners to apply the current PATH
  • refresh stale runners after app auto-restart and when a busy runner becomes idle

Root Cause

Live runners created before the PATH fix kept running with old .path snapshots like /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin, so Actions could not resolve Homebrew-installed tools such as /opt/homebrew/bin/npm. Restarting the runners manually fixed the immediate failure, but Mac Runner should repair this state at the runner-management layer.

Validation

  • Confirmed ditto-app runners rewrote .path with /opt/homebrew/bin after restart
  • Reran ditto-app Firebase preview workflow successfully: https://github.com/ditto-assistant/ditto-app/actions/runs/27806209112
  • git diff --check
  • swift test attempted but blocked by existing local toolchain/repo issues: missing PreviewsMacros for #Preview and existing Containerization actor-isolation diagnostics in RunnerManager

Summary by CodeRabbit

  • New Features

    • Container-isolated runners now automatically refresh environment paths during auto-restart cycles and after completing jobs, ensuring access to current tools.
  • Tests

    • Added test coverage for environment path refresh detection.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds RunnerEnvironment.pathSnapshotNeedsRefresh(in:) to detect stale PATH snapshots by reading and parsing the .path file. Wires this check into RunnerManager's auto-restart loop and busy-to-idle tracking to trigger container-isolated runner restarts, backed by three new async orchestration helpers and three unit tests.

Changes

PATH Snapshot Staleness Detection and Auto-Restart

Layer / File(s) Summary
PATH snapshot staleness detection helper and tests
Sources/Services/RunnerEnvironment.swift, Tests/MacRunnerTests/MacRunnerTests.swift
pathSnapshotNeedsRefresh(in:) reads the runner's .path snapshot file, parses colon-delimited entries, and returns true when any preferredPathEntries are absent or the file is unreadable. Tests cover missing file, stale content, and up-to-date content cases.
Auto-restart and busy-to-idle integration
Sources/Services/RunnerManager.swift (lines 392–411, 828–873)
autoRestartRunners() now calls restartRunnersWithStalePathSnapshots() when no runners are queued for restart and again after processing queued restarts. updateRunnerStatuses() accumulates becameIdleRunnerIDs for runners transitioning from busy to idle and passes them to restartRunnersWithStalePathSnapshots(candidateIDs:).
Restart orchestration helpers
Sources/Services/RunnerManager.swift (lines 1249–1319)
Adds restartRunnersWithStalePathSnapshots(candidateIDs:) to scan and orchestrate restarts, runnerIsConfirmedIdle(_:) to confirm runner idle state via GitHub, and restartRunnerForPathSnapshotRefresh(_:) to execute the stop/start sequence with state and event recording.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • omniaura/mac-runner#52: Extends the same runner auto-restart and restart scheduling infrastructure in RunnerManager that this PR builds on to add stale PATH snapshot restart orchestration.

Suggested labels

enhancement

🐇 Hop, hop! The PATH is stale,
A snapshot check will never fail!
Busy runners rest, then wake anew,
With Homebrew paths refreshed brand new.
🌿 The rabbit checks each colon-split line —
"All entries present? Yes, we're fine!" 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the PR: detecting and refreshing stale runner PATH snapshots that lack Homebrew directories.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/refresh-stale-runner-path

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 and usage tips.

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

🧹 Nitpick comments (1)
Sources/Services/RunnerManager.swift (1)

1253-1266: ⚡ Quick win

Remove duplicate remote-idle confirmation in the stale-scan loop.

runnerIsConfirmedIdle(_:) is invoked in both the scan phase and the restart phase, which doubles ghService.listRemoteRunners calls for the same runner without adding safety (the restart path already re-validates idleness).

♻️ Suggested simplification
     private func restartRunnersWithStalePathSnapshots(candidateIDs: Set<UUID>? = nil) async {
         var staleRunnerIDs: [UUID] = []
         let runnerSnapshot = runners

         for runner in runnerSnapshot {
             guard runner.status == .running else { continue }
             guard !runner.busy else { continue }
             if let candidateIDs {
                 guard candidateIDs.contains(runner.id) else { continue }
             }

             let isolation = runner.effectiveIsolationMode(global: currentSettings.isolationMode)
             guard isolation != .container else { continue }
             guard processManager.isProcessAlive(for: runner.id) else { continue }
             guard let runnerDir = try? RunnerDirectory.path(for: runner.id, isolation: isolation) else { continue }
             guard RunnerEnvironment.pathSnapshotNeedsRefresh(in: runnerDir) else { continue }
-            guard await runnerIsConfirmedIdle(runner) else { continue }

             staleRunnerIDs.append(runner.id)
         }

         for id in staleRunnerIDs {
             await restartRunnerForPathSnapshotRefresh(id)
         }
     }

Also applies to: 1293-1295

🤖 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 `@Sources/Services/RunnerManager.swift` around lines 1253 - 1266, The
stale-scan loop in RunnerManager contains a redundant call to
runnerIsConfirmedIdle(runner) that duplicates idle confirmation already
performed during the restart phase. Remove the guard statement that calls await
runnerIsConfirmedIdle(runner) from the scan loop (the line with guard await
runnerIsConfirmedIdle(runner) else { continue }) since the restart path
re-validates idleness, eliminating unnecessary duplicate calls to
ghService.listRemoteRunners for the same runner.
🤖 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.

Nitpick comments:
In `@Sources/Services/RunnerManager.swift`:
- Around line 1253-1266: The stale-scan loop in RunnerManager contains a
redundant call to runnerIsConfirmedIdle(runner) that duplicates idle
confirmation already performed during the restart phase. Remove the guard
statement that calls await runnerIsConfirmedIdle(runner) from the scan loop (the
line with guard await runnerIsConfirmedIdle(runner) else { continue }) since the
restart path re-validates idleness, eliminating unnecessary duplicate calls to
ghService.listRemoteRunners for the same runner.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d4ecb74d-24e6-4026-98cd-6b1f700c924b

📥 Commits

Reviewing files that changed from the base of the PR and between fa87769 and 4dc618c.

📒 Files selected for processing (3)
  • Sources/Services/RunnerEnvironment.swift
  • Sources/Services/RunnerManager.swift
  • Tests/MacRunnerTests/MacRunnerTests.swift

@Peyton-Spencer
Peyton-Spencer merged commit 0125355 into main Jul 1, 2026
2 checks passed
@Peyton-Spencer
Peyton-Spencer deleted the codex/refresh-stale-runner-path branch July 1, 2026 19:51
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.17.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant