fix(subtitle-prefetch): reuse startup runs and prefetch overlap lines

- Warm combined text for overlapping subtitle cues.
- Preserve valid in-flight tokenization across startup restarts while rejecting invalidated cache results.
This commit is contained in:
2026-09-28 01:17:59 -07:00
parent 4648c5e5a1
commit a4325740b7
9 changed files with 274 additions and 6 deletions
+10 -1
View File
@@ -7,6 +7,12 @@ export interface SubtitlePrefetchServiceDeps {
tokenizeSubtitle: (text: string) => Promise<SubtitleData | null>;
preCacheTokenization: (text: string, data: SubtitleData) => void;
hasCachedTokenization?: (text: string) => boolean;
/**
* Bumped whenever the tokenization cache is invalidated. A result is cached only if
* the generation is unchanged since its tokenization began; without this dep every
* result counts as fresh.
*/
getCacheGeneration?: () => number;
priorityWindowSize?: number;
}
@@ -88,9 +94,12 @@ export function createSubtitlePrefetchService(
}
warmedKeys.add(cacheKey);
// Freshness follows the cache generation, not the run: a seek or restart that
// supersedes this run leaves the result valid, and the parser time is already spent.
const generation = deps.getCacheGeneration?.();
try {
const result = await deps.tokenizeSubtitle(cue.text);
if (result && !stopped && runId === currentRunId) {
if (result && generation === deps.getCacheGeneration?.()) {
deps.preCacheTokenization(cue.text, result);
}
} catch {