Skip to content

fix(gallery): serialize same-backend upgrades - #11721

Draft
poorpaper wants to merge 1 commit into
mudler:masterfrom
poorpaper:fix/backend-upgrade-race
Draft

fix(gallery): serialize same-backend upgrades#11721
poorpaper wants to merge 1 commit into
mudler:masterfrom
poorpaper:fix/backend-upgrade-race

Conversation

@poorpaper

Copy link
Copy Markdown

Summary

  • Serialize backend upgrades by their resolved concrete backend path.
  • Make background auto-upgrades skip a backend that is already being upgraded.
  • Preserve context cancellation and clean up idle coordinator entries.
  • Ensure meta backends coordinate on the concrete backend they resolve to.
  • Refresh installed backend metadata after waiting for an in-flight upgrade.

Problem

In standalone mode, manual upgrades run through the serialized GalleryService
worker, while UpgradeChecker can invoke BackendManager.UpgradeBackend directly.

This allows both paths to upgrade the same backend concurrently. Because both
invocations reuse and remove the same <backend>.upgrade-tmp and
<backend>.backup paths, one invocation can delete the other one's extraction
directory or rollback backup. This can cause extraction failures and leave the
previously installed backend missing.

Background auto-upgrades now back off when the same resolved backend is already
being upgraded. Explicit upgrades remain serialized and context-cancellable.

Testing

  • go test ./core/gallery -run "TestBackendOperationCoordinator|TestUpgradeBackendUsesResolvedConcretePath" -count=20
  • go test ./core/gallery -count=1
  • go test ./core/application ./core/services/galleryop -run "^$" -count=1

Fixes #11720

@localai-org-maint-bot localai-org-maint-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking down the same-path race. The coordinator shape looks reasonable, and the focused gallery tests pass locally, but this needs a few changes before it is ready:

  1. core/gallery/backend_operation_internal_test.go implements all cases with stdlib testing assertions (t.Fatalf, etc.). LocalAI requires Ginkgo v2/Gomega for Go tests, and forbidigo enforces this in lint. Please convert these cases to the package’s existing Ginkgo suite instead of adding a standalone stdlib-style suite.
  2. Please add a focused LocalBackendManager.UpgradeBackend regression test covering the new op.ID == "" contract: an empty-ID background operation must use the non-blocking option, while an explicit non-empty-ID operation must wait. That boundary is what connects UpgradeChecker to the coordinator and is currently only implied by the direct coordinator tests.
  3. DCO is ACTION_REQUIRED. Please amend the commit yourself with your own Signed-off-by trailer and force-push it; maintainers/automation cannot provide that legal attestation for you.

I verified git diff --check and go test ./core/gallery -run "TestBackendOperationCoordinator|TestUpgradeBackendUsesResolvedConcretePath" -count=1 on head 6c5b6ab36a37db0de62f07ffbda02ca011682e5d.

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.

Upgrade backends fails if auto-upgrade is enabled

2 participants