feat(health): implement ID-based surgical repair with ARR metadata auto-discovery#531
Open
drondeseries wants to merge 1 commit intojavi11:mainfrom
Open
feat(health): implement ID-based surgical repair with ARR metadata auto-discovery#531drondeseries wants to merge 1 commit intojavi11:mainfrom
drondeseries wants to merge 1 commit intojavi11:mainfrom
Conversation
bc78af4 to
260fce4
Compare
javi11
reviewed
Apr 24, 2026
| @@ -0,0 +1,21 @@ | |||
| # Plan: Respect Configured Categories in ARR Auto-Registration | |||
javi11
reviewed
Apr 24, 2026
| metadataStr = &str | ||
| } | ||
|
|
||
| if relinked, err := s.healthRepo.RelinkFileByFilename(c.Context(), fileName, normalizedPath, path, metadataStr); err == nil && relinked { |
Owner
There was a problem hiding this comment.
Why are you saving all the hook request metadata? can we select just some fields? does it make sense better to save it as JSON in the database to perform queries?
Contributor
Author
|
I've addressed all feedback:
Everything is consolidated into a single clean commit on the PR branch. |
Contributor
Author
|
I've further optimized the metadata storage by:
The code is now 100% strict, performant, and storage-efficient. |
260fce4 to
f516048
Compare
…scovery This comprehensive update transitions AltMount's repair system from fragile path-based string matching to a high-precision, ID-based surgical workflow. By capturing and persisting unique ARR database IDs, AltMount can now guarantee 100% accuracy during repairs, even if files or folders have been renamed or reorganized. Key Technical Components: 1. Database & Schema: - Adds a 'metadata' JSON column to the 'file_health' table (Migration 026). - Updates all repository queries to persist and retrieve rich ARR IDs. - Ensures metadata is preserved and updated during file re-linking/renames. 2. Rich Metadata Capture: - Expands the Webhook handler to extract InstanceName, SeriesID, MovieID, and EpisodeFileID directly from Sonarr/Radarr payloads. - Implements detailed logging for webhook events, providing immediate visibility into captured IDs and library paths. 3. Automated Metadata Discovery Service (Three-Layer Engine): - Priority 1 (Show & Scene Match): Directly searches ARR libraries by title extracted from Release Name (NZB), matching against the permanent 'sceneName' field—the gold standard for ID precision. - Priority 2 (Global Discovery): Automatically polls all enabled ARR instances if the managing instance cannot be determined by path alone. - Priority 3 (Fuzzy Fallback): Safety mechanism using dots-to-spaces normalization and fuzzy title matching to identify legacy items. 4. Health Worker Integration: - Auto-Discovery: Proactively backfills IDs for healthy files during background check cycles. - Emergency Discovery: Attempts a final high-precision ID lookup immediately before a corruption repair strike if metadata is missing. - Surgical Strike: Utilizes captured IDs to execute targeted 'Fail and Replace' commands via the starr API, ensuring zero false-positive deletions. This creates a self-healing, ID-aware media management layer that provides production-grade reliability for large-scale library repairs.
260fce4 to
9919ae2
Compare
Contributor
Author
|
Here is the technical rationale for the specific fields retained in the metadata JSON:
All other redundant fields (like file paths) have been removed as they are already stored in Altmount's dedicated database columns ( |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR introduces a significant architectural upgrade to AltMount’s repair system, moving from Path-Based Guessing to ID-Based Precision.
Currently, AltMount attempts to repair corrupted files by matching paths and filenames against the Sonarr/Radarr library. This is fragile and often fails if the user has renamed folders or changed episode naming formats since the file was imported.
This update enables AltMount to capture, persist, and utilize unique ARR database IDs (`SeriesID`, `EpisodeFileID`, `MovieID`, `InstanceName`) to execute surgical "Fail and Replace" strikes with 100% accuracy.
Key Features
Technical Details
Example Log Output
```text
level=INFO msg="Successfully re-linked health record during webhook with rich metadata"
event=Download instance="Sonarr-Main" series_id=1587 episode_file_id=139540
new_library_path="/mnt/tv/Show Name/Season 01/Episode.mkv"
```
```text
level=INFO msg="ID-Based Precision: Using metadata IDs for Sonarr repair"
series_id=1587 episode_file_id=139540 instance="Sonarr-Main"
```