Skip to content

fix: treat an out-of-range season as final instead of a transient error - #37

Merged
Pasithea0 merged 2 commits into
mainfrom
fix/unsupported-season-range
Nov 2, 2026
Merged

Pasithea0 merged 2 commits into
mainfrom
fix/unsupported-season-range

Conversation

@Pasithea0

@Pasithea0 Pasithea0 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Why

The same defect as TheIntroDB/jellyfin-plugin#39, in this codebase: Emby passes the season number it reads from TVDB metadata straight through, and TVDB numbers the seasons of a year-based series by year — Tagesschau is S2024, S2025, … The API caps a season at 1000, so every episode of those series answers

GET /v4/media?tvdb_id=252244&season=2024&episode=196&duration_ms=930709
400 {"error":"Invalid season. Must be between 0 and 1000"}

Here that 400 became MediaFetchResult.ClientError() → SegmentFetchResult.ClientError(): the client logged the body at Warn for every request, the provider logged a warning per episode, and the scanner logged a third warning per item ("TheIntroDB API rejected request … (client error)"). A 200-episode year-based season produced ~600 warning lines per scan, and every scan re-sent a request that cannot succeed.

Nothing about the request is fixable on this side: season+episode is the only way /media addresses an episode (the episode's TVDB id is already sent as a pin), so the coordinates are simply not expressible on this API version.

What the PR does

  • TheIntroDbClient.IsUnsupportedCoordinateRejection(statusCode, body) (new, internal): a 400 whose body carries the API's range message (Invalid season. Must be between … / Invalid episode. Must be between …) is recognised as a refusal of the coordinates. Matching the message prefix keeps it correct if the API moves the bounds. The client logs it at Debug and reports result = "unsupported_coordinates" instead of the truncated body at Warn.
  • MediaFetchResult.Unsupported() — a final outcome that is deliberately not IsError (which would retry it forever) and not IsNotFound (whose path makes the scan rewrite the item's segments with an empty list).
  • SegmentFetchResult.Unsupported() — WasApiAttempted: true, IsLookupCompleted: false, IsError: false, plus an IsUnsupported flag.
  • TheIntroDbSegmentProvider — an unsupported answer warns once per series (the dedupe dictionaries are static, like _orderSkipsLogged, because a provider instance is short-lived), remembers the address for the rest of the session so later scans do not re-ask a known 400, and returns without writing anything for the item. IsLookupCompleted: false is the point: true would make the scan ReplaceSegments(...) with an empty list and wipe what the item already has.
  • TheIntroDbLibraryScanner — handles the new flag explicitly (processed++; continue;) before the failure-counting branch, and ShouldCountTowardFailureLimit excludes it. Without that, an unsupported run of items would have counted as consecutive API failures and aborted the scan ("API may be down") after 8 episodes of one year-based series.
  • README — the limitation is documented in Metadata Requirements, next to the display-order notes.

Segments for those series need the API to accept season numbers above 1000 (TheIntroDB/theintrodb-api#47 raises the cap to 9999). Until then this PR's contract is: handled gracefully, one line per series, no wasted requests, nothing deleted.

Tests

dotnet test TheIntroDB.sln → 117 passed, 0 failed (was 104 on main; +13 cases). dotnet build clean for both projects (the netstandard2.0 library and the net8.0 test project); the only warnings are the five pre-existing CS8625s at ScanSafetyTests lines 79–130, which this PR does not touch.

The new coverage is the classification and the result contract, and both are pinned by mutation:

  • range detection disabled (IsUnsupportedCoordinateRejection → never matches) → 3 failures, exactly the range rows of OnlyTheSeasonOrEpisodeRangeIsClassifiedAsUnsupportedCoordinates (including the case-insensitive one).
  • ShouldCountTowardFailureLimit(SegmentFetchResult.Unsupported()) is asserted false — that is the assertion standing between a year-based season and an aborted scan.
  • The theory's bodies are the API's real answers: curl "https://api.theintrodb.org/v4/media?tvdb_id=252244&season=2024&episode=196" → that exact 400; the same request with season=1 → 404 no_submissions. A malformed-season body (Invalid season format) is asserted to stay a loud error rather than becoming a silent skip.

Honest limits: the provider/scanner branch itself has no runtime test here (it needs ILibraryManager plus a live item, and this repo mocks no Plugin instance), so it is covered by the flag-contract tests plus the build. And the API has not been re-pointed at a server that accepts 2024 — the classification was verified against the live 400 body above.

Not in this PR

  • The API-side cap (TheIntroDB/theintrodb-api#47), which is what actually delivers segments for those series.
  • MaxEpisodeNumber (10000) and the other result kinds are untouched.

Summary by CodeRabbit

  • Bug Fixes
    • Episodes with season or episode numbers rejected as out of range are now skipped rather than treated as lookup errors.
    • Skipped episodes keep their existing segments and do not count as scan failures. A warning is reported once per series, and rejected lookups are not retried until Emby restarts.
  • Documentation
    • Clarified that Emby may send season numbers up to 9999, while the API may reject seasons above 1000.

Emby passes a year-based season number (Tagesschau S2024) straight to the API,
which caps a season at 1000, so every such episode answered a 400 that this
plugin classified as a client error: the client warned the body, the provider
warned per episode and the scanner warned per item, every scan, on a request
that can never succeed (jellyfin-plugin#39).

Those coordinates cannot be expressed on /media, so the answer is final for the
item. A 400 carrying the range message now maps to a new
MediaFetchResult.Unsupported()/SegmentFetchResult.Unsupported(): the client logs
it at debug, the provider warns once per series, the address is remembered for
the session so later scans do not re-ask, and the scan skips the item without
writing - IsLookupCompleted stays false so a completed 404 cannot make it
ReplaceSegments with an empty list. ShouldCountTowardFailureLimit excludes it,
or eight episodes of one year-based series would abort the scan.

Serving those episodes still needs the API to accept season numbers above 1000.
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d47ca62d-ea2b-45f8-8870-78c1f7ed27d7
Commits

Reviewing files that changed from the base of the PR and between dcd9ec7 and 03405fa.

Files selected for processing: 3
  • README.md
  • TheIntroDB.Tests/ScanSafetyTests.cs
  • TheIntroDB/Providers/TheIntroDbSegmentProvider.cs
Files skipped from review as they are similar to previous changes: 1
  • README.md

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

Walkthrough

The client classifies out-of-range season or episode responses as unsupported. The provider caches rejected lookups for the session and limits warnings to one per series. The scanner skips unsupported results without changing stored segments or counting them toward its failure limit.

Changes: Unsupported Coordinates

Layer / File(s) Summary
API rejection classification
TheIntroDB/Api/MediaFetchResult.cs, TheIntroDB/Api/TheIntroDbClient.cs, TheIntroDB.Tests/ScanSafetyTests.cs
The client recognizes HTTP 400 responses containing season or episode range errors and returns an unsupported result. Tests cover result classification and the rejection conditions.
Provider result and session cache
TheIntroDB/Providers/SegmentFetchResult.cs, TheIntroDB/Providers/TheIntroDbSegmentProvider.cs, TheIntroDB.Tests/ScanSafetyTests.cs
The provider returns an unsupported segment result for rejected coordinates. It caches rejected lookup addresses for the session and logs one warning per series. Tests cover unsupported results and lookup reservation behavior.
Scanner skip behavior and validation
TheIntroDB/Services/TheIntroDbLibraryScanner.cs, README.md
The scanner skips unsupported results without changing stored segments or counting them toward the failure limit. The README describes the year-based season case and its handling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant API as TheIntroDB API
  participant Client as TheIntroDbClient
  participant Provider as TheIntroDbSegmentProvider
  participant Scanner as TheIntroDbLibraryScanner
  API->>Client: HTTP 400 with invalid season or episode range
  Client->>Provider: Unsupported media result
  Provider->>Provider: Cache rejected lookup address and log once per series
  Provider->>Scanner: Unsupported segment result
  Scanner->>Scanner: Skip item without changing stored segments
Loading

Possibly related PRs

  • TheIntroDB/emby-plugin#35: PR #35 adds season and episode coordinates to API v4 lookups, which PR #37 uses to identify out-of-range coordinate responses.
Merge Risk: Minimal · up to 03405

No actionable merge-blocking risk remains in the reviewed change.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main behavior change: an API 400 rejection for an out-of-range season is now treated as a final, unsupported result instead of a transient error. The changeset adds an Unsupported …
Docstring Coverage Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
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.
Full details: Title check

Explanation

The title names the main behavior change: an API 400 rejection for an out-of-range season is now treated as a final, unsupported result instead of a transient error. The changeset adds an Unsupported result state across MediaFetchResult, SegmentFetchResult, TheIntroDbClient, the segment provider, and the library scanner, and the objectives describe the same skip path. The title is concise, specific, and follows the conventional prefix style.

Full details: Docstring Coverage

Explanation

Docstring coverage is 83.33% which is sufficient. 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 6 functions across 6 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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

  • Fix comments: Fix CodeRabbit comments on this PR

Review finding on this PR, verified against the scanner: it reserves a lookup
before calling the provider and refunds it only when the result reports no API
attempt (`!result.WasApiAttempted`). The session memo for an out-of-range
season returned SegmentFetchResult.Unsupported(), which sets WasApiAttempted, so
a cached skip kept its reservation: with enough such items sorting first, every
run would spend MaxLookupsPerRun on the same cached items and never reach the
rest of the library.

The memo hit now returns NotAttempted() - no request goes out, exactly like the
not-found cache hit below it - while a real HTTP 400 still returns Unsupported().
A test pins the flag contract the scanner's refund depends on.

Also rewords the skip log and the README: the API raised its season cap to 9999
and the change is live, so the refusal only happens against an older API
deployment, and the message must not assert the current bound.
@Pasithea0
Pasithea0 force-pushed the fix/unsupported-season-range branch from 0076a80 to 03405fa Compare November 2, 2026 19:59
@Pasithea0

Copy link
Copy Markdown
Member Author

Update after the API change shipped

TheIntroDB/theintrodb-api#47 merged and is deployed — probed against production:

?tvdb_id=71663&season=2024&episode=1   → 404 no_submissions   (was 400)
?tvdb_id=71663&season=9999&episode=1   → 404 no_submissions
?tvdb_id=71663&season=10000&episode=1  → 400 "Invalid season. Must be between 0 and 9999"

So these episodes now fetch normally, and this PR's path only fires against a deployment that still caps a season at 1000 — which is why the classifier matches the message prefix and the skip log no longer asserts the current bound. README and the log line were reworded accordingly (03405fa), and the skip/Unsupported handling stays: it is what keeps an older API from producing a warning per episode and a wasted request per item per scan.

CodeRabbit's finding on the memo hit (it charged a reserved lookup even though no request went out) is fixed in the same commit: the memo now returns NotAttempted(), a real 400 still returns Unsupported(), and a test pins the flag contract. 118 tests pass, 0 failed.

@Pasithea0
Pasithea0 merged commit b0af0a6 into main Nov 2, 2026
3 checks passed
@Pasithea0
Pasithea0 deleted the fix/unsupported-season-range branch November 2, 2026 20:08
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.

1 participant