Skip to content

Fix ebook match dialog to support generic provider IDs - #182

Merged
Quick104 merged 2 commits into
mainfrom
codex/fix-ebook-match-dialog
Jun 19, 2026
Merged

Quick104 merged 2 commits into
mainfrom
codex/fix-ebook-match-dialog

Conversation

@Quick104

@Quick104 Quick104 commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #180

Summary

  • Add generic provider ID support to admin match search and apply requests, including server-side normalization and blank-value filtering.
  • Update the Match Item dialog to preserve the real item content type, pass library context, show video ID fields only for video items, and expose generic provider ID rows for non-video matches.
  • Resolve metadata provider chains from the actual content level so ebook, manga, audiobook, and other non-video searches do not default to the series provider chain.
  • Add focused backend coverage for admin match search behavior and provider-chain content-level mapping.

Testing

  • go test ./internal/api/handlers -run AdminMatch -count=1
  • go test ./internal/metadata -run ProviderChainContentLevel -count=1
  • pnpm exec tsc -b
  • pnpm exec prettier --check web/src/components/MatchItemDialog.tsx web/src/hooks/queries/items.ts web/src/pages/AdminLibraries.tsx web/src/api/types.ts
  • pnpm exec eslint web/src/components/MatchItemDialog.tsx web/src/pages/AdminLibraries.tsx (exited 0 with one pre-existing warning)
  • git diff --check origin/main..HEAD
  • Privacy leak checks on staged diff, commit message, and candidate PR text

Review

  • Claude Code adversarial review completed in review-only mode.
  • Codex validation fixed the stable React key concern and found no remaining blocking issues.

Residual Risk

  • Generic provider ID matching still depends on configured metadata providers for the target media type.

AI Assistance

  • Implemented with Codex assistance and reviewed with Claude Code.

Summary by CodeRabbit

  • New Features
    • Added optional library ID scoping to match search and match apply operations
    • Updated the match dialog to use IMDb/TMDB/TVDB inputs for video items, and provider-id row editing for non-video items
  • Bug Fixes
    • Improved provider ID normalization (trimmed whitespace, case-insensitive handling) and now ignore blank provider IDs during searches
    • Enhanced provider-chain content type detection, including additional media content types and better fallbacks
  • Tests
    • Added coverage for provider-chain content level resolution and normalized match search requests

@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 12cd5ce8-af5e-4f7a-a45f-40fd71d0c978

📥 Commits

Reviewing files that changed from the base of the PR and between 2886335 and e785471.

📒 Files selected for processing (1)
  • web/src/components/MatchItemDialog.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/components/MatchItemDialog.tsx

📝 Walkthrough

Walkthrough

Adds end-to-end support for matching non-video items using arbitrary provider IDs. The metadata service gains a providerChainContentLevel helper to normalize content types to chain levels. The admin match handler normalizes generic provider IDs via new helper functions. The frontend MatchItemDialog conditionally renders video (IMDb/TMDB/TVDB) or generic provider-ID inputs based on item type, and the apply hook forwards library_id.

Changes

Generic Provider ID Matching

Layer / File(s) Summary
providerChainContentLevel normalization
internal/metadata/types.go, internal/metadata/service.go, internal/metadata/service_content_level_test.go
Adds providerChainContentLevel function mapping content types (movie, series, show, tv, season, episode, etc.) to chain levels; updates processInternal and SearchProviders to call it instead of inline branching; updates SearchQuery.ContentType comment; adds table-driven unit test.
Admin match handler provider-ID normalization
internal/api/handlers/admin_match.go, internal/api/handlers/admin_match_test.go
Adds normalizeMatchProviderIDs and setMatchProviderID helpers to trim/lowercase all provider keys/values and drop blank entries; wires them into request-to-query mapping for both generic and video-specific fields; adds omitempty to ProviderIDs JSON tag; updates test helper to capture folderID; adds test for ebook items with generic/whitespace-padded provider IDs.
Frontend API types, apply hook, and AdminLibraries wiring
web/src/api/types.ts, web/src/hooks/queries/items.ts, web/src/pages/AdminLibraries.tsx
Extends ItemMatchSearchRequest with provider_ids and library_id, ItemMatchApplyRequest with library_id; extends ApplyMatchItem and includes library_id in the apply POST body; removes narrowing cast of content_type in both AdminLibraries call sites.
MatchItemDialog conditional provider-ID UI
web/src/components/MatchItemDialog.tsx
Introduces ProviderIDInput, isVideoMatchType, and providerIdInputs state; updates handleSearch to send either video external IDs or provider_ids map; replaces static IMDb/TMDB/TVDB inputs with a mode-switched UI that renders either the three video fields or a dynamic per-row provider-ID editor with add/remove controls.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for generic provider IDs in the match dialog for non-video items like ebooks.
Linked Issues check ✅ Passed All acceptance criteria from issue #180 are met: video fields hidden for non-video items, generic provider IDs supported in search/apply, ebook chain resolution implemented, and video matching preserved.
Out of Scope Changes check ✅ Passed All changes directly support the PR objectives: provider ID normalization, match dialog updates, content-level metadata resolution, and supporting test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-ebook-match-dialog

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2886335283

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +210 to +216
func normalizeMatchProviderIDs(input map[string]string) map[string]string {
out := make(map[string]string, len(input))
for provider, providerID := range input {
setMatchProviderID(out, provider, providerID)
}
return out
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize provider IDs before applying matches

The new normalization helper is used only by the search endpoint; apply still passes req.ProviderIDs directly into Process. If a generic candidate or API client supplies a key such as ISBN or ISBN, prepareProcessRequest treats it as distinct from an existing lowercase isbn ID and can merge the stale value back into the request, causing providers to resolve the old match or return no metadata. Normalize the apply map as well, and reject it if no nonblank entries remain.

Useful? React with 👍 / 👎.

Comment on lines +2922 to +2924
// Search uses the item-level chain. Video child records search through the
// series chain; non-video content searches through its own content level.
contentLevel := providerChainContentLevel(query.ContentType)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Deduplicate candidates by generic provider IDs

Routing ebook, audiobook, and manga searches through their own chains sends their results into NormalizeCandidates, but that function's identity logic in internal/metadata/match_candidates.go only considers TMDB/TVDB/IMDb and metadb. Consequently, two results carrying the same isbn, openlibrary, or another generic ID receive separate synthetic keys instead of being merged, so the dialog shows duplicate matches and loses cross-provider IDs/agreement. Extend candidate normalization to fingerprint arbitrary durable provider IDs as part of this routing change.

Useful? React with 👍 / 👎.

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/src/components/MatchItemDialog.tsx`:
- Around line 93-100: The handleSearch function uses parseInt(year, 10) without
validation, which can result in NaN being serialized to null in the request
object. Add a guard condition to validate that the year value is actually a
valid numeric string before parsing it. Check that parseInt returns a valid
number (not NaN) and only include the year in the ItemMatchSearchRequest if it
parses successfully; otherwise leave it as undefined like the title field
handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 883ad61a-de76-4fde-a446-ddb896492c26

📥 Commits

Reviewing files that changed from the base of the PR and between 18e27be and 2886335.

📒 Files selected for processing (9)
  • internal/api/handlers/admin_match.go
  • internal/api/handlers/admin_match_test.go
  • internal/metadata/service.go
  • internal/metadata/service_content_level_test.go
  • internal/metadata/types.go
  • web/src/api/types.ts
  • web/src/components/MatchItemDialog.tsx
  • web/src/hooks/queries/items.ts
  • web/src/pages/AdminLibraries.tsx

Comment thread web/src/components/MatchItemDialog.tsx Resolved
@Quick104
Quick104 merged commit 9562754 into main Jun 19, 2026
1 check passed
@Quick104
Quick104 deleted the codex/fix-ebook-match-dialog branch June 19, 2026 00:19
Quick104 added a commit to fluxis/silo-server that referenced this pull request Jul 2, 2026
…'t be bypassed by casing

Review on PR Silo-Server#276 flagged that suppressRecordedStaleProviderIDs lowercases
and trims the stored stale row's provider before looking it up in the
incoming map, while the map keys are used verbatim, and that
HandleApplyItemMatch passes req.ProviderIDs from the JSON body straight
into metadata.Process without the normalization the search endpoint
applies. A caller-supplied key like "TMDB" or " tmdb " therefore defeated
the suppression. The same normalization gap was previously flagged on
PR Silo-Server#182.

Fix both layers:
- HandleApplyItemMatch now runs req.ProviderIDs through
  normalizeMatchProviderIDs (same semantics as the search endpoint) and
  returns 400 when no non-blank entries remain, mirroring the existing
  empty-map rejection.
- suppressRecordedStaleProviderIDs now indexes the incoming map by
  normalized key and deletes the matching original keys, so suppression
  is robust regardless of caller casing or padding.

Adds regression tests at both layers: a metadata-level case where the
durable row arrives as "TMDB " while the stale row records "tmdb", and
handler-level cases asserting apply normalizes keys/values and rejects
all-blank provider-id maps.

Co-Authored-By: Claude Fable 5 <[email protected]>
Quick104 added a commit that referenced this pull request Jul 2, 2026
…Ds (#276)

* fix(metadata): stop manual rematch from resurrecting recorded stale IDs

The Apply Match flow (ModeIdentify) re-injected durable provider IDs into
the identify request without checking stale_media_ids, so a known-dead
tmdb ID rode along, 404ed again during the Phase-2 fetch, and was
re-recorded with a fresh last_seen_at — the item never left the Stale
External IDs list and jumped back to the top after every rematch.

Filter recorded-stale IDs out of the injected durable set in
prepareProcessRequest. Caller-supplied IDs are untouched, so an admin
deliberately re-selecting a previously-stale ID still retries it (which
is also why the ModeIdentify suppression guard in processInternal stays).

Fixes #268

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(metadata): normalize provider-id keys so stale-ID suppression can't be bypassed by casing

Review on PR #276 flagged that suppressRecordedStaleProviderIDs lowercases
and trims the stored stale row's provider before looking it up in the
incoming map, while the map keys are used verbatim, and that
HandleApplyItemMatch passes req.ProviderIDs from the JSON body straight
into metadata.Process without the normalization the search endpoint
applies. A caller-supplied key like "TMDB" or " tmdb " therefore defeated
the suppression. The same normalization gap was previously flagged on
PR #182.

Fix both layers:
- HandleApplyItemMatch now runs req.ProviderIDs through
  normalizeMatchProviderIDs (same semantics as the search endpoint) and
  returns 400 when no non-blank entries remain, mirroring the existing
  empty-map rejection.
- suppressRecordedStaleProviderIDs now indexes the incoming map by
  normalized key and deletes the matching original keys, so suppression
  is robust regardless of caller casing or padding.

Adds regression tests at both layers: a metadata-level case where the
durable row arrives as "TMDB " while the stale row records "tmdb", and
handler-level cases asserting apply normalizes keys/values and rejects
all-blank provider-id maps.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Co-authored-by: Quick <[email protected]>
Quick104 added a commit to RXWatcher/silo-server that referenced this pull request Jul 10, 2026
* fix(metadata): match non-video items with content-aware providers

* fix(web): guard invalid match year parsing
Quick104 added a commit to RXWatcher/silo-server that referenced this pull request Jul 10, 2026
…Ds (Silo-Server#276)

* fix(metadata): stop manual rematch from resurrecting recorded stale IDs

The Apply Match flow (ModeIdentify) re-injected durable provider IDs into
the identify request without checking stale_media_ids, so a known-dead
tmdb ID rode along, 404ed again during the Phase-2 fetch, and was
re-recorded with a fresh last_seen_at — the item never left the Stale
External IDs list and jumped back to the top after every rematch.

Filter recorded-stale IDs out of the injected durable set in
prepareProcessRequest. Caller-supplied IDs are untouched, so an admin
deliberately re-selecting a previously-stale ID still retries it (which
is also why the ModeIdentify suppression guard in processInternal stays).

Fixes Silo-Server#268

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(metadata): normalize provider-id keys so stale-ID suppression can't be bypassed by casing

Review on PR Silo-Server#276 flagged that suppressRecordedStaleProviderIDs lowercases
and trims the stored stale row's provider before looking it up in the
incoming map, while the map keys are used verbatim, and that
HandleApplyItemMatch passes req.ProviderIDs from the JSON body straight
into metadata.Process without the normalization the search endpoint
applies. A caller-supplied key like "TMDB" or " tmdb " therefore defeated
the suppression. The same normalization gap was previously flagged on
PR Silo-Server#182.

Fix both layers:
- HandleApplyItemMatch now runs req.ProviderIDs through
  normalizeMatchProviderIDs (same semantics as the search endpoint) and
  returns 400 when no non-blank entries remain, mirroring the existing
  empty-map rejection.
- suppressRecordedStaleProviderIDs now indexes the incoming map by
  normalized key and deletes the matching original keys, so suppression
  is robust regardless of caller casing or padding.

Adds regression tests at both layers: a metadata-level case where the
durable row arrives as "TMDB " while the stale row records "tmdb", and
handler-level cases asserting apply normalizes keys/values and rejects
all-blank provider-id maps.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Co-authored-by: Quick <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Match Item dialog shows video provider IDs for ebook libraries

1 participant