Skip to content

[codex] Gate episode refresh debt on provider provenance - #60

Merged
Quick104 merged 1 commit into
mainfrom
codex/episode-refresh-debt-provenance
Jun 7, 2026
Merged

Quick104 merged 1 commit into
mainfrom
codex/episode-refresh-debt-provenance

Conversation

@Quick104

@Quick104 Quick104 commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add an explicit EpisodeHasActionableMetadataDebt predicate for refresh scheduling
  • keep EpisodeHasIncompleteMetadata as the broader quality/incompleteness check
  • route stale metadata refresh requests, episode debt sync, and the series episode_metadata_incomplete state through actionable debt
  • add predicate and service-level tests for provider-matched Episode N rows, empty provider overviews, provisional TBD, scanner fallback, missing IDs, and recent missing stills

Root Cause

EpisodeHasIncompleteMetadata treated any Episode N title or empty overview as incomplete. That predicate was also used as refresh debt, so provider-matched episodes whose canonical metadata is Episode 1 or has no overview could permanently regenerate episode refresh debt.

Behavior

Provider-matched episodes with a provider ID no longer create actionable refresh debt solely because the provider title is Episode N or the overview is empty. Empty titles, scanner fallback rows, missing provider IDs, provider TBA/TBD, and recent episodes missing still images still create refresh debt.

Validation

  • go test ./internal/metadata ./internal/api/handlers ./internal/adminjob -count=1
  • go test ./...
  • make verify-local-paths

AI Disclosure

Implemented with Codex.

Summary by CodeRabbit

  • Bug Fixes
    • Improved metadata refresh decision logic for episodes and seasons. The system now uses more sophisticated criteria—including provisional titles, provider identifiers, and recent air dates—to determine which content needs metadata updates, resulting in more accurate refresh targeting.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7d8d5cd9-6e88-4825-9af1-17d34c57415e

📥 Commits

Reviewing files that changed from the base of the PR and between fbd77f9 and d318768.

📒 Files selected for processing (5)
  • internal/api/handlers/items.go
  • internal/metadata/episode_completeness.go
  • internal/metadata/episode_completeness_test.go
  • internal/metadata/service.go
  • internal/metadata/service_test.go

📝 Walkthrough

Walkthrough

This PR introduces EpisodeHasActionableMetadataDebt, a more targeted metadata completeness check that determines when episode metadata can benefit from another provider refresh. The function replaces EpisodeHasIncompleteMetadata across refresh debt orchestration and API handlers, accounting for provider identifiers, provisional titles, and scanner fallback sources.

Changes

Actionable Metadata Debt

Layer / File(s) Summary
Core actionable debt detection and testing
internal/metadata/episode_completeness.go, internal/metadata/episode_completeness_test.go
Episode regexes are consolidated into a single block. Internal helpers isEpisodeProvisionalTitle and episodeHasProviderMatch support the new exported EpisodeHasActionableMetadataDebt(ep, now) function, which detects when metadata is improvable via empty title, scanner fallback source, missing provider IDs, provisional titles, or recent air-date still-image gaps. Comprehensive test cases cover provider-numbered episodes, provisional/placeholder titles, scanner fallback scenarios, and recency-based still requirements.
Service refresh debt orchestration using actionable debt
internal/metadata/service.go, internal/metadata/service_test.go
Refresh debt decision logic in syncRefreshDebtForSeason, syncRefreshDebtForEpisode, refreshSeriesEpisodeMetadataState, and syncVisibleEpisodeRefreshDebt now uses actionable metadata debt. Test TestRefreshSeriesEpisodeMetadataStateUsesActionableDebt verifies series-level incomplete flag behavior when actionable episode debt exists (cleared after refresh) or when only scanner-fallback episodes exist (remains set).
API handler stale refresh conditions
internal/api/handlers/items.go
maybeRequestStaleEpisodeMetadataRefresh and maybeRequestStaleSeasonMetadataRefresh switch from incomplete metadata checks to actionable metadata debt checks with current time.

Sequence Diagram(s)

This PR does not meet the criteria for sequence diagram generation—the changes are primarily a logic substitution replacing one internal function call with another across multiple call sites, without introducing new component interactions or significant control flow changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

✨ 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 codex/episode-refresh-debt-provenance

Comment @coderabbitai help to get the list of available commands and usage tips.

@Quick104
Quick104 marked this pull request as ready for review June 7, 2026 02:43
@Quick104
Quick104 merged commit 4a4956b into main Jun 7, 2026
1 check was pending
@Quick104
Quick104 deleted the codex/episode-refresh-debt-provenance branch June 7, 2026 02:43

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d31876812c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +79 to +80
if !episodeHasProviderMatch(ep) {
return true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat plugin-only provider IDs as matches

When an episode comes from a plugin whose capability is not tmdb, tvdb, or imdb, this new check keeps returning actionable debt even after a successful provider refresh. PluginProvider.GetEpisodes can populate EpisodeResult.ProviderIDs with p.capabilityID, but persistSeasonsAndEpisodes only copies imdb/tmdb/tvdb onto models.Episode, so a custom-provider episode is persisted as MetadataSource: "provider" with all three checked ID fields empty. In that context EpisodeHasActionableMetadataDebt never clears the episode/season debt and the scheduled refresh queue can repeatedly refresh already-provider-backed episodes.

Useful? React with 👍 / 👎.

Comment on lines +79 to +80
if !episodeHasProviderMatch(ep) {
return true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the debt backfill predicate in sync

On fresh databases or upgrades where migration 100 runs with this code, the migration still inserts due episode debts using the old incomplete predicate (Episode N titles and empty overviews), while this new predicate immediately treats provider-backed episodes with TMDB/TVDB/IMDB IDs as non-actionable. In libraries with many provider-numbered or overview-less episodes, the scheduler will enqueue and run an avoidable refresh for each of those rows just to clear the debt afterward, so the backfill/cleanup criteria should be updated to match the new actionable definition.

Useful? React with 👍 / 👎.

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