Repository navigation
fix(manager): stop old project work from overlapping a handoff - #154
Conversation
ecv
left a comment
There was a problem hiding this comment.
Approve.
Departure and re-engagement now wait for running reconciles before teardown or replacement. go test -race -count=1 ./internal/manager/... passes at 8cac778, and removing the acquire() gate in both reconcilers fails TestProjectDepartureDrainsReconciliation, TestProjectReengagementDrainsReconciliation and TestProjectEngagementSerializesDownstreamSetupAndCleanup.
- A hung reconcile blocks teardown forever.
drain()takesreconcileMu.Lock()with no bound, andunbindLockedcallsstop()while holding the per-cluster engagement token. The cancel does reach the engage context, so a reconcile that honours its context ends. One that ignores it stalls every later Engage of that cluster name until the process restarts. Waiters that carry a ctx do return on cancel.
Follow-ups:
- Bound the drain wait (timeout plus a log line naming the project) so a stuck reconcile surfaces instead of wedging re-engagement silently.
- A failed re-engage after the prior runtime drained leaves the project unregistered until discovery retries; the doc says so, but there is no metric or alert for a project stuck unengaged.
- Nothing mutation-tests the
drainOnce/stoppedpair: dropping only theLock()wait indrain()was not checked (my sed broke the build), so confirm one test fails without the wait.
|
One stress run of the manager tests failed before these numbers were taken. I didn't keep its output, and 108 later runs passed, as did a reviewer's 90 runs with shuffling across 1, 2 and 8 CPUs. If it shows up in CI, the cause is still unknown. |
kevwilliams
left a comment
There was a problem hiding this comment.
Hold: provider-event Machine reconciles bypass the drain, so old work can still overlap a handoff.
ClusterProviderEventReconciler.Reconcile(provider_events.go:137) takesr.Projects.Getand callsruntime.Machinewithoutruntime.acquire(); a temporary probe test saw departure finish while that handler was still running.- Fix:
if !runtime.acquire() { return }plusdefer runtime.reconcileMu.RUnlock()there;staging.EngagedPublisherwrites throughruntime.Binding.Clientthe same way. - Test: add a provider-event case to the drain tests.
Provider MachineCapacity events and the synthetic publisher resolved the engaged runtime without acquiring it, so departure or re-engagement could finish while one of them was still writing through the old runtime. Both now acquire the runtime first and skip work once it is draining. The departure drain test gains a provider-event case, which fails without the gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@kevwilliams the hold is fixed in fe3a15b:
@ecv on your follow-up about the drain wait: removing the lock wait in the drain fails five tests, including both drain tests and the re-engagement registry test. The time limit on the wait and the alert for a project left unengaged are still open as follow-ups. |
kevwilliams
left a comment
There was a problem hiding this comment.
Verified removing the new provider-event acquire fails the provider_event drain case under race; the publisher gate copies it but has no test of its own.
ecv
left a comment
There was a problem hiding this comment.
Approve.
The re-review delta closes the provider-event gap from the hold on 8cac778. ClusterProviderEventReconciler and EngagedPublisher now take the runtime's reconcile gate before writing, and both return without work once the runtime is draining. The provider-event path joins the departure drain test.
Follow-ups:
- The
EngagedPublishergate has no test. Removing it passes the suite. - My earlier follow-ups stand: an unbounded drain wait, and no signal for a project left unengaged after a failed re-engage.
Fixes three races in how the fleet manager hands off a project. A project could leave, or come back, while work from its old runtime was still running and could still write.
Related to #90. These fixes come from that inventory feature branch. They don't depend on inventory, so they land first, on their own.
What changes
Test plan
🤖 Generated with Claude Code