From 593c7cbc30fe4634f656f14c88435279bd231de9 Mon Sep 17 00:00:00 2001 From: sudacode Date: Sun, 22 Nov 2026 02:26:36 -0800 Subject: [PATCH] fix(character-dictionary): re-resolve AniList matches cached by the old season resolver Version the anilist-resolution-cache.json file and drop entries written before version 2, so seasons the old resolver landed one short on stop being served from the cache. --- docs/architecture/domains.md | 2 +- .../cache.test.ts | 25 ++++++++++++++++++- .../character-dictionary-runtime/cache.ts | 15 ++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/architecture/domains.md b/docs/architecture/domains.md index 58a04bb3..91c20446 100644 --- a/docs/architecture/domains.md +++ b/docs/architecture/domains.md @@ -67,7 +67,7 @@ Read when: you need to find the owner module for a behavior or test surface `delete-maintenance-scheduler.ts` coalesces and serializes stats deletes; the expensive work runs in `delete-maintenance-worker-thread.ts` while the tracker queues playback writes. Each batch uses one transaction, lexical update, rollup refresh, and incremental lifetime subtraction (`planLifetimeRemovals`/`applyLifetimeRemovals` in `lifetime.ts`). Merges, moves, AniList reassignments, and `stats cleanup -l` use `repairLifetimeSummariesFromMedia` (recompute from the per-video media ledger). The full lifetime rebuild survives only as the empty-table bootstrap; anywhere else it would collapse lifetime totals to the session retention window. - Immersion sync: `src/core/services/stats-sync/`, bound by `src/main/sync-cli.ts`. The sync window and auto-sync scheduler live in `src/main/assemblies/sync.ts`. `snapshot-transfer.ts` selects compressed rsync or scp. `transfer-cache.ts` atomically retains the last successfully received snapshot per hashed peer/database identity under the config directory's `sync-transfer-cache/`. Cache copies seed isolated transfer directories; rsync verifies reconstructed files before the existing merge engine runs. The `--make-temp` / `--remove-temp` helpers accept an internal `--transfer-cache` key, with a fallback for older peers that do not recognize it. -- AniList tracking + character dictionary: `src/core/services/anilist/`, `src/main/runtime/composers/anilist-*` (called by `src/main/assemblies/anilist.ts`), `src/main/character-dictionary-runtime.ts`, `src/main/character-dictionary-runtime/`, assembled by `src/main/assemblies/character-dictionary.ts` +- AniList tracking + character dictionary: `src/core/services/anilist/`, `src/main/runtime/composers/anilist-*` (called by `src/main/assemblies/anilist.ts`), `src/main/character-dictionary-runtime.ts`, `src/main/character-dictionary-runtime/`, assembled by `src/main/assemblies/character-dictionary.ts`. Every consumer maps a parsed title + season to an AniList entry through `anilist/season-resolver.ts` (sequel-chain walk; see its header for what counts as a season). Changing what it returns needs a `MEDIA_RESOLUTION_CACHE_VERSION` bump in `character-dictionary-runtime/cache.ts`, or old matches keep being served from `anilist-resolution-cache.json`. - TMDB live-action metadata: `src/core/services/tmdb/` (client + exact-title resolver), `src/core/services/immersion-tracker/live-action-link.ts` (links an entry to a TMDB title and merges other holders of the same title). The AniList cover-art fetcher calls the resolver as its fallback; `imm_anime.media_kind` marks the result and keeps the entry out of AniList season repair. - Jellyfin integration: `src/core/services/jellyfin*.ts`, `src/main/runtime/composers/jellyfin-*`, assembled by `src/main/assemblies/jellyfin.ts` diff --git a/src/main/character-dictionary-runtime/cache.test.ts b/src/main/character-dictionary-runtime/cache.test.ts index b24a869d..2c4fb17c 100644 --- a/src/main/character-dictionary-runtime/cache.test.ts +++ b/src/main/character-dictionary-runtime/cache.test.ts @@ -4,7 +4,13 @@ import * as os from 'os'; import * as path from 'path'; import test from 'node:test'; import { isDeepStrictEqual } from 'node:util'; -import { getSnapshotPath, readSnapshot, writeSnapshot } from './cache'; +import { + getSnapshotPath, + readCachedMediaResolution, + readSnapshot, + writeCachedMediaResolution, + writeSnapshot, +} from './cache'; import { CHARACTER_DICTIONARY_FORMAT_VERSION } from './constants'; import type { CharacterDictionarySnapshot } from './types'; @@ -121,3 +127,20 @@ test('readSnapshot ignores snapshots written with an older format version', asyn assert.equal(await readSnapshot(snapshotPath), null); }); + +test('media resolutions cached before the season resolver fix are re-resolved', () => { + const outputDir = makeTempDir(); + const cachePath = path.join(outputDir, 'anilist-resolution-cache.json'); + // Written by the old resolver, which counted "Season 2 Part 2" as season 3. + fs.writeFileSync( + cachePath, + JSON.stringify({ + entries: [{ seriesKey: 'mushoku-tensei-s3', mediaId: 166873, mediaTitle: 'Part 2' }], + }), + ); + assert.equal(readCachedMediaResolution(outputDir, 'mushoku-tensei-s3'), null); + + const entry = { seriesKey: 'mushoku-tensei-s3', mediaId: 178789, mediaTitle: 'Season 3' }; + writeCachedMediaResolution(outputDir, entry); + assert.deepEqual(readCachedMediaResolution(outputDir, 'mushoku-tensei-s3'), entry); +}); diff --git a/src/main/character-dictionary-runtime/cache.ts b/src/main/character-dictionary-runtime/cache.ts index e392f0ff..a550c297 100644 --- a/src/main/character-dictionary-runtime/cache.ts +++ b/src/main/character-dictionary-runtime/cache.ts @@ -28,9 +28,17 @@ type MediaResolutionCacheEntry = { }; type MediaResolutionCacheFile = { + version?: number; entries?: MediaResolutionCacheEntry[]; }; +/** + * Bump when the AniList season resolver changes what it returns, so matches it used to get + * wrong are re-resolved instead of being served from here forever. Version 2: split-cour + * continuations and specials no longer count as seasons. + */ +const MEDIA_RESOLUTION_CACHE_VERSION = 2; + function getMediaResolutionCachePath(outputDir: string): string { return path.join(outputDir, 'anilist-resolution-cache.json'); } @@ -55,6 +63,7 @@ function readMediaResolutionEntries(outputDir: string): MediaResolutionCacheEntr const parsed = JSON.parse( fs.readFileSync(getMediaResolutionCachePath(outputDir), 'utf8'), ) as MediaResolutionCacheFile; + if (parsed.version !== MEDIA_RESOLUTION_CACHE_VERSION) return []; if (!Array.isArray(parsed.entries)) return []; const byKey = new Map(); for (const value of parsed.entries) { @@ -74,7 +83,11 @@ function writeMediaResolutionEntries( ensureDir(outputDir); fs.writeFileSync( getMediaResolutionCachePath(outputDir), - JSON.stringify({ entries }, null, 2), + JSON.stringify( + { version: MEDIA_RESOLUTION_CACHE_VERSION, entries } satisfies MediaResolutionCacheFile, + null, + 2, + ), 'utf8', ); }