Repository navigation
Description
Summary
A pre-existing startup data race intermittently fails CI: attempt recovery invokes a local-placement runner callback while Build is still mutating the Config captured by that callback. This is a real production race exposed by a flaky test result, not an effort-picker regression. Track and fix separately from #2266.
CI evidence
- PR: feat(mecatui): migrate effort picker to a bounded modal surface #2266, head
2c6d442337184fecf415328a0cfd845c65862547 - Failed job: https://github.com/stacklok/mecatl/actions/runs/38179800979/job/114589789965
- Failing test:
TestCloudNativeLearning_Scenario3_ExplicitProcedureAttemptSurvivesRestart - The job reported one race and one failing test. The TUI race suite passed.
Root cause
At this head, internal/app/build.go:2352-2355 installs runnerForRoot on the local placement provider. Its closure captures the mutable local cfg and passes it by value to buildCommandRunnerForRoot (internal/app/build.go:6680), reading/copying the whole struct.
Build starts attempt recovery at internal/app/build.go:2368. The immediate recovery timer can reattach queued work before startup finishes. Meanwhile Build writes cfg.maintenanceMutationAvailable at internal/app/build.go:2943.
Race-detector read stack:
Build.func12 build.go:2355
localPlacementProvider.bindLocal placement.go:284
localPlacementProvider.Reattach placement.go:160
recoverAttempt.func4 attempt_recovery.go:159
attemptWorker.Run attempt_worker.go:297
recoverAttempt attempt_recovery.go:218
startAttemptRecovery.func1 attempt_recovery.go:77
newAttemptRecoveryLoop.func1 attempt_recovery.go:55
Write stack:
Build build.go:2943
TestCloudNativeLearning_Scenario3_ExplicitProcedureAttemptSurvivesRestart
cloud_native_learning_scenario3_test.go:102
All race-stack source/test files are unchanged by #2266 relative to c6d7338888b94935b67535a0bd37902dd944ff71. The callback and later assignment both predate the PR.
Local reproduction
An initial 30-repeat focused race run passed. This command subsequently reproduced the identical stacks in about 45 seconds:
GOMAXPROCS=2 GOWORK=off go test -mod=readonly -race ./internal/app \
-run '^TestCloudNativeLearning_Scenario3_ExplicitProcedureAttemptSurvivesRestart$' \
-count=200Minimal proposed fix and verification
Capture an immutable configuration snapshot before publishing the callback, and use that snapshot for runner creation rather than the still-mutating cfg. Preserve the later service-dependent maintenance assignment. No sleeps, recovery suppression, or blind retries.
Retain the restart scenario, repeat the focused race reproduction, and run recovery/placement tests plus the full race gate. Preserve shell-disable, root selection, and environment-scrubbing behavior.
Activity
jbeda commentedon Oct 12, 2026
Investigation summary and proposed handoff
This is a server-startup configuration ownership race, not construction of a special learning session.
app.Buildcomposes the shared service used by ordinary sessions. During composition, it starts durable learning-attempt recovery, which can discover queued work left by a previous process.Core issue
The local placement provider's
runnerForRootclosure captures Build's mutablecfgand passes it by value tobuildCommandRunnerForRoot. Recovery reaches that callback through exact placement reattachment. Meanwhile, Build assignscfg.maintenanceMutationAvailableafter creating the service. The argument copy reads the whole Config and races with that assignment—even if Shell is disabled, because copying precedes the shell-disable check.Current source anchors (investigated at
56c5534a3):internal/app/build.go:2352-2368: callback publication and recovery launch.internal/app/build.go:2943: late maintenance-predicate assignment.internal/app/build.go:6680: by-value runner constructor.internal/app/attempt_recovery.go:31-43: immediate initial discovery.internal/app/attempt_recovery.go:149-169: source-session placement reattachment.internal/app/placement.go:274-284: environment/runner construction.Recovery has its own by-value Config parameter; the unsafe reference is indirect, through the placement callback that still captures Build's variable. Delaying recovery alone therefore does not establish safe Config ownership for other callbacks.
Proposed immediate plan for #2268
svc.MaintenanceMutationAvailablemethod, passed to the maintenance workers, rather than modifying the Config already captured by placement/service callbacks. Do not cache availability as a boolean. Capture diagnostics separately for the earlier reservation-reconciliation callback, whose value-receivercfg.diag()also copies mutable Config. Check remaining publication/teardown captures, includingcloseProfiles, rather than asserting all startup/close races are solved by the one assignment change.Automatic-reservation reconciliation is accounting repair, not model analysis: the admission ledger and attempt repository are separate stores. The loop resolves expired, still-held budget reservations against the corresponding attempt, retaining charges for admitted work or reclaiming unused reservations where creation authority was not consumed. Already committed create authority is conservatively charged; this is not a refund loop for failed attempts. It currently launches immediately and normally polls every second (
internal/app/automatic_reservation_reconciliation.go,engine/learning/automatic_ledger.go).Provisioner / execution-environment implications
The immediate race/lifecycle fix does not require changing provisioner APIs, persisted environment identities, or execution setup. Keep existing exact reattachment initially.
There is a separate coupling worth evaluating with the placement/provisioner owner:
PlacementReattacher.Reattach, which may construct workspace, ledger, runner and environment. For microVM, coldresolvecan restore/boot a VM even though learning only needs validated context./workspace, or a fresh Bind/provision operation.inspectrequires an active attachment; avoiding cold boot needs client/daemon metadata-validation work, including deletion state and repository/source-checkout association. Existing binding checks alone are not the complete substitute for reattachment.BindingID, while the Kubernetes execution provider requires it for exact reattachment (internal/adapter/executionclient/client.go:770-779). The context-resolution follow-up should forward/validate the source session ID rather than weaken binding checks.Status / verification
Investigation and provisional planning only; no fix has been implemented, no implementation branch or commits created. The earlier narrower plan received static review; the expanded lifecycle/context work is not finalized or implementation-approved. A subsequent delegated 200-repeat race run passed without reproducing the interleaving; that does not invalidate the issue's recorded race or prove a fix.
Use the focused reproduction in the issue, recovery/placement/maintenance tests, then the repository gates (
task test,task lint,task test:race, offline demo) and implementation review. No retries, recovery suppression or timing sleeps to mask the race. #1785's authorization-stream flake remains separate and deferred.jbeda commentedon Oct 12, 2026
Ozz -- I assigned this one to you. I hit this flake a couple of times but fixing it includes a mix of the dream/learning features and the environment provisioning. Right now there is no way to inspect an environment without creating a full microVM. Not sure how we want to resolve this but having the API capability to at least examine things without loading the full environment seems like a good thing.