Skip to content

fix(app): eliminate recovery startup Config race and order worker lifecycle - #2310

Merged
JAORMX merged 3 commits into
mainfrom
investigate/2268-startup-reproducer-20261014
Oct 15, 2026
Merged

JAORMX merged 3 commits into
mainfrom
investigate/2268-startup-reproducer-20261014

Conversation

@JAORMX

@JAORMX JAORMX commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2268.

  • Keep the configuration captured by placement/service callbacks immutable: use local copies for maintenance wiring and profile teardown, and capture diagnostics separately.
  • Start durable attempt recovery and automatic-reservation reconciliation only after successful composition. Preserve immediate discovery, and cancel/join both loops before service/backend teardown.
  • Close acquired resources on intervening startup failures, including command-resolver, placement-signer, and placement-validation failures.
  • Add behavior-named, real-composition regression tests.

Reproduction and cause

Reproduced on ab30305e7 with a test-only, channel-gated fixture using real Build composition, a persisted source session, queued durable work, and offline repositories/providers. The fixture gates recovery claim completion and late startup model discovery; it does not add production hooks or sleeps.

The pre-fix diagnostic failed during 50 race-enabled repetitions in 1.785s with the exact issue stacks:

write: Build                         build.go:2960
read:  Build.func12                  build.go:2363
       localPlacementProvider.bindLocal / Reattach
       recoverAttempt.func4         attempt_recovery.go:159
       attemptWorker.Run            attempt_worker.go:297
       newAttemptRecoveryLoop

Recovery reaches the local provider callback while Build is still assigning cfg.maintenanceMutationAvailable. Passing captured cfg by value reads the whole struct, even when Shell is disabled. The original 200-repeat restart stress test passed during investigation, demonstrating why stress alone is insufficient.

The committed regression fixture, TestBuildAttemptRecoveryWaitsForComposition in internal/app/attempt_recovery_startup_test.go, asserts the corrected lifecycle rather than requiring premature startup. Synctest with in-memory gRPC transport provides scheduling witnesses; held callbacks and cancellation acknowledgments expose teardown ordering. Temporary mutation checks (10 repetitions each) failed at the intended assertions for early recovery launch, service teardown before joins, either loop canceling without joining, and unavailable maintenance continuing into GC.

Verification

  • Focused recovery/reconciliation/GC/regression race tests, 50 repetitions
  • Existing restart and placement boundary race tests
  • task test
  • task lint
  • GOFLAGS=-p=4 task --concurrency 2 test:race — complete suite passed
  • task docs
  • Offline go run ./cmd/mecademo: tool call, permission ask/approval, result
  • Independent spec, standards, test-adequacy, architecture, reuse, and security review; no blocking or important findings after test improvements

Local full gates use the short system temporary root: the first managed-temp run exceeded UNIX-domain socket path limits in existing embedded-client tests; the same complete offline suite passed with the short root. The unrestricted race run exhausted /tmp during concurrent linking; limiting Task/build concurrency allowed the complete gate to pass. No test was disabled.

Earlier race attempts also exposed two unrelated failures, investigated rather than silently retried: the MCP login fixture sends its callback before installing the expected state (identical failures on baseline: 6/100; patch: 8/100), and an unchanged standalone microVM helper exceeded its two-second receipt deadline under load (focused race run passed; its dependency closure contains no app code). A diagnostic attempt using global GOFLAGS=-json conflicted with architecture tests' nested go list -f; that invocation error was removed. These findings did not lead to changes outside this PR's scope.

CI status

All checks on 199d51c3c passed or were intentionally skipped, including the full race job. The unrelated OAuth fixture failure seen on the prior revision remains documented above.

API compatibility

Compatible lifecycle/ownership correction. No wire fields, public Go APIs, stored-data formats, placement identities, provisioner contracts, or feature identifiers change. No API major bump, approval for a breaking change, or client upgrade is required.

Deliberate scope boundary

The issue comments also identify context-only environment inspection and recovery's missing Kubernetes BindingID. Those are separate concerns: this PR does not redesign provisioner APIs, change exact reattachment, or claim that learning recovery avoids cold microVM acquisition.

JAORMX and others added 2 commits October 14, 2026 15:36
Resolve the reproduced startup Config race, defer durable recovery until composition succeeds, and join workers before backend teardown.

Co-authored-by: Mecatl <[email protected]>
Use quiescence, cancellation acknowledgments, and service/backend witnesses; mutation-check early launch and missing joins.

Co-authored-by: Mecatl <[email protected]>
@JAORMX
JAORMX marked this pull request as ready for review October 14, 2026 13:29
@peppescg peppescg mentioned this pull request Oct 14, 2026
10 of 14 tasks
Remove incidental composition detail from the memory architecture chapter and replace issue-specific test names with behavior-based names.

Co-authored-by: Mecatl <[email protected]>
@JAORMX
JAORMX merged commit f07d4b4 into main Oct 15, 2026
37 checks passed
@JAORMX
JAORMX deleted the investigate/2268-startup-reproducer-20261014 branch October 15, 2026 08:39
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 20, 2026
2 tasks
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.

fix(app): flaky startup data race between attempt recovery and Build config mutation

1 participant