Skip to content

fix(sections): deduplicate items within home rows - #928

Merged
Quick104 merged 1 commit into
mainfrom
codex/fix-home-section-duplicates
Sep 3, 2026
Merged

Quick104 merged 1 commit into
mainfrom
codex/fix-home-section-duplicates

Conversation

@Quick104

@Quick104 Quick104 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #927

Home section responses must not contain the same non-empty content_id more than once within one row. Current main can violate that invariant in Recently Added TV: the repository emits one card-producing event per scan run, so two multi-episode scan batches for the same series produce the same series card twice. Those duplicates can crash clients that use content_id as a keyed-list identity.

The production report did not capture the affected section type. This change therefore fixes the deterministic current-source producer and adds a final response guard for every native section path.

Approach

  • Add an opt-in unique-target mode to the recent-TV repository. It selects the newest event for each target before total calculation, LIMIT, or OFFSET, so duplicates do not consume page slots and the retained card keeps the newest playback anchor.
  • Enable unique-target mode only for native Recently Added section fetching. The catalog section browser keeps its existing event-per-scan behavior, and jellycompat keeps its existing distinct-series compatibility path.
  • Enforce stable first-occurrence uniqueness in the shared section response builder used by both aggregate and per-section endpoints. The guard drops nil or empty-ID cards, allows overlap between different rows, repairs rendered-count totals when exact, and logs only the section identity and duplicate/invalid counts.
  • Keep the hot no-prefix query's expensive anchor aggregation page-bounded. A pre-commit complexity review also consolidated the common result projection and removed a redundant page-local CTE chain.

Validation

The new regressions were confirmed failing before the implementation: the repository returned six events instead of five unique targets, and the response builder retained four keyed items instead of three.

Passed on the final diff:

SILO_TEST_DATABASE_URL='postgres://silo:[email protected]:55433/silo?sslmode=disable' go test -race ./internal/catalog -run '^TestRecentTVRepositoryGroupsScanBatchesAndPaginates$' -count=1 -v
PASS
ok github.com/Silo-Server/silo-server/internal/catalog

go test -race ./internal/api/handlers -run '^TestBuildSectionsResponseDeduplicatesItemsWithinEachSection$' -count=1 -v
PASS
ok github.com/Silo-Server/silo-server/internal/api/handlers

make test-go
PASS

go build ./...
PASS

go vet ./...
PASS

go run github.com/golangci/golangci-lint/v2/cmd/[email protected] run --new-from-merge-base=origin/main ./...
0 issues.

gofmt -l .
(no output)

git diff --check
PASS

make verify-local-paths
PASS

make verify-playback-fixtures
playback fixtures are current

make verify-settings-bindings
settings bindings are current

Additional validation notes:

  • A database-enabled run of all three affected packages reached an unrelated assertion in untouched TestEpisodeSearchPostgresAndDocumentSource: PostgreSQL returned the silo_recommendations vector key with a nil value where the test expected no key. The focused PostgreSQL regression above and the normal full Go suite pass.
  • make verify-settings-bindings-all verified the server binding, then could not run the unchanged web binding's formatting check because prettier is not installed in this worktree. The server-only verification above passes.
  • Web lint, build, and tests were not run because this change has no web code or generated web-contract changes. Screenshots are not applicable to this backend response fix.

Risks

  • The exact section type in the original production response remains unknown. The final response guard enforces the invariant for all section types and logs enough sanitized context to identify any additional producer.
  • Unique-target selection adds scalar aggregation and deduplication to native Recently Added TV. Playback-anchor aggregation remains limited to the requested page.
  • There is no migration or API shape change. Catalog browsing, cross-section overlap, and jellycompat behavior remain unchanged.

If the response guard logs another producer, follow-up work should fix that producer so duplicates cannot consume its item limit before serialization.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: OpenAI Codex desktop app
  • Tool(s): OpenAI Codex with multi-agent collaboration
  • Model(s): primary runtime model identifier not exposed (n/a); independent review subagents used gpt-5.6-sol with high reasoning effort
  • Involvement: AI-assisted
  • Adversarial review: Five independent gpt-5.6-sol high-reasoning subagent workstreams covered producer diagnosis, regression design, catalog/jellycompat/client compatibility, SQL and response-boundary correctness, and over-engineering. The complexity review identified a redundant page-local CTE chain, repeated SQL result projection, a one-use CTE, and an unnecessary slice return; all were removed or consolidated, cutting 76 net lines before the final test pass. The final staged-diff reviews found no unresolved correctness or complexity findings.

Summary by CodeRabbit

  • New Features
    • Recent TV results now avoid repeated content targets, retaining the newest occurrence while preserving distinct episodes.
    • Pagination and result counts reflect deduplicated content.
    • Duplicate items are removed within sections, while the same item may still appear across different sections.
  • Bug Fixes
    • Empty, invalid, and repeated section items are excluded from rendered results.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-03T14:27:44.319931Z 4b4055f PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

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: Team

Run ID: d347d78f-2dcb-4474-8800-0e27a9b78e38

📥 Commits

Reviewing files that changed from the base of the PR and between e767788 and 4b4055f.

📒 Files selected for processing (5)
  • internal/api/handlers/sections.go
  • internal/api/handlers/sections_test.go
  • internal/catalog/recent_tv.go
  • internal/catalog/recent_tv_db_test.go
  • internal/sections/fetcher.go

Included review availability: 2 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.


📝 Walkthrough

Walkthrough

Recent TV queries can collapse repeated targets before counting and pagination. Section response construction also removes invalid and duplicate items within each section while retaining first occurrences and repairing safe totals.

Changes

Recent TV target deduplication

Layer / File(s) Summary
Unique recent TV query paths
internal/catalog/recent_tv.go
Adds UniqueTargets, deduplicates targets for prefix and no-prefix queries, and shares result projection, playback-anchor, ordering, limit, and offset logic.
Recent TV wiring and repository validation
internal/sections/fetcher.go, internal/catalog/recent_tv_db_test.go
Enables unique targets for section fetching. Tests cover deduplication, pagination, totals, continuation flags, ordering, playback episodes, and prefix filtering.
Per-section response cleanup
internal/api/handlers/sections.go, internal/api/handlers/sections_test.go
Removes nil, empty-content, and repeated items within each section. The first occurrence remains, safe totals are updated, and duplicate items across sections remain allowed.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to 4b405

The change deduplicates Recently Added TV targets and invalid or repeated section cards while preserving row boundaries and correcting counts. Focused coverage and reported repository checks support merge readiness.

Sequence Diagram(s)

sequenceDiagram
  participant SectionsFetcher
  participant RecentTVRepository
  participant Database
  participant buildSectionsResponse
  SectionsFetcher->>RecentTVRepository: Request recent TV with UniqueTargets
  RecentTVRepository->>Database: Count and page unique targets
  Database-->>RecentTVRepository: Return deduplicated targets
  RecentTVRepository-->>SectionsFetcher: Return recent TV items
  SectionsFetcher->>buildSectionsResponse: Build section response
  buildSectionsResponse->>buildSectionsResponse: Remove invalid and duplicate section items
Loading

Suggested reviewers: rhainland

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: deduplication of items within home-section rows.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-home-section-duplicates

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

@Quick104
Quick104 merged commit 7c1cb2d into main Sep 3, 2026
4 checks passed
@Quick104
Quick104 deleted the codex/fix-home-section-duplicates branch September 3, 2026 17:31
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