Repository navigation
fix(plugins): refuse a plugin update that another install overtook during its download - #4509
Conversation
…during its download A plugin replacement wrote its package over whatever the installation held when it finished. An automatic update still downloading when an admin installed a newer release stopped that release, wrote the older package, stored archive and version over it, and left the newer release's files on disk. A replacement now writes its row and stored archive in one transaction, guarded on the install path it was prepared against, and a changed installation is refused with ErrInstallationChanged before its process is stopped. Applying a recorded update prepares against the installation that recorded it. A manual install, update or upload that loses the race answers 409; an automatic update is skipped and leaves the newer release's refusal record alone. Closes Silo-Server#4352
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Warning Review limit reachedThis organization requires a seat for paid usage-based reviews, including automatic and on-demand reviews. Ask an admin to assign a seat or enable paid usage-based reviews for users without a seat in Billing. Next included review available in 49 minutes. View limit details
|
| existing := expected | ||
| if existing == nil { | ||
| existing, err = s.existingInstallationByPluginID(ctx, req.PluginID) |
There was a problem hiding this comment.
Catalog resolution can hide an intervening plugin replacement
An update completed while ResolveInstall fetches the repository index can become the baseline and be overwritten by an older requested release. Capture the existing installation before catalog resolution and guard the replacement against that snapshot.
Prompt for LLM
File internal/plugins/service.go, lines 330-332:
Catalog resolution can hide an intervening plugin replacement
A catalog install reads the existing installation only after `ResolveInstall` fetches the repository index, so an update that completes during that fetch becomes the baseline and can be overwritten by the older requested release. Capture the existing installation before resolving the catalog and guard the replacement against that snapshot.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
🤖 Claude Code (claude-opus-5-5)
This holds for a plain catalog install. /update now passes the installation it read, but InstallCatalog still reads the installation after ResolveInstall returns, so an install that lands while the index is fetched becomes the baseline and gets replaced. I'm fixing this in a commit on this branch by reading the installation before the catalog resolves, so there's no need to change it yourself.
There was a problem hiding this comment.
That makes sense. Reading the installation before catalog resolution closes the window for plain catalog installs, just as passing the earlier snapshot does for /update. Thanks for handling the fix on the branch.
There was a problem hiding this comment.
🤖 Claude Code (claude-opus-5-5)
Fixed in a18456d: installCatalog now reads the installation before ResolveInstall, so an install that lands while the index is fetched refuses this one with 409. A new case in TestServiceInstallCatalogStopsPluginOnlyForAnAcceptedPackageDB ("replaced while a catalog install resolves") fails on 74c42e1 and passes now. docs/admin-api.md says the guard covers the catalog lookup as well as the download.
There was a problem hiding this comment.
Thanks for fixing this. Reading the installation before catalog resolution closes the window identified in the suggestion, and the new regression case covers it. The documentation update also makes the guard’s scope clear.
Quick104
left a comment
There was a problem hiding this comment.
🤖 Claude Code (claude-opus-5-5)
One finding outside the diff, so it goes here rather than on a line. The catalog-install window from the existing thread on internal/plugins/service.go holds up too; my reply is in that thread.
Low: the web plugin list stays stale after the new 409. useInstallPlugin, useUploadPlugin and useApplyPluginUpdate in web/src/hooks/queries/admin/plugins.ts refresh the plugin queries only on success. With this PR, an install, upload or update that loses to another install answers 409, and the message asks the admin to check the installed version. The page still shows the version from before the other install landed, and still offers the update. Repair: refresh the plugin queries when one of these calls answers 409. I'm fixing this in a commit on this branch, so there's no need to change it yourself.
…solves InstallCatalog read the installation after ResolveInstall returned, so an install that landed while the repository index was fetched became the baseline and was replaced. Read it first, as /update already does. The web admin now refreshes the plugin lists when an install, upload or update answers 409, so the page shows the version the message asks the admin to check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
🤖 Claude Code (claude-opus-5-5) Review summaryReviewed head: The approach holds: the guarded write on Addressed
Checked and left as is
Left for maintainersOlder gaps on the same paths, outside this PR:
Validation
Other checks
Fit: 9/10 · Readiness: 9/10: ready (assuming CI is green) Fit: it fixes a real way to lose a newer plugin install. The fix is a database guard that works the same on one server or many, with no new setting. Readiness: the race is refused on this branch and reproduced on the base, the two gaps the review found are fixed with tests that failed before, and the remaining gaps predate this PR and are tracked. |
| existing := expected | ||
| if existing == nil { | ||
| var err error | ||
| existing, err = s.existingInstallationByPluginID(ctx, req.PluginID) |
There was a problem hiding this comment.
A concurrent first install can create duplicate plugin installations
A concurrent install can make the initial lookup stale, causing InstallBinary or InstallRemote to create a duplicate and later installs to fail with multiple existing installations found. Enforce uniqueness atomically when inserting the installation.
Prompt for LLM
File internal/plugins/service.go, line 329:
A concurrent first install can create duplicate plugin installations
If the plugin is absent at this lookup but another install completes while the catalog resolves, the stale nil snapshot sends this request through `InstallBinary` or `InstallRemote`, which inserts a second installation instead of detecting the new row; subsequent catalog installs then fail with `multiple existing installations found`. Guard the create path against an installation appearing after the initial snapshot, with an atomic uniqueness check at insertion.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Confirmed. Reading the installation before the catalog resolves widened the window for a duplicate first install. This PR merged before my fix was pushed, so the fix isn't on main yet: commit 9539ccc on the PR branch reads the installation again once the catalog resolves and answers 409 (ErrInstallationChanged) if one appeared meanwhile. It comes with TestServiceInstallCatalogRefusesAFirstInstallOvertakenWhileResolvingDB, which fails without the fix. It will land as a follow-up PR.
Two first installs whose downloads overlap can still both create a row, as before this PR. Only a unique index on plugin_installations.plugin_id closes that fully.
There was a problem hiding this comment.
Thanks for the clarification. The recheck addresses the widened race during catalog resolution, and the new test covers that case.
The broader duplicate-first-install race remains when downloads overlap; the recheck alone cannot enforce uniqueness at insertion. I understand the unique-index migration is being handled separately, so I would treat that as a known follow-up rather than a reason to block this PR.
Problem
Closes #4352
Related issue: N/A
Validation tasks: changes #1224 C1; changes #1225 C1 (only when two installs or updates of one plugin overlap; a single install or update behaves as before)
Other clients: Apple N/A (no plugin administration); Android N/A (no plugin administration); Roku N/A (no plugin administration)
When an automatic plugin update was still downloading and an admin installed a newer release of the same plugin, the automatic update won once its download finished. It stopped the newer plugin, wrote its older package, stored archive and version over the installation, and left the newer release's files on disk. The admin's install had reported success, and the plugin ran the older release afterwards. Two manual installs, updates or uploads of one plugin could race the same way.
With this change, an install, update or upload only replaces the installation it started from. One that another install overtook is refused without writing anything. The newer release, its stored package and its files stay. A manual one answers 409. An automatic update is skipped and records no refusal.
Approach
UpdateInstallationInputgainsArchiveandIfInstallPath, and a guarded write that no longer matches returns the newErrInstallationChangedinstead of doing nothing. The refusal record that automatic updates write already usedIfVersionand now ignores that error.POST /api/v2/admin/plugins/installations/{id}/update) prepares against the installation that recorded the available version. Before, it read the installation again after resolving the catalog, so an install landing in between could be replaced by the older recorded version./api/v2:createAdminPluginInstallationanduploadAdminPluginInstallationnow declare 409, whichapplyAdminPluginUpdateand the chunked upload's complete step already declared. The problem type isconflictwith adetailwritten for the admin. This is additive. The OpenAPI document, web types anddocs/admin-api.mdare updated. The frozen/api/v1bridge, jellycompat and the Apple and Android clients are not involved.Validation
go build ./...,gofmt -l,go mod tidy -diff,go vet ./...,make lint-changed,make lint-router-recovery: pass.make verify-route-inventory,verify-apiv2-openapi,verify-apiv2-web-types,verify-apiv2-contract,verify-apiv2-fixtures,TestCommittedArtifactMatchesRouter,verify-local-paths,verify-case-collisions,verify-size-ratchet,verify-bidi: pass.make test-goagainst a migrated PostgreSQL 18 database: passes. One earlier run failed ininternal/scanner(TestScanKeepsFileRowAcrossRenameDB). That test passes on its own and on the rerun, and this branch does not touch the scanner.scripts/ci/db-contracts.txt.pnpm exec vitest run src/hooks/queries/admin/ src/pages/AdminPluginDetail.test.tsx,tsc --noEmit, eslint and prettier on the changed files: pass. The new hook test fails without the 409 refresh.verify-settings-bindings-all,verify-playback-fixtures,verify-migrations,verify-prometheus-rules,verify-actionlintandverify-shellcheck(none of their inputs changed).Evidence
Checked on a local server running
origin/main(before) and this branch (after), with the same database. A local test catalog lists a test plugin at 1.0.0, 2.0.0 and 3.0.0. 1.0.0 is installed with automatic updates on. The 2.0.0 download is served slowly. Check Plugin Updates starts the automatic update to 2.0.0, and two seconds later the admin installs 3.0.0 from the catalog.Before (
origin/main):After (this branch), same steps:
(The extra
3.0.0/install-2973146988directory still on disk after the fix was left behind by the earlier run onorigin/main.)Reverse order on this branch: the admin's 2.0.0 install downloads slowly while Check Plugin Updates installs 3.0.0.
On the same build, an automatic update with no concurrent install still goes from 1.0.0 to 2.0.0. So does applying a recorded update with
POST /api/v2/admin/plugins/installations/{id}/update.Follow-ups
notifymarker,/update's second marker clear, and its 500 when the marker disappears) still go by ID alone and need this PR's guard.Risks
InstallationStore.Updatethat no longer matches now returnsErrInstallationChangedinstead ofnil. Its only earlier caller, the automatic update's refusal record, handles the error.Checklist
AI Disclosure
Note
Refuse plugin updates overtaken by another install during download
ErrInstallationChangedin installation.go. Guarded installation updates now reject stale state when the install path or version changed since preparation, and the installation row plus archive are written in one transaction.Service.replaceStoppedandAutoUpdateService.autoUpdatePlugincheck the installation path before stopping the plugin, so an overtaken update returns early. The newer release, stored package, and files remain.ErrInstallationChanged— seeupdateInstallationRowin installation.go and the updated assertion in builtin_guard_test.go.Macroscope summarized 2bc8e22.