Repository navigation
Fix Swift 6 main-actor isolation in RunApp; scan Swift via CodeQL - #23
Conversation
CodeQL's Swift analysis (autobuild) failed because `swift build` errors under Swift 6 strict concurrency: RunApp calls @mainactor AppKit APIs (NSApplication.shared / setActivationPolicy / delegate / run() / reply(toApplicationShouldTerminate:) / terminate) from nonisolated methods. Newer toolchains only warn, so it built locally but broke CI. RunApp is the NSApplicationDelegate and drives the AppKit run loop, and its VM is created on and only used from the main queue, so mark the class @mainactor. The two VZVirtualMachineDelegate callbacks (a non-isolated protocol) fire on the VM's main delegate queue, so keep them nonisolated and hop via MainActor.assumeIsolated. Build/start RunApp on the main actor from the synchronous @main run command. Add an advanced CodeQL workflow scanning actions + swift with an explicit `swift build --package-path macos` (manual build mode) instead of the unreliable autobuild. Default setup (actions-only) is disabled in repo settings in favour of this workflow. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 27 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a CodeQL GitHub Actions workflow analysing ChangesCodeQL Workflow
Main-Actor Isolation Fix
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant RunCommand as run command
participant MainActor as Main Actor
participant RunApp
participant VM as VZVirtualMachine
RunCommand->>MainActor: MainActor.assumeIsolated
MainActor->>RunApp: create RunApp
MainActor->>RunApp: start()
RunApp->>VM: run VM
VM-->>RunApp: guestDidStop / didStopWithError (nonisolated)
RunApp->>MainActor: MainActor.assumeIsolated
MainActor->>RunApp: cleanupAndTerminate()
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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/codeql.yml:
- Around line 42-43: The Checkout step in the CodeQL workflow is leaving the
default persisted GitHub credentials enabled, which is unnecessary for this job.
Update the actions/checkout usage in the checkout step to set
persist-credentials to false so the GITHUB_TOKEN is not retained for later steps
or nested tool invocations.
- Around line 23-26: Add a brief explanatory comment for the job-level
permissions override in the CodeQL workflow, since the `permissions` block
granting `security-events: write` is undocumented. Update the workflow near the
`permissions` section in the CodeQL job to explain why the elevated access is
required, matching the style of the top-level permissions comment.
- Line 43: Update the CodeQL workflow so the `actions/checkout` step is pinned
to a full commit SHA instead of `@v4`, while leaving the
`github/codeql-action/init` and `github/codeql-action/analyze` steps on `@v4`.
Use the existing workflow step identifiers in `.github/workflows/codeql.yml` to
locate the checkout action and replace only that reference.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: b7efb555-afcd-4b1c-b891-398f20572f27
📒 Files selected for processing (2)
.github/workflows/codeql.ymlmacos/Sources/vmctl/main.swift
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
- Document the job-level security-events: write permission. - Set persist-credentials: false on checkout (no step pushes). - Pin actions/checkout to a commit SHA (v4.3.1); CodeQL actions stay on @v4. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Why
CodeQL's Swift analysis (default setup, autobuild) was failing on the code-scanning status page:
Root cause:
swift buildfails under Swift 6 strict concurrency.RunAppcalls@MainActorAppKit APIs (NSApplication.shared,setActivationPolicy,delegate,run(),reply(toApplicationShouldTerminate:),terminate) from nonisolated methods (start(),cleanupAndTerminate()). Newer local toolchains only warn, so it built locally but the stricter CI toolchain treated them as errors and the build (and thus the CodeQL Swift extraction) failed.What
Code fix (
macos/Sources/vmctl/main.swift)RunApp@MainActor— it is theNSApplicationDelegate, drives the AppKit run loop, and itsVZVirtualMachineis created on / only used from the main queue.VZVirtualMachineDelegatecallbacks (guestDidStop,didStopWithError) implement a non-isolated protocol but fire on the VM's main delegate queue, so keep themnonisolatedand hop viaMainActor.assumeIsolated.RunAppon the main actor from the synchronous@mainruncommand.Scanning (
.github/workflows/codeql.yml)swift build --package-path macos(manual build mode) instead of the unreliable autobuild — the "manual build command" GitHub recommends.contents: readdefault; job elevatessecurity-events: write).Verification
swift build— succeeds, 0 errors, 0 warnings for the RunApp concurrency issues (only a pre-existing, non-fatal@Sendablecapture warning in the install path remains).scripts/Build-vmctl.sh(release + ad-hoc codesign) —Build complete!, binary signs and runs (vmctl helpexit 0).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes