Skip to content

fix(metadata): stop manual rematch from resurrecting recorded stale IDs - #276

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
fluxis:fix/identify-stale-id-resurrect
Jul 2, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
fluxis:fix/identify-stale-id-resurrect

Conversation

@fluxis

@fluxis fluxis commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Problem

When an item with a stale provider ID (e.g. Formula 1, tmdb=324880) is manually rematched to a correct result from a different provider via Admin → Match → Apply Match, it never leaves the Stale External IDs list — its last_seen refreshes and it jumps back to the top.

Mechanism: the Apply Match flow runs Process in ModeIdentify. prepareProcessRequest re-injects the item's durable provider IDs — including the known-dead tmdb ID — into the request without consulting stale_media_ids. The Phase-2 fetch 404s on it again, and the post-persist stale-row refresh (DeleteByContentID + re-Upsert of this run's 404s) re-creates the stale row with a fresh last_seen_at. The list is ordered last_seen_at DESC, hence the row resurfacing at the top.

Approach

Filter recorded-stale IDs out of the injected durable set in prepareProcessRequest (reusing suppressRecordedStaleProviderIDs), before it merges into the request. Two properties fall out deliberately:

  • Caller-supplied IDs in req.ProviderIDs are never filtered, so an admin explicitly re-selecting a previously-stale ID (e.g. the provider fixed it) still retries it. This is also why the existing Mode != ModeIdentify suppression guard in processInternal stays untouched.
  • With no 404 recorded, the existing post-persist block now clears the item's stale rows and re-records nothing — the item drops off the stale list after a successful rematch, matching the (deprecated) HandleRematchStaleID behavior.

For non-identify modes the filtering is redundant-but-harmless: those paths already suppress recorded-stale IDs later in processInternal.

Two regression tests via ProcessWithProviders: one reproduces the full #268 scenario (stale tmdb + rematch to tvdb → request must not carry tmdb, stale rows must be empty after persist; failed before the fix with the stale row re-upserted), and one pins the exception (user re-selecting the recorded-stale ID keeps it).

Risks / follow-ups

Behavior change is limited to durable-ID injection when a matching stale_media_ids row exists. Scheduled/manual refreshes already suppressed these IDs downstream, so no observable change there.

Fixes #268

AI-use disclosure

Implemented with Claude Code (test-first); human-reviewed before submission.

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Quick104, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6a2bd364-73e6-4edf-b16a-4fba94b36ac1

📥 Commits

Reviewing files that changed from the base of the PR and between 3605eec and 515d245.

📒 Files selected for processing (4)
  • internal/api/handlers/admin_match.go
  • internal/api/handlers/admin_match_test.go
  • internal/metadata/identify_stale_id_test.go
  • internal/metadata/service.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@Quick104

Quick104 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Code review

Found 1 issue:

  1. The new suppression can be defeated by provider-key casing/whitespace. suppressRecordedStaleProviderIDs lowercases and trims the stored stale row's provider before the map lookup, but the map keys it checks are used as-is. HandleApplyItemMatch passes req.ProviderIDs straight from the JSON body into Process without normalizing (only the search endpoint runs normalizeMatchProviderIDs), and durable IDs are stored with whatever casing they arrived with — so a key like TMDB or tmdb slips past the lookup and the stale ID is re-injected after all. This is the same gap flagged in PR Fix ebook match dialog to support generic provider IDs #182's review ("Normalize provider IDs before applying matches — apply still passes req.ProviderIDs directly into Process"); normalizing the apply map (or normalizing keys inside suppressRecordedStaleProviderIDs itself) would close it. (prior PR feedback, PR Fix ebook match dialog to support generic provider IDs #182)

}
provider := strings.ToLower(strings.TrimSpace(staleID.Provider))
if provider == "" {
continue
}

result, err := h.metadata.Process(r.Context(), metadata.ProcessRequest{
ContentID: contentID,
ProviderIDs: req.ProviderIDs,
FolderID: folderIDStr,
Mode: metadata.ModeIdentify,
})

Otherwise the fix verified cleanly: it correctly filters only the injected durable set, preserves the deliberate ModeIdentify retry exception, doesn't disturb the provider404s gating from earlier stale-ID fixes (#35/#37/#38), and both regression tests pin the intended behavior.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

…'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

Quick104 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Addressed the review finding in 515d245:

  • HandleApplyItemMatch now normalizes req.ProviderIDs via the existing normalizeMatchProviderIDs (same semantics as the search endpoint) and returns the existing 400 when nothing non-blank remains — closing the PR Fix ebook match dialog to support generic provider IDs #182 gap.
  • suppressRecordedStaleProviderIDs now matches keys case-insensitively/trimmed regardless of caller.

New tests: stale-ID suppression despite "TMDB " key casing, apply-endpoint key normalization, and all-blank rejection. Both packages vet/test clean.

🤖 Generated with Claude Code

@Quick104
Quick104 merged commit 1704070 into Silo-Server:main Jul 2, 2026
1 check passed
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.

Stale External IDs: manual rematch to a different provider re-records the stale ID instead of clearing it

2 participants