Skip to content

fix(core): serialize provision runs with a per-VM lock - #34

Merged
NovusEdge merged 2 commits into
mainfrom
core-provision-lock
Aug 10, 2026
Merged

fix(core): serialize provision runs with a per-VM lock#34
NovusEdge merged 2 commits into
mainfrom
core-provision-lock

Conversation

@NovusEdge

Copy link
Copy Markdown
Owner

Two provision runs against one VM each start apk, and the second dies on the apk database lock with exit 99: Unable to lock database: Resource temporarily unavailable. The TUI guarded against itself in one process, but a CLI stoat up auto-provision, a manual stoat provision, and the TUI did not share that guard.

core.WithProvisionLock(dir, fn) holds an exclusive non-blocking flock on <vm dir>/provision.lock while fn runs. A second run finds the lock held and returns ErrProvisionInProgress without touching the guest. The flock is advisory and released by the kernel on process death, so a lock file left by a crash never blocks the next run.

Every provision path funnels through it:

  • core.Apply wraps its body in the lock (used by the TUI, stoat up, stoat apply).
  • stoat provision drives sshx.Provision directly, so it takes the lock itself around that call.

A concurrent run is a skip, not an error: the CLI prints ": provision already running" and exits 0 (JSON gets a skipped_reason); the TUI shows a plain toast. The in-process m.provisioning guard stays as the same-process fast path.

Tests: WithProvisionLock serializes and reacquires after release; Apply returns ErrProvisionInProgress when the lock is held, before it reaches ssh. just check and just test pass.

Two concurrent Apply runs against one VM each start apk, and the
second hits apk's own database lock and fails with exit 99. Apply now
holds an exclusive flock on <VM dir>/provision.lock for the whole run
and returns ErrProvisionInProgress when another run already holds it.
core.Apply's ErrProvisionInProgress means another run already holds
the VM's lock, not that this run did anything wrong. The CLI's apply,
provision, and up commands print a short notice and exit 0; the TUI
shows a toast instead of the red error path. runProvision drives
sshx.Provision directly rather than through Apply, so it takes
core.WithProvisionLock itself around that call.
@NovusEdge NovusEdge added the bug Something isn't working label Aug 10, 2026
@NovusEdge NovusEdge self-assigned this Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@NovusEdge, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9fa1797b-8bf5-4b40-91a3-c1d451824b8f

📥 Commits

Reviewing files that changed from the base of the PR and between 51ba1c6 and 1dfe9cf.

📒 Files selected for processing (8)
  • internal/cli/run_access.go
  • internal/cli/run_apply.go
  • internal/cli/run_vm.go
  • internal/core/apply.go
  • internal/core/apply_test.go
  • internal/core/lock.go
  • internal/core/lock_test.go
  • internal/tui/app.go

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.

@NovusEdge
NovusEdge merged commit 1751bc3 into main Aug 10, 2026
8 checks passed
@NovusEdge
NovusEdge deleted the core-provision-lock branch August 10, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant