Skip to content

fix(controller): keep removals moving while a runner starts - #99

Merged
ysya merged 1 commit into
mainfrom
fix/controller-start-blocks-removals
Dec 1, 2026
Merged

ysya merged 1 commit into
mainfrom
fix/controller-start-blocks-removals

Conversation

@ysya

@ysya ysya commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Problem

Each scale set has one reconciler goroutine. It hands removals to their own goroutines, but it started a runner with a synchronous call. Until the provider's StartInstance returned, that scale set removed nothing.

A start can take minutes, and it can wait in the provider for host capacity. The Tart provider waits for one of the host's two macOS VM permits, or for a warm VM. A permit comes back only when a VM is removed, and only the reconciler claims removals.

With two macOS Tart scale sets on one host, both can stop for good:

  1. Each scale set has one VM running a job. Both permits are in use.
  2. Each wants a second runner. The process-wide limit defaults to the sum of max-runners, which is 4 here, so each gets a lease and enters StartInstance, where it waits for a permit.
  3. Both jobs finish. Neither VM is removed, because each reconciler is still inside its start.
  4. No permit is ever returned. Only a restart recovers.

When only one scale set is scaling up, it does not deadlock, but it stalls until the other scale set's job ends.

The comment on acquireCapacity describes the same hazard for the capacity lease and avoids it by abandoning the wait on a reconcile signal. The provider's wait had no such way out.

Fix

The reconciler now reserves the runner's name and lease, then runs the start in its own goroutine, as it already does for removals. The instance state already reserved a runner before provider I/O and already handled a completion or a drain that races a start, so no new state was needed beyond "a start is in flight".

  • reserveStart records the runner as provisioning, so the next reconcile pass counts it.
  • provision is the rest of the former startInstanceWithLease. It runs in the goroutine and signals the reconciler when it ends.
  • Drain and Shutdown wait for that goroutine before they take their snapshots. A start adds observer goroutines, so it is waited for before them.

Starts stay one at a time per scale set. Providers have never been asked to start two instances at once, and the start-failure backoff counts consecutive failures. Starting several runners in parallel is a separate change.

The providers are unchanged, and there is no new configuration.

Tests

internal/controller/start_in_flight_test.go uses a provider that holds a start until it gets a permit. The tests run under testing/synctest, so they do not depend on timing.

Test Before the fix
TestRemovalDoesNotWaitForStartInFlight fails: the finished runner is not removed while another start is in flight
TestScaleSetsSharingHostLimitDoNotDeadlock fails: neither scale set removes its finished runner
TestOneStartInFlightPerScaleSet passes; it fails with "3 starts in flight, want 1" if starts are allowed to overlap

go test ./... -race, go vet ./... and golangci-lint run ./... pass.

Verified on a Tart host

Run on an Apple silicon host with tart 2.40.1: two controllers, each with a real Tart provider, sharing the host's two macOS VM permits and a process-wide limit of 4. The guests ran a stand-in for the runner, and jobs were simulated by calling the controller's job handlers, so no GitHub registration was involved. The harness is build-tagged and not part of this PR.

Each scale set started one VM and was given a job, then asked for a second runner, then had its job finish.

Result
On main Both scale sets stayed at one provisioning and one removing instance for 2.5 minutes, until the harness gave up.
With this change Both finished runners were removed at once, and both second runners were idle 38 s later.

Not verified

  • A real runner and real jobs from GitHub.
  • No new test covers Drain and Shutdown waiting for the start goroutine. The existing drain and shutdown tests pass under the race detector.

The reconciler started a runner with a synchronous call, so a scale set
removed nothing until the provider's StartInstance returned. A start can
wait in the provider for host capacity that only a removal returns, and
only the reconciler claims removals.

With two macOS Tart scale sets on one host this could stop both for good.
The default process-wide limit is the sum of max-runners, which is above
the host's two VM permits. Each scale set could hold a finished runner it
never removed and a start that waited for a permit.

The reconciler now reserves the runner's name and lease, then runs the
start in its own goroutine, as it already does for removals. Drain and
Shutdown wait for that goroutine before they take their snapshots.

Starts stay one at a time per scale set. Providers have never been asked
to start two instances at once, and the start-failure backoff counts
consecutive failures.
@ysya
ysya merged commit 851eb1d into main Dec 1, 2026
12 checks passed
@ysya
ysya deleted the fix/controller-start-blocks-removals branch December 1, 2026 17:12
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.

1 participant