You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(plugins): keep one installation per plugin - #4525
Other clients: N/A (no client-visible change: plugin installation is a web admin feature, and the Apple, Android and Roku apps don't call the plugin install or upload endpoints)
A plugin could end up with two installation rows, and from then on every install or update of that plugin failed with a server error. Nothing in the database stopped it: installs read plugin_installations to decide between creating and replacing, then inserted without a lock. Two API servers auto-installing a default plugin at startup, or an admin install racing that auto-install, could both insert. An install from a direct archive_url never looked for an existing row at all, so installing an already-installed plugin that way always added a second one. Once two rows exist, existingInstallationByPluginID refuses with "multiple existing installations", which the API returns as a 500.
This change enforces one installation per plugin in Postgres and cleans up deployments that already have duplicates.
Approach
Unique index. A migration adds a unique index on plugin_id for ordinary plugins (kind = 'plugin'; the builtin row keeps its own index). A deployment without duplicates only builds the index; the cleanup below runs only when duplicates exist. It first locks the accounts linked to a duplicated plugin (a provider sign-in locks the account before the installation), then takes EXCLUSIVE locks on the chain and task-binding tables and then on plugin_installations (the order chain and task-binding edits take them), so a server still on the previous release can't add a duplicate mid-migration; this mode also waits out row locks such as a settings save's, which would otherwise deadlock with the cleanup. It then deletes duplicates, keeping per plugin a row with an enabled sign-in binding, then one with linked sign-in identities, then one an admin configured (settings or a sign-in binding), then one with a stored package, then an enabled one, then the oldest. Request connections on a deleted row move to the kept one, and the kept row takes any library chain placement, task binding, saved task schedule or marker provider setting it lacks from the best-ranked duplicate. A stored package doesn't move between rows: the same version can be a different build. Sign-in identities don't move either, since a duplicate may have been set up for another directory: every account linked through a deleted duplicate is revoked the way a password reset revokes one (login, impersonation, Audiobookshelf and Jellyfin-compatible sessions and approved device sign-ins) and its API keys are deleted, so it signs in again and links to the kept provider. A break-glass account keeps its local login sessions and API keys, as under a provider refusal: only the sessions and device approvals opened through a deleted identity end, along with its Audiobookshelf tokens and Jellyfin-compatible sessions, which don't record the identity they came from. The deleted rows' settings, sign-in bindings, remaining chain entries and state go with them: settings are encrypted under the installation id, and a delivered event leaves no delivery row, so moving a pending delivery could deliver it to the kept row twice. Events still pending only for a deleted row are dropped.
One write per create.InstallationStore.Create now writes the row, capabilities, signature and stored package in one transaction, with the row enabled. A create that hits the new index returns ErrPluginAlreadyInstalled. The create paths in the installer extract files before writing the row. They no longer save the package, enable the row, or delete it after a later failure as separate steps, so a concurrent replacement can no longer have its package overwritten or its row deleted by a create that started first.
Key creation re-checks the request's credential. Revoking an account's sign-ins locks the account row first, and the migration now locks the accounts it revokes the same way. Audiobookshelf token issuance and device approval already check their source under that lock; API key creation (personal and admin) now does too: under the account lock it already takes, it refuses a request whose login session was revoked or whose API key was deleted, with 401. Without that, a key request authenticated just before a revocation (the migration's, or a provider re-check's) could still save a key afterwards. Servers still on the previous release during the migration don't have the check.
Direct archive links.Service.InstallRemote takes the same create-or-replace decision as an upload, so a direct archive link for an installed plugin replaces it through fix(plugins): refuse a plugin update that another install overtook during its download #4509's guarded replacement path. Because the plugin is known only after the download, it reads the installations before downloading, as installCatalog does: another install of the plugin that lands during the download, or an uninstall, makes this one answer 409 instead of replacing the newer release.
Validation
Postgres test: installing one plugin twice through a direct archive link leaves one installation, replaced in place under the same id. A second create for the installed plugin is refused and leaves the stored package unchanged. An archive link overtaken by another install during its download is refused and the newer release stays. The test failed on main (4102bca) for the reported reason (the second archive link added a second row), and its overtaken-download case failed on this PR's first head before the fix.
Postgres migration test: a duplicate cleanup keeps a break-glass account's password session and API key while ending its session through the deleted identity and its Audiobookshelf token, fully revokes a regular account linked the same way, and moves the deleted duplicate's marker provider setting to the kept row. It failed on aca60c5 for all three before the fix, and on 244e725 for the Audiobookshelf token. The archive-link test also covers an uninstall during the download, which answered "installation not found" (404) before the fix.
Migration: run on a main-migrated database seeded with duplicates (no package versus package, disabled versus enabled, an older row versus a newer one holding an admin setting, a configured row without a package versus an unconfigured one with one, a request connection naming a duplicate, three duplicates where two hold the same chain placement, task bindings and saved schedules, and sign-in plugins whose duplicates hold different bindings and linked identities). It kept the expected row for each plugin (for sign-in plugins, the one with the enabled binding), moved the request connection and linked identities to it, gave it the missing chain placement, task binding and saved schedules without touching its own, left the builtin row and single installations alone, and the index then refused a new duplicate. Run against an in-flight settings save on a duplicate it deletes, the migration deadlocked with the earlier SHARE ROW EXCLUSIVE lock and waited and finished with EXCLUSIVE.
make test-go, go vet ./..., make lint-changed, go mod tidy -diff, make migrate-validate, and the generated-contract, route-inventory, size-ratchet, local-path and case-collision checks pass.
make test-db-contracts: every listed test that ran passed. The 45 backup tests that need pg_dump/pg_restore skipped on the build host; go test ./internal/backup/ passed there against the branch's database. make lint-router-recovery was not run (no golangci-lint on the build host; no router code changed).
Postgres test: an API key requested with a revoked login session, or by a deleted API key, is refused; it fails on main, where both requests mint a key. Existing auth, handler, API and Audiobookshelf tests pass against the database.
Not reproduced on a running deployment: the proof is the test and the migration run above.
The migration deletes data on deployments that already have duplicate installations: the dropped rows' plugin settings, sign-in bindings, chain entries and state. The ranking keeps the configured row where one exists. When both rows were configured, the older one wins and the other's settings are lost; when the kept configured row has no stored package, it loads only on nodes that still have its files, and elsewhere the admin installs the plugin again, which replaces that row in place and keeps its settings. Install directories of deleted rows stay on disk.
During a rolling upgrade, a server still on the previous release that hits the new index (an archive-link install of an installed plugin, or a lost race) returns a 500 instead of a 409 until it is upgraded.
The migration briefly blocks writes and row locks on plugin_installations while it runs; plain reads continue.
On a deployment that has duplicates, the cleanup locks accounts, the chain, task-binding and installation tables in a fixed order. A server still on the previous release that uninstalls a plugin or saves a sign-in re-check at the same moment can deadlock with it, as can one that links an account to a duplicate just as the migration starts and then signs that account in again before it commits; PostgreSQL then aborts one side, and an aborted migration rolls back and runs again at the next start.
Other state keyed by a deleted duplicate's installation id stays behind with it: a profile's watch-sync connection to a non-first-party plugin (keyed by installation on purpose, so a plugin can't inherit another's tokens) has to be reconnected, and per-user plugin settings for the deleted row are lost.
During a rolling upgrade, a server still on the previous release creates an installation and saves its package in two steps. A direct archive link handled by an upgraded server can replace that row in between, and the old server's package save then overwrites the new package. Catalog and upload replacements already have this window.
An account whose only sign-in identity was on a deleted duplicate, and whose password login was turned off when it linked, can't sign in until an admin resets its password or links it to the kept provider, as after removing a sign-in plugin today.
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or how I checked a change nobody sees.
AI Disclosure
Harness: Claude Code in T3 Code
Tool(s): Claude Code; Codex (plan review)
Model(s): claude-opus-5-5 (implementation, plan cut, code review), claude-sonnet-5-5 (code review cleanup finder and validation check), gpt-6.2-sol (plan attack)
Involvement: Fully AI-generated; not yet human verified
Adversarial review: before implementation, gpt-6.2-sol attacked the plan and claude-opus-5-5 cut it. That changed which duplicate the migration keeps (stored package and admin configuration before enabled and age, instead of the oldest row), added the write lock, and reused fix(plugins): refuse a plugin update that another install overtook during its download #4509's ArchiveInput and saveArchive. A high code review (three finders and a validation check) led to the admin-configuration ranking and the 409 wording in the operation summaries, and removed an interface method the installer no longer calls. A simplify pass changed nothing. Kody's review moved admin configuration ahead of the stored package in that ranking and added the request-connection, chain-placement and task-binding moves; Codex's reviews added the saved-schedule move, the sign-in ranking and the revocation of accounts linked through a deleted duplicate. The background adversarial review (gpt-6.2-sol, reviewed a1b9f75) found two problems, both fixed: the migration's lock mode could deadlock with a settings save from a server on the previous release, and a slow archive-link install could replace a newer install that landed during its download. It posted nothing because the head moved before it published. A /silo review (claude-opus-5-5 with a high code review of three finders and a validation check, and gpt-6.2-sol cross-provider, reviewed aca60c5) found three problems, all fixed: the cleanup revoked a break-glass account's local credentials, dropped marker provider settings instead of moving them, and an uninstall during an archive-link download answered 404.
Enforce one installation per plugin with unique index and typed conflict errors
Adds a migration that removes duplicate plugin-kind installations, consolidates references and settings onto the retained row, and creates a unique index on plugin_id in 20261118203050_unique_plugin_installation_per_plugin.sql
InstallationStore.Create now stores the installation, its capabilities, and its archive in one transaction, and returns the new ErrPluginAlreadyInstalled on a unique-index violation (installation.go)
The admin API maps that error to a 409 conflict, and the auto-updater treats it as a skipped install rather than a failure
Service.InstallRemote snapshots installations before downloading; an install that appears during the download is not selected as a replacement, and a concurrent uninstall converts to ErrInstallationChanged (service.go)
API-key creation now passes request claims into the repository, which locks the account rows and rejects the insert with ErrSessionRevoked if the session or API key backing the request was revoked (api_key_repository.go)
Risk: the migration locks affected users, deletes duplicate installation rows, and revokes credentials tied to displaced sign-in identities per break-glass rules; verify the ranking and credential-revocation logic in the migration and its test unique_plugin_installation_per_plugin_test.go
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
The database now enforces one plugin installation per plugin ID. Installation creation stores archives transactionally, and install paths handle replacement and creation races. API-key creation checks that the request credential remains live.
The migration ranks duplicate installations, moves or removes related records, deletes duplicates, and adds a partial unique index. The integration test checks survivor selection, credential handling, and marker-provider settings.
Create stores the installation, capabilities, and archive in one transaction. It maps matching unique-index violations to ErrPluginAlreadyInstalled. Backup test fixtures no longer include duplicate installations, and installation test fixtures provide archive data.
Archive installation and replacement internal/plugins/installer.go, internal/plugins/installer_replace_test.go, internal/plugins/service.go, internal/plugins/service_install_unique_db_test.go, internal/plugins/auto_update.go, cmd/silo/marker_plugin_migration_test.go
Installers include archive data when creating enabled installations, and archive files are extracted before record creation. Local and remote archive installs use shared logic. Replacement races return ErrInstallationChanged, and automatic updates skip an already-installed plugin. Database tests cover replacement and delayed downloads.
Creation-race handling and API descriptions internal/apiv2/admin_plugin_configuration.go, internal/apiv2/admin_plugin_lifecycle.go, internal/apiv2/admin_plugin_uploads.go, docs/admin-api.md, contracts/api/v2/openapi.json, web/src/api/v2/schema.ts
The admin API returns a conflict for duplicate creation. API descriptions document the 409 outcome for install and upload creation races.
Handlers pass request claims to storage. Storage checks that a session or API key remains live before creating a key. The admin API maps revoked-session errors to an authentication-required response. Database tests cover live and revoked credentials.
This change enforces one plugin installation per plugin and makes API-key creation refuse revoked sessions. Remaining risks are narrow: the cleanup migration can hit a lock-ordering deadlock and need a rerun, servers still on the previous release during the upgrade can bypass two of the new protections, and one test can hang on failure. Fix the migration lock order before merging if possible; the rest can be accepted or handled as follow-ups.
Security architecture risk: Moderate · up to 244e7
The steady-state changes strengthen installation consistency and credential revocation. A mixed-version upgrade still has a security-sensitive window: an already authenticated request on an older server can create an API key after cleanup revokes its credentials. Cleanup also removes duplicate-owned data that dropping the new index cannot restore.
Retained concerns
Medium · security · inferred: Duplicate cleanup assumes a key-creation request waiting on an affected account will recheck its credential after the migration commits. Previous-release creation paths take the account lock but do not perform that check. During a mixed-version upgrade, a request authenticated before cleanup can wait behind the migration, then insert a durable API key after sessions were revoked and existing keys deleted. This requires an affected non-break-glass account and an otherwise authorized key-creation request; personal keys also require the existing feature and profile permissions. Updated servers reject this ordering. Although the older revocation race predates the PR, the new destructive migration introduces a one-time cleanup transition that depends on enforcement absent from older writers. Whether deployment procedures drain those writers remains unresolved.
Security review details
Security Blast Radius
inferred — The mixed-version concern affects accounts linked to deleted duplicate installations in the shared database, not unauthenticated callers generally. A surviving key carries the authority allowed by the existing creation route: personal keys remain constrained by user-key settings and profile checks, while an authorized admin request can mint an account key. No cross-environment exposure was established.
Security Findings and Attack Paths
inferred — An affected account's request can pass authentication on an older node, wait for the migration's account lock, then create a key after cleanup commits. That key is outside the completed deletion and is not tied to the revoked session. Updated writers close this path by checking the requesting credential after acquiring account locks. Draining older writers would prevent this particular ordering.
Trust Boundaries and Controls
observed — Authentication middleware constructs API-key claims or validates an access token and its active session before attaching claims. The changed handler forwards those claims to issuance, where session rows are share-locked or API-key rows key-share-locked before insertion. Claim-less internal contexts still pass the helper; that fallback alone does not demonstrate a new unauthenticated HTTP path.
Resilience and Maintainability Implications
inferred — The migration uses transactional SQL without a no-transaction directive, so cleanup and index creation should roll back together on failure under the configured migration provider. Exclusive table locks protect cleanup against writes, and the final unique-index build fails rather than accepting remaining duplicates. These controls contain partial database state but do not make older application writers perform the new credential check.
Hardening Proposals
proposed — Make cleanup conditional on a drained upgrade with no older API requests in flight, or stage credential revalidation onto every writer before enabling destructive cleanup. This would make the revocation guarantee independent of mixed-version request timing.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(plugins): keep one installation per plugin" matches the main change. The PR adds a partial unique index on plugin_id, a migration that consolidates duplicate installations, and a create…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description is detailed and directly related to the changeset. It explains the duplicate plugin installation problem, the unique index and migration cleanup, the single-transaction create in Insta…
Full details: Title check
Explanation
The title "fix(plugins): keep one installation per plugin" matches the main change. The PR adds a partial unique index on plugin_id, a migration that consolidates duplicate installations, and a create path that returns ErrPluginAlreadyInstalled. The title is short, specific, and uses a conventional commit prefix.
Full details: Description check
Explanation
The description is detailed and directly related to the changeset. It explains the duplicate plugin installation problem, the unique index and migration cleanup, the single-transaction create in InstallationStore, the 409 handling for losing creates, the API-key credential re-check, and the direct archive-link replacement path. It also lists validation steps and risks, all matching the files in the raw summary.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
This assertion accepts any error, including an unmapped PostgreSQL uniqueness error. That error would leave the API returning a server error and automatic installation reporting a failure.
Use errors.Is(err, ErrPluginAlreadyInstalled) here. The existing row and archive assertions can remain.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: a953caaa-b0e5-4477-95ce-2d3477b1b464
Commits
Reviewing files that changed from the base of the PR and between d4a2117 and 64d6716.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.
Reviewing changes in Silo
Include the related issue, expected behavior, and validation steps in the PR description.
For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
Follow this repository's AGENTS.md and CONTRIBUTING.md.
Request another review with @kody start-review in a PR comment.
React with 👍 or 👎 to give feedback on individual suggestions.
Review settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
⚠️ 5 Kody Rule(s) were not evaluated
These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:
Preserve optional store capabilities through production wrappers
Detach mandatory cleanup from request cancellation and bound its lifetime
Preserve durable media identity and share identity-evidence precedence
Bound decoder throughput trades and share direct-play eligibility
Retain distributed firing claims through their own validity windows
A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
A plugin could get a second plugin_installations row: installs chose between
creating and replacing by reading the table and then inserted without a lock,
and a direct archive_url install never looked for an existing row at all. Two
servers auto-installing a default plugin at startup, or an admin install racing
that, could both insert. Once two rows existed, every later install or update
of the plugin failed with a server error.
- A partial unique index on plugin_id (kind 'plugin') enforces one row per
plugin. Its migration first removes duplicates, keeping a row with a stored
package, then an enabled one, then the oldest.
- InstallationStore.Create writes the row, capabilities, signature and package
in one transaction, enabled, and answers ErrPluginAlreadyInstalled when
another install created the plugin first. The create paths extract files
before the row and no longer delete a row on a later failure.
- The admin API answers that with 409 conflict; the auto-install skips it.
- InstallRemote downloads the archive and replaces an installed plugin the
same way an upload does.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
Security: Prevent N-1 replicas from minting keys after revocation
Required conditions: a rolling upgrade with an N-1 replica, duplicate auth-plugin rows, and either a displaced admin or auth.user_api_keys enabled. Fresh evidence beyond the earlier fixes is that the parent revision's key-creation paths take the user lock and insert without rechecking the authenticating session. A request authenticated while this revocation is uncommitted waits on FOR UPDATE; after commit the old handler inserts a fresh key, which survives identity deletion and provider rechecks. Ship the credential-live check before this migration, or require a maintenance-window drain of all N-1 API replicas.
The reason will be displayed to describe this comment to others. Learn more.
This is the previous-release window the maintainer accepted for this PR (see the earlier thread on the same race): the new check in API key creation can't reach a replica still running the previous release while this migration runs. The two ways to close it are the ones you name, shipping the credential check in a release before this migration or draining previous-release API replicas during the upgrade. Both are release decisions for the maintainer, so I'm leaving this open for them.
…licate cleanup
The duplicate cleanup revoked every session and deleted every API key of a
break-glass account linked through a deleted duplicate, which a provider
refusal never does: it now ends only what the account opened through a
deleted identity, as the refusal does. A deleted duplicate's marker provider
settings (keyed by installation id, like task schedules) now move to the kept
installation when it has none, so a sharing opt-out survives.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…talled mid-download
An archive-link install or upload that read an installation and found it
uninstalled before replacing it returned "installation not found", which the
API maps to 404 on a create. It now returns ErrInstallationChanged, the 409 an
install overtaken by another install already gets.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
Review of aca60c5 (this branch's commit with main merged in). Three findings. I'm fixing all three in commits on this branch, so there's no need to change them yourself.
Reviewed head: 1a65a77. The first pass reviewed aca60c5 (main 663882f merged into the PR's commit) and added 52ced25 and 244e725. This rerun handled the bot feedback that arrived after that pass and added 1a65a77.
Fit: 8/10 · Readiness: 8/10 — conditional (assuming CI is green)
Fit: enforcing one installation per plugin in Postgres fixes the 500s at their source, and that suits a server where several API servers share one database. The score is held down by how much the duplicate cleanup does for a state most deployments never reach: it moves state between installations, revokes credentials and takes table locks against servers still on the previous release.
Readiness: each fix is backed by a test that failed before it. What's left is two rollout decisions for the maintainers (below), and the change wasn't reproduced on a running deployment.
Addressed in this review
The duplicate cleanup revoked every session and deleted every API key of a break-glass account linked through a deleted duplicate. It now ends only what that account opened through the deleted identity, as a provider refusal does (52ced25).
A deleted duplicate's marker provider settings were dropped. They now move to the kept installation when it has none of its own, like task schedules (52ced25).
An archive-link install whose installation was uninstalled during the download answered 404. It now answers 409, like an install overtaken by another install (244e725).
The cleanup left a break-glass account's Audiobookshelf tokens alive. A token doesn't record the login it was minted from, so it may have come from the deleted identity. The cleanup now ends them, as it already ended Jellyfin-compatible sessions (1a65a77).
The archive-link test fixture closed its server before releasing held downloads, so a failure mid-download hung the test binary instead of reporting. It now releases them first (1a65a77).
New and changed tests: TestUniquePluginInstallationCleanupPostgres (new, listed in scripts/ci/db-contracts.txt) failed on aca60c5 for both migration findings, and on 244e725 for the Audiobookshelf token. The new uninstall-during-download case in TestPluginInstallKeepsOneInstallationPerPluginDB failed on aca60c5 with "installation not found". The PR's own tests passed against a database migrated to the head: plugins, auth, API-key handlers and admin API. make lint-changed reports no issues.
Left for the maintainers
Rolling upgrade. Two windows stay open while servers on the previous release run alongside this migration. First, a previous-release server can still mint an API key after the migration revokes the account, because it lacks the new credential check (the open thread). Second, a previous-release server creates an installation and saves its package in two steps, so an archive-link replacement on an upgraded server can have its package overwritten. Both close if the atomic create and the credential check ship one release before the cleanup migration, or if previous-release API servers are drained during the upgrade. The PR body now lists the second window under Risks.
Accounts linked only through a deleted duplicate. When such an account's password sign-in was turned off at linking, it can't sign in until an admin acts. For an SSO-only admin that means the shell recovery. The PR already lists this risk.
Checked and not changed:
Request connections moved to the kept row go to an installation of the same plugin, as an in-place update already does.
A request connection saved against a deleted duplicate during the migration is left with a deleted installation id. An uninstall leaves the same state on main.
A previous-release server can still deadlock the cleanup by linking an account to a duplicate in the gap between the migration's first account scan and its table lock, then signing that account in again before the migration commits. Locking the tables before the accounts would deadlock with every ordinary sign-in instead. PostgreSQL aborts one side, and an aborted migration reruns at the next start. The PR body's Risks now lists this case.
Task firing claims stay under the old task key, which allows at most one extra run of a moved schedule's task at upgrade. Before the cleanup, each duplicated task was already running twice.
Watch-sync connections and per-user plugin settings for a deleted duplicate are lost. Watch-sync connections are keyed by installation on purpose. The PR body now lists this under Risks.
Validation
The validation board couldn't be read from this account (the token lacks read:project). Read directly, #1224 C1 (server install and update) and #1225 C1 (web admin install) are changed: installs now write the row, capabilities and package in one transaction, and a lost race answers 409. That matches the PR's Validation tasks: line. Other passed cases (API keys, external sign-in, scheduled plugin tasks, library chains, request connections) could not be checked against the board. The migration reaches them only on deployments that already have duplicates.
Manual and clients
User manual: unaffected. Its plugin-install pages don't cover archive links or duplicates, and the break-glass fix brings the cleanup into line with what the sign-in pages already say.
Other clients: N/A. Apple, Android and Roku don't call plugin install or upload.
The reason will be displayed to describe this comment to others. Learn more.
Fixture cleanup can hang on a blocked archive download
If the competing 4.0.0 install fails while the 3.0.0 response is held, server.Close waits for the blocked handler and the test hangs instead of reporting the failure. Register the release cleanups after server.Close so they run first in LIFO order.
Prompt for LLM
File internal/plugins/service_install_unique_db_test.go, lines 119-120:
Fixture cleanup can hang on a blocked archive download
If the competing 4.0.0 install fails while the 3.0.0 response is held, cleanup calls `server.Close` before releasing the blocked handler and the test hangs instead of reporting the failure. Register the release cleanups after `server.Close`, so they run first in LIFO order.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 1a65a77. The fixture now registers one cleanup that releases every held download and then closes the server, and the per-version release cleanups are gone. Checked by forcing a failure while 3.0.0 is held: on 244e725 the test binary hung until the 20 s timeout, and with the fix it fails in 0.3 s with the real message.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this and testing the failure path. Releasing the held downloads before closing the server addresses the cleanup hang; the forced-failure test confirms it reports the underlying error instead of timing out.
Provider-derived Audiobookshelf tokens can remain valid and be rotated after their issuing identity is deleted because abs_sessions does not record that identity. Revoke tokens for displaced break-glass accounts too, or track the issuing identity to revoke only provider-derived tokens.
Prompt for LLM
File migrations/sql/20261118203050_unique_plugin_installation_per_plugin.sql, lines 125-126:
Provider-derived Audiobookshelf tokens survive identity removal
Audiobookshelf tokens issued from a break-glass account's displaced provider session remain valid and can be rotated after that provider identity is deleted, because `abs_sessions` does not record the issuing identity. Revoke those tokens for displaced break-glass accounts as well, or track their issuing identity so only provider-derived tokens are revoked.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 1a65a77. The cleanup now ends the Audiobookshelf tokens of every displaced account, break-glass accounts included, for the reason it already ends their Jellyfin-compatible sessions: a token doesn't record the login it was minted from. A break-glass account's local login sessions and API keys still stay. TestUniquePluginInstallationCleanupPostgres now seeds a break-glass token and checks it's revoked; it failed on 244e725 and passes now.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. Revoking Audiobookshelf tokens for all displaced accounts addresses the reported gap, while preserving break-glass local sessions and API keys. The regression test described covers the break-glass token case.
I haven’t independently verified the commit or test results.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Stability & Availability · Heavy lift
Do not wait for account locks while the migration holds the installation table lock.
The migration takes plugin_installations in EXCLUSIVE mode at line 60 before it locks the displaced accounts at lines 108-111. An account linked to a duplicate after the first scan is not locked earlier. A sign-in for that account locks the account, then waits on its installation with FOR SHARE (internal/auth/service.go:694). That wait conflicts with the migration's table lock. The migration then waits for the account, and the sign-in waits for the table. PostgreSQL aborts one transaction. If the migration is aborted, the upgrade fails until it is rerun.
Change the migration so it never waits for an account row while it holds the installation table lock. The lock order must match the sign-in order: account first, then installation.
The reason will be displayed to describe this comment to others. Learn more.
Checked, and the race is real, but I'm leaving the order as it is. It needs an account linked to a duplicate by a previous-release server in the gap between the migration's first account scan and its table lock, then another sign-in for that account before the migration commits. Swapping the order doesn't close it: locking the installation or identity tables before the accounts deadlocks with every ordinary sign-in, which locks the account first. When it does happen, PostgreSQL aborts one side, and an aborted migration rolls back and runs again at the next start. That's the outcome the PR already accepts for an uninstall or re-check from a previous-release server. I've added this case to the deadlock item under Risks.
…plicate cleanup
An Audiobookshelf token can be minted from a login session and doesn't
record which identity that session came from, so a break-glass account
linked through a deleted duplicate could keep a token from that identity.
The cleanup now ends those tokens for every displaced account, as it
already does for Jellyfin-compatible sessions.
The archive-link test fixture now releases held downloads before closing
its server, so a failure mid-download reports instead of hanging.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
Security: Preserve refused primary identities during duplicate cleanup
Required conditions: a displaced account has a refused identity on the duplicate primary provider and a surviving enabled network identity. Fresh evidence beyond the credential-revocation fixes is that this delete cascades the refused identity, while primaryAuthorityOf blocks overlay sign-in only when that identity still exists. After commit, the network identity no longer defers to the primary provider and can mint a new session, undoing deprovisioning; if its role answer is unspecified, the account can also retain a stale admin role. Preserve the refusal as a tombstone, disable the account pending relink, or otherwise prevent network sign-in until a surviving primary provider reconciles it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workinggoPull requests that update go codeimpact: usabilityCore flow broken or severely blockedpriority: P1Core-path bug; painful workaround — next after P0size/XL500–999 added + deleted lines (all files); change volume, not priority.
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Related issue: N/A
Validation tasks: changes #1224 C1; changes #1225 C1
Other clients: N/A (no client-visible change: plugin installation is a web admin feature, and the Apple, Android and Roku apps don't call the plugin install or upload endpoints)
A plugin could end up with two installation rows, and from then on every install or update of that plugin failed with a server error. Nothing in the database stopped it: installs read
plugin_installationsto decide between creating and replacing, then inserted without a lock. Two API servers auto-installing a default plugin at startup, or an admin install racing that auto-install, could both insert. An install from a directarchive_urlnever looked for an existing row at all, so installing an already-installed plugin that way always added a second one. Once two rows exist,existingInstallationByPluginIDrefuses with "multiple existing installations", which the API returns as a 500.This change enforces one installation per plugin in Postgres and cleans up deployments that already have duplicates.
Approach
plugin_idfor ordinary plugins (kind = 'plugin'; the builtin row keeps its own index). A deployment without duplicates only builds the index; the cleanup below runs only when duplicates exist. It first locks the accounts linked to a duplicated plugin (a provider sign-in locks the account before the installation), then takesEXCLUSIVElocks on the chain and task-binding tables and then onplugin_installations(the order chain and task-binding edits take them), so a server still on the previous release can't add a duplicate mid-migration; this mode also waits out row locks such as a settings save's, which would otherwise deadlock with the cleanup. It then deletes duplicates, keeping per plugin a row with an enabled sign-in binding, then one with linked sign-in identities, then one an admin configured (settings or a sign-in binding), then one with a stored package, then an enabled one, then the oldest. Request connections on a deleted row move to the kept one, and the kept row takes any library chain placement, task binding, saved task schedule or marker provider setting it lacks from the best-ranked duplicate. A stored package doesn't move between rows: the same version can be a different build. Sign-in identities don't move either, since a duplicate may have been set up for another directory: every account linked through a deleted duplicate is revoked the way a password reset revokes one (login, impersonation, Audiobookshelf and Jellyfin-compatible sessions and approved device sign-ins) and its API keys are deleted, so it signs in again and links to the kept provider. A break-glass account keeps its local login sessions and API keys, as under a provider refusal: only the sessions and device approvals opened through a deleted identity end, along with its Audiobookshelf tokens and Jellyfin-compatible sessions, which don't record the identity they came from. The deleted rows' settings, sign-in bindings, remaining chain entries and state go with them: settings are encrypted under the installation id, and a delivered event leaves no delivery row, so moving a pending delivery could deliver it to the kept row twice. Events still pending only for a deleted row are dropped.InstallationStore.Createnow writes the row, capabilities, signature and stored package in one transaction, with the row enabled. A create that hits the new index returnsErrPluginAlreadyInstalled. The create paths in the installer extract files before writing the row. They no longer save the package, enable the row, or delete it after a later failure as separate steps, so a concurrent replacement can no longer have its package overwritten or its row deleted by a create that started first.conflict, for installs and uploads. Both operations already declared 409 after fix(plugins): refuse a plugin update that another install overtook during its download #4509, and their summaries now mention this case. The default-plugin auto-install logs and skips it instead of recording a failure.Service.InstallRemotetakes the same create-or-replace decision as an upload, so a direct archive link for an installed plugin replaces it through fix(plugins): refuse a plugin update that another install overtook during its download #4509's guarded replacement path. Because the plugin is known only after the download, it reads the installations before downloading, asinstallCatalogdoes: another install of the plugin that lands during the download, or an uninstall, makes this one answer 409 instead of replacing the newer release.Validation
SHARE ROW EXCLUSIVElock and waited and finished withEXCLUSIVE.make test-go,go vet ./...,make lint-changed,go mod tidy -diff,make migrate-validate, and the generated-contract, route-inventory, size-ratchet, local-path and case-collision checks pass.make test-db-contracts: every listed test that ran passed. The 45 backup tests that needpg_dump/pg_restoreskipped on the build host;go test ./internal/backup/passed there against the branch's database.make lint-router-recoverywas not run (nogolangci-linton the build host; no router code changed).Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-4525/
Risks
plugin_installationswhile it runs; plain reads continue.Checklist
AI Disclosure
ArchiveInputandsaveArchive. Ahighcode review (three finders and a validation check) led to the admin-configuration ranking and the 409 wording in the operation summaries, and removed an interface method the installer no longer calls. A simplify pass changed nothing. Kody's review moved admin configuration ahead of the stored package in that ranking and added the request-connection, chain-placement and task-binding moves; Codex's reviews added the saved-schedule move, the sign-in ranking and the revocation of accounts linked through a deleted duplicate. The background adversarial review (gpt-6.2-sol, reviewed a1b9f75) found two problems, both fixed: the migration's lock mode could deadlock with a settings save from a server on the previous release, and a slow archive-link install could replace a newer install that landed during its download. It posted nothing because the head moved before it published. A/siloreview (claude-opus-5-5 with ahighcode review of three finders and a validation check, and gpt-6.2-sol cross-provider, reviewed aca60c5) found three problems, all fixed: the cleanup revoked a break-glass account's local credentials, dropped marker provider settings instead of moving them, and an uninstall during an archive-link download answered 404.🤖 Generated with Claude Code
Note
Enforce one installation per plugin with unique index and typed conflict errors
plugin_idin 20261118203050_unique_plugin_installation_per_plugin.sqlInstallationStore.Createnow stores the installation, its capabilities, and its archive in one transaction, and returns the newErrPluginAlreadyInstalledon a unique-index violation (installation.go)Service.InstallRemotesnapshots installations before downloading; an install that appears during the download is not selected as a replacement, and a concurrent uninstall converts toErrInstallationChanged(service.go)ErrSessionRevokedif the session or API key backing the request was revoked (api_key_repository.go)Macroscope summarized 1a65a77.