Skip to content

fix(metadata): report a failed Match Item folder lookup as a server error - #3576

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/match-folder-lookup-errors
Nov 9, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/match-folder-lookup-errors

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

Case search, apply before search, apply after hints before hints after
Lookup fails, no library_id 422 validation_failed 500 internal_error 500 internal_error 500 internal_error
Lookup fails, library_id named 422 validation_failed 500 internal_error 422 validation_failed 500 internal_error
Item not in that library_id 422 validation_failed 422 validation_failed 422 validation_failed 422 validation_failed
Item in several libraries, no library_id 422 validation_failed 422 validation_failed 422 validation_failed 422 validation_failed

Evidence: https://evidence.siloserver.org/r/silo-server/pr-3576/

Risks

A client that treated this 422 as a bad library_id now sees a 500 during a database failure. No other response changes.

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 says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code, Codex CLI (review only)
  • Model(s): claude-opus-5-5, gpt-6.1-sol (review only)
  • Involvement: Fully AI-generated, human verified
  • 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.

Macroscope summarized 536d8f4.

@silo-triage silo-triage Bot added the size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. label Nov 5, 2026
@silo-kody

silo-kody Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

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 settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

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.
V2 hints contract and endpoint
contracts/api/v2/openapi.json, contracts/api/v2/fixtures/*, internal/apiv2/admin_catalog_match.go, internal/apiv2/admin_catalog_items.go, internal/apiv2/admin_catalog_match_test.go, internal/apiv2/fixtures_test.go, internal/apiv2/household_profile_gate_test.go, internal/api/testdata/media_routes.txt, web/src/api/v2/*, docs/admin-catalog-api.md
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.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

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

Suggested labels: bug, enhancement, javascript, go, api-v2, priority: P2, impact: usability, stacked, size/XL

Suggested reviewers: quick104, blurbery

Merge Risk: Low · up to fa260

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: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive 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 Passed checks: 4 passed

Check name Status Explanation
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed 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-triage silo-triage Bot 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
@coderabbitai coderabbitai Bot added enhancement New feature or request impact: usability Core flow broken or severely blocked javascript Pull requests that update javascript code size/XL 500–999 added + deleted lines (all files); change volume, not priority. labels Nov 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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: 52f2d195-91ec-4748-8a6d-7906f82d12e0
Commits

Reviewing files that changed from the base of the PR and between c44b895 and fa2602f.

Files selected for processing: 25

  • contracts/api/v2/breaking-approvals.json
  • contracts/api/v2/fixtures/admin_catalog_capabilities.json
  • contracts/api/v2/fixtures/admin_match_hints.json
  • contracts/api/v2/fixtures/index.json
  • contracts/api/v2/fixtures/poll_device_login_binding_mismatch.json
  • contracts/api/v2/openapi.json
  • docs/admin-catalog-api.md
  • internal/api/handlers/admin_match.go
  • internal/api/handlers/admin_match_test.go
  • internal/api/router.go
  • internal/api/testdata/media_routes.txt
  • internal/apiv2/admin_catalog_items.go
  • internal/apiv2/admin_catalog_match.go
  • internal/apiv2/admin_catalog_match_test.go
  • internal/apiv2/fixtures_test.go
  • internal/apiv2/household_profile_gate_test.go
  • internal/scanner/group_snapshot_item_db_test.go
  • internal/scanner/group_snapshot_repo.go
  • scripts/ci/db-contracts.txt
  • web/src/api/v2/operations.ts
  • web/src/api/v2/schema.ts
  • web/src/components/MatchItemDialog.test.tsx
  • web/src/components/MatchItemDialog.tsx
  • web/src/hooks/queries/items.ts
  • web/src/hooks/queries/keys.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

Comment thread web/src/components/MatchItemDialog.tsx Resolved
@silo-triage silo-triage Bot removed the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Nov 5, 2026
…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".
@Quick104
Quick104 force-pushed the fix/match-folder-lookup-errors branch from fa2602f to 536d8f4 Compare November 9, 2026 15:08
@silo-triage silo-triage Bot added size/M 50–199 added + deleted lines (all files); change volume, not priority. and removed size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. labels Nov 9, 2026
@silo-kody

silo-kody Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

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 settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104

Quick104 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 536d8f433

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.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-3576/

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.

🤖 Claude Code in T3 Code (claude-opus-5-5)

@Quick104
Quick104 merged commit 07d2428 into Silo-Server:main Nov 9, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working enhancement New feature or request go Pull requests that update go code impact: usability Core flow broken or severely blocked javascript Pull requests that update javascript code priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority. stacked Base is another open PR; merge in stack order named in the body

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants