Skip to content

fix(tmdb): repair anilist anime resolution#254

Open
maksii wants to merge 1 commit into
mainfrom
fix/anilist-anime-resolution
Open

fix(tmdb): repair anilist anime resolution#254
maksii wants to merge 1 commit into
mainfrom
fix/anilist-anime-resolution

Conversation

@maksii

@maksii maksii commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

AniList enrichment has been fully broken: no anime upload has ever received a romaji AKA or a MAL ID from a title lookup. Two independent bugs each break it on their own.

The context is dead before AniList is ever called

FetchMetadata does:

requestCtx := ctx
group, ctx := errgroup.WithContext(ctx)   // shadows ctx
...
_ = group.Wait()                          // <- cancels the shadowed ctx

errgroup cancels its derived context once Wait returns, and every closure returns nil, so cancellation lands exactly at Wait. ResolveAnime then ran on that cancelled context and every AniList request died with context canceled before it left the process.

requestCtx already existed for precisely this reason and was already used by the German-title fallback a few lines above; ResolveAnime simply missed it. Switched to requestCtx.

seasonYear is an Int, not a String

anilistQuery selects seasonYear, which AniList types as Int. anilistMedia.SeasonYear was declared string, so decoding a matched result failed with:

json: cannot unmarshal number into Go struct field ...seasonYear of type string

doAniListSearch treats that as a hard failure and the error is not retryable, so the search bailed. Verified against the live API — https://graphql.anilist.co returns "seasonYear": 1998 unquoted. Changed anilistMedia.SeasonYear and AnimeResult.SeasonYear to int.

This also explains why no test caught it: the fixture in anilist_test.go had "seasonYear":"2024" quoted, encoding the bug into the test data. Corrected to a number.

Also

  • AniList search failures were swallowed silently; they now log a warning naming the term.
  • Client.anilistURL replaces the package-level const at the two call sites, so the endpoint can be pointed at a test server. NewClient still defaults it to the real URL.

Tests

TestFetchMetadataResolvesAnimeAKA drives the real FetchMetadata path (nested errgroup and all) against an httptest AniList server and asserts both that AniList was actually queried and that the romaji AKA came back. It fails on main for either bug alone.

Follow-up work (AniList rate limiting and the missing-media contract) is tracked separately.

Summary by CodeRabbit

  • Bug Fixes

    • Improved anime metadata enrichment, including alternate titles and MyAnimeList IDs.
    • Fixed season year handling so numeric values are displayed and processed consistently.
    • Improved reliability of AniList requests and metadata retrieval after concurrent lookups.
    • Added warning visibility when anime searches fail, helping diagnose incomplete results.
  • Tests

    • Added coverage for anime metadata resolution and alternate-title retrieval.
    • Updated retry tests for numeric season-year responses.

Anime lookups ran on the errgroup context, which is canceled once Wait
returns, so every AniList request failed and no romaji AKA was ever
retrieved. The failures were also swallowed silently, and seasonYear
decodes as a number, not a string.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

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

Run ID: 459ce1ad-1f87-4e13-98d8-cc496b16f51f

📥 Commits

Reviewing files that changed from the base of the PR and between 5a00fc7 and a117621.

📒 Files selected for processing (6)
  • internal/metadata/tmdb/anilist.go
  • internal/metadata/tmdb/anilist_test.go
  • internal/metadata/tmdb/client.go
  • internal/metadata/tmdb/metadata.go
  • internal/metadata/tmdb/metadata_test.go
  • internal/metadata/tmdb/types.go

📝 Walkthrough

Walkthrough

Client now stores the AniList endpoint, AniList requests use that endpoint, season years are numeric, search failures are logged, and anime enrichment uses the uncanceled request context with added integration coverage.

Changes

AniList metadata resolution

Layer / File(s) Summary
Client endpoint and season-year contracts
internal/metadata/tmdb/client.go, internal/metadata/tmdb/anilist.go, internal/metadata/tmdb/types.go
The client stores its AniList URL, while AniList and anime result season years use numeric types.
AniList request and error handling
internal/metadata/tmdb/anilist.go, internal/metadata/tmdb/anilist_test.go
AniList search and metadata requests use the configured client URL, failed searches emit warnings, and retry fixtures use numeric seasonYear values.
Metadata enrichment context and coverage
internal/metadata/tmdb/metadata.go, internal/metadata/tmdb/metadata_test.go
Anime enrichment uses requestCtx, with coverage for AniList-derived anime, MAL ID, and AKA values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Poem

A bunny saw AniList hop,
With numeric years in every crop.
Context stayed alive through TMDB’s race,
Warnings now mark each missing trace.
“AKA!” cried Hare, “the tests now glow!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main fix: AniList-based anime resolution in TMDB metadata.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 fix/anilist-anime-resolution

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.

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