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(metadata): report a failed Match Item folder lookup as a server error - #3576
When the database lookup of an item's library folders fails during Match Item, an admin is told their library_id is invalid, even though the server is at fault and retrying with another library can't help. This change makes that failure a 500 on /api/v2 search, apply and hints.
Approach
The folder lookup failure now has its own error, which /api/v2 renders as an internal_error problem. A library_id the item isn't in stays a 422, and "library_id is required for items in multiple libraries" is unchanged.
/api/v1 responses don't change: its search and apply handlers turn the lookup failure back into 400 "Invalid library_id". The one difference on v1 is in the logs, where a lookup failure on a request naming a library now logs at error level with the database error instead of a warning without it.
The new v1 test is a deliberate exception to the rule against testing frozen /api/v1 behavior. That mapping is v1-only code and nothing else guards it.
The Apple and Android clients don't call these operations, and jellycompat has no equivalent.
Validation
Full pre-PR gate: passed, except make verify-actionlint and make verify-shellcheck, which couldn't run because the required tool versions aren't installed here. This branch changes no workflows or shell scripts.
make test-go ran without a test database, so Postgres-backed tests were skipped. This change adds none.
Tests cover all three /api/v2 actions through the real handler with a failing folder lookup, including that the database error text doesn't reach the caller, and pin the /api/v1 response body. They don't exercise a real database outage.
Evidence
No screen changes. /api/v2 status and problem type before and after, from the handler with a simulated lookup failure. search and apply returned the same results in every row.
Adversarial review: independent reviews of this commit's diff by both models on correctness, standards and spec. No correctness or spec findings. Both flagged the v1 test against the frozen-v1 test rule: two rows that duplicated v2 coverage were removed, and the rest is kept as the exception described under Approach. One optional note about repeated sentinel returns in matchTarget was left as is.
Note
Fix AdminMatchHandler to report folder lookup failures as server errors
A failed folder lookup in AdminMatchHandler.resolveMatchFolderID was previously misclassified as an invalid library selection (a 400 client error). Lookup errors now propagate to matchTarget, which maps them to a distinct folder-lookup sentinel and logs them as lookup failures (admin_match.go).
The v1 HTTP handlers for search, apply, and hints keep their historical response: writeMatchErrorV1 translates the folder-lookup sentinel to the existing Invalid library_id API error.
New tests in admin_match_test.go and admin_catalog_match_test.go cover folder-lookup failure, unassociated library ID, and ambiguous multi-library selection for search, apply, and hints. The v2 tests assert the underlying lookup error is not exposed.
Behavioral Change: invalid and ambiguous library selections still return 400, but other folder-resolution failures now return internal errors on v2 and keep the Invalid library_id body on v1.
The pull request adds a scanner-backed admin match-hints endpoint and uses its results to prefill the Match Item dialog. It also changes admin match search year handling and shared library resolution, and updates the v2 API contract, fixtures, and tests.
Changes: Admin Match Hints
Layer / File(s)
Summary
Scanner lookup and match resolution internal/scanner/group_snapshot_repo.go, internal/scanner/group_snapshot_item_db_test.go, internal/api/handlers/admin_match.go, internal/api/handlers/admin_match_test.go, internal/api/router.go, scripts/ci/db-contracts.txt
The scanner repository selects the largest active group for an item in a folder. The handler uses the lookup for hints and shares item and folder resolution across search and apply. V1 search retains its stored-year fallback, while admin match search does not use the stored year when the request omits one.
The v2 API adds the permission-gated hints operation, response schema, and capability flag. Tests and fixtures cover hints responses, permissions, library validation, and lookup failures. The API documentation describes the endpoint and search behavior.
Web hints query and dialog prefill web/src/hooks/queries/items.ts, web/src/hooks/queries/keys.ts, web/src/components/MatchItemDialog.tsx, web/src/components/MatchItemDialog.test.tsx
The web query fetches hints for an item and optional library. The dialog applies hints to fields that the user has not edited and disables search while hints load. Tests cover hint values, fallbacks, and loading behavior.
Contract Metadata Adjustments
Layer / File(s)
Summary
Approval and fixture metadata contracts/api/v2/breaking-approvals.json, contracts/api/v2/fixtures/poll_device_login_binding_mismatch.json
The approvals array is emptied, and the device-login binding mismatch fixture's request identifier changes.
sequenceDiagram
participant MatchItemDialog
participant AdminCatalogMatchAPI
participant AdminMatchHandler
participant ScannedGroupRepository
MatchItemDialog->>AdminCatalogMatchAPI: GET match hints with item and library IDs
AdminCatalogMatchAPI->>AdminMatchHandler: Request hints for the item and library
AdminMatchHandler->>ScannedGroupRepository: GetForItem(folderID, contentID)
ScannedGroupRepository-->>AdminMatchHandler: Scanned group or no matching group
AdminMatchHandler-->>AdminCatalogMatchAPI: Title, year, and provider IDs
AdminCatalogMatchAPI-->>MatchItemDialog: AdminMatchHints response
Loading
Possibly related issues
Silo-Server/silo-server#3362: The changes address the reported Match Item title and year suggestions and the stored-year search fallback.
Silo-Server/silo-server#1210: The recorded Match Item validation failures were blocked by the behavior addressed in this pull request.
Silo-Server/silo-server#1209: The parent tracker records Match Item failures blocked by the search year fallback addressed here.
Silo-Server/silo-server#1211: The Match Item validation failures recorded under C1 were blocked by the behavior addressed here.
Possibly related PRs
Silo-Server/silo-server#3575: This PR builds on the same Match Item hints endpoint, scanner lookup, and dialog prefill code.
On an item in multiple libraries, switching libraries after editing a field can leave other search fields filled with suggestions from the previous library. This is a bounded issue to fix or accept before merging.
Security architecture risk: Low · up to fa260
The new suggestions are permission-gated and do not apply metadata changes automatically. No introduced access-control bypass or sensitive-error disclosure was identified. Some concurrency and recovery guarantees beyond the changed request handling remain unverified.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
observed — The added read surface projects scanner title, year, and TMDB, IMDb, and TVDB IDs, not raw filesystem paths or complete scanner records. It performs no metadata mutation or provider request itself. Existing apply behavior can replace content identity and notify catalog consumers; that authority is separate from the new hints read.
Trust Boundaries and Controls
observed — Hints uses the same authenticated, viewer-access and metadata-curation permission boundary as existing match operations, rather than an admin-role-only check. Production supplies the shared curation middleware, which evaluates acting-admin household/profile facts or delegated permission with the target item’s library set and the caller’s effective library scope.
observed — After item resolution, a requested library must belong to the item; an unscoped multi-library item is rejected as ambiguous. Production supplies the folder dependency, so the inherited nil-dependency fallback is not the public production path. Scanner retrieval then independently binds the resolved folder and content ID.
Resilience and Maintainability Implications
observed — Apply returns on item or folder resolution failure before entering metadata processing. After processing begins, existing partial-failure behavior remains: failures may follow writes and trigger an old-ID catalog notification; success notifies old and resulting IDs. This is inherited recovery behavior, not a newly introduced atomicity guarantee.
Pre-merge checks: 4 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title names the main change: a failed Match Item folder lookup is now reported as a server error instead of an invalid-library error. The raw summary and PR description both describe this behavior…
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 pull request description directly explains the Match Item folder-lookup error handling changes, the v1 and v2 response behavior, tests, validation, and risks. It is consistent with the changeset.
Full details: Title check
Explanation
The title names the main change: a failed Match Item folder lookup is now reported as a server error instead of an invalid-library error. The raw summary and PR description both describe this behavior change in the match handlers, the v2 error mapping, and the v1 compatibility adapter. The title does not mention the new hints endpoint, the year-fallback change, or the web dialog changes, but these are secondary to the main fix, so the title is related to the main change.
Full details: Docstring Coverage
Explanation
Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 15 files. (10 skipped: 9 unsupported, 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
silo-triageBot
added
api-v2
API v2 / Huma migration program (epic #135); long-running, stacked by phase
bug
Something isn't working
go
Pull requests that update go code
priority: P2
Limited scope, workaround exists, or polish
stacked
Base is another open PR; merge in stack order named in the body
labels
Nov 5, 2026
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.
…rror
A database failure while looking up an item's library folders told the
caller their library_id was invalid. /api/v2 search, apply and hints now
answer it with a 500 internal error problem, with or without a library_id.
The frozen /api/v1 routes keep their 400 "Invalid library_id".
Branch rewritten.#3575 merged as a squash, which left this branch conflicting with main. I rebased it onto main, dropped the commit #3575 already landed, and force-pushed. The PR's own commit is unchanged (same patch), and its authorship is kept.
Findings: none. I traced the change through the v1 and v2 handlers and their error mappers, and an independent review by a second model (Codex, gpt-6.1-sol) also found nothing. Specifically:
/api/v1 search and apply still return 400 {"error":"bad_request","message":"Invalid library_id"} on every path: a failed lookup with or without a library_id, a non-positive id, an item not in the library, and the no-folder-lookup case. The "library_id is required for items in multiple libraries" response is unchanged too.
No code modifies the shared *APIError sentinels, so matching them with errors.Is is safe.
All three v2 operations already document a 500 response, so no contract, fixture, or doc change is needed.
Verification.TestAdminMatchLibraryFailures fails on main in exactly the five lookup-failure cells the description's table lists (422 validation_failed where 500 is expected), and all twelve cells pass on this head. TestAdminMatchV1_FolderLookupFailureIsInvalidLibrary passes on both, as it should: it guards the unchanged v1 response rather than proving the fix. Nothing was run against a real database outage.
Other feedback. The CodeRabbit thread on MatchItemDialog.tsx concerns #3575's code, which main already fixed; I replied there.
Validated features. I couldn't read the v1.0 validation board in this run, so the description's Validation tasks: none is unconfirmed. Only the admin Match Item error status changes, and only when the database lookup fails.
User manual. Unaffected. The manual covers Match Item but not its error responses.
Clients. No Apple or Android follow-up: neither app calls these operations, and jellycompat has no equivalent.
PR body. I removed the note about depending on #3575 and added the evidence link.
Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)
Fit: a small correctness fix to how /api/v2 reports a server fault, with no new surface area. The frozen v1 contract is untouched.
Readiness: the new v2 test fails on main and passes here, two independent reviews found no defects, and the v1 response is pinned.
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
api-v2API v2 / Huma migration program (epic #135); long-running, stacked by phasebugSomething isn't workingenhancementNew feature or requestgoPull requests that update go codeimpact: usabilityCore flow broken or severely blockedjavascriptPull requests that update javascript codepriority: P2Limited scope, workaround exists, or polishsize/M50–199 added + deleted lines (all files); change volume, not priority.stackedBase is another open PR; merge in stack order named in the body
2 participants
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: none
When the database lookup of an item's library folders fails during Match Item, an admin is told their
library_idis invalid, even though the server is at fault and retrying with another library can't help. This change makes that failure a 500 on/api/v2search, apply and hints.Approach
The folder lookup failure now has its own error, which
/api/v2renders as aninternal_errorproblem. Alibrary_idthe item isn't in stays a 422, and "library_id is required for items in multiple libraries" is unchanged./api/v1responses don't change: its search and apply handlers turn the lookup failure back into 400 "Invalid library_id". The one difference on v1 is in the logs, where a lookup failure on a request naming a library now logs at error level with the database error instead of a warning without it.The new v1 test is a deliberate exception to the rule against testing frozen
/api/v1behavior. That mapping is v1-only code and nothing else guards it.The Apple and Android clients don't call these operations, and jellycompat has no equivalent.
Validation
make verify-actionlintandmake verify-shellcheck, which couldn't run because the required tool versions aren't installed here. This branch changes no workflows or shell scripts.make test-goran without a test database, so Postgres-backed tests were skipped. This change adds none./api/v2actions through the real handler with a failing folder lookup, including that the database error text doesn't reach the caller, and pin the/api/v1response body. They don't exercise a real database outage.Evidence
No screen changes.
/api/v2status and problem type before and after, from the handler with a simulated lookup failure.searchandapplyreturned the same results in every row.search,applybeforesearch,applyafterhintsbeforehintsafterlibrary_idvalidation_failedinternal_errorinternal_errorinternal_errorlibrary_idnamedvalidation_failedinternal_errorvalidation_failedinternal_errorlibrary_idvalidation_failedvalidation_failedvalidation_failedvalidation_failedlibrary_idvalidation_failedvalidation_failedvalidation_failedvalidation_failedEvidence: https://evidence.siloserver.org/r/silo-server/pr-3576/
Risks
A client that treated this 422 as a bad
library_idnow sees a 500 during a database failure. No other response changes.Checklist
AI Disclosure
matchTargetwas left as is.Note
Fix
AdminMatchHandlerto report folder lookup failures as server errorsAdminMatchHandler.resolveMatchFolderIDwas previously misclassified as an invalid library selection (a 400 client error). Lookup errors now propagate tomatchTarget, which maps them to a distinct folder-lookup sentinel and logs them as lookup failures (admin_match.go).writeMatchErrorV1translates the folder-lookup sentinel to the existingInvalid library_idAPI error.Invalid library_idbody on v1.Macroscope summarized 536d8f4.