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.

@localai-org-maint-bot

Copy link
Copy Markdown
Collaborator

Review pass on this draft. The underlying race is worth fixing, so it would be a shame to let it rot. Three items, all author-side:

  1. DCO. The single commit 6c5b6ab3 has an empty body and no Signed-off-by. Amending with the trailer clears the failing check.
  2. Test style. core/gallery/backend_operation_internal_test.go uses stdlib testing, which make lint rejects on forbidigo. This repo requires Ginkgo/Gomega for Go tests.
  3. Coverage for the new contract. The op.ID == "" boundary connecting UpgradeChecker to the coordinator is only covered indirectly. A LocalBackendManager.UpgradeBackend regression test would pin it.

No maintainer action is pending beyond this, so whenever you have time to pick it back up it can move.

@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.

The DCO check is failing — commits need a Signed-off-by: Your Name <email> trailer. You can fix this by running:

git rebase --signoff HEAD~<num-commits>
git push --force-with-lease

The implementation looks solid — the backend operation coordinator with channel-based per-path serialization and the WithSkipIfBackendBusy option for background auto-upgrades is a clean design. Tests are thorough. Once DCO is fixed I'll review the full PR.

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