Conversation
…read DiscoverAccountContent pages the channel's videos by offset, but the next offset was start plus the number of videos kept on the page. Videos older than the discovery window, or dropped by normalization, did not count, so the next page started inside the one just read. Once the window's lower bound was reached no video was kept at all, and the same cursor came back until the daily read budget ran out. The cycle never finished, so newer uploads were never discovered. Advance by every video read, and stop at the first video older than the window, since the listing is sorted newest first. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughPeerTube account discovery now stops at videos older than the publication window and advances pagination by every video fetched. A test covers multi-page channels, filtering, cursor progression, and termination. A changelog entry documents the fix. ChangesPeerTube discovery
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The pagination change handles invalid publication timestamps without prematurely stopping discovery, and no actionable merge risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
PeerTube account content discovery could never finish a cycle once a channel had a video older than the discovery window. When that happened, the cycle got stuck on one cursor and new uploads were never discovered.
DiscoverAccountContentpagesGET /api/v1/video-channels/{handle}/videosby offset (start). It computed the next offset asstart + len(page.Items), which counts only the videos it kept. Videos filtered out for predatingPublishedAfter, or dropped by normalization, still occupy their offsets in PeerTube's listing, so the next page started inside the page just read. At the window's lower bound nothing is kept, so the same cursor came back every time.The fix:
start + len(result.Data)sort=-publishedAt(newest first), the same way the Mastodon-compatible discovery stops at its lower boundMotivation
What this does in the discovery job (
internal/services/analytics/discovery.go) on today'smain:CyclePublishedAfteris always set: 90 days back for the initial cycle, and the previous cycle start for routine cycles.NextCursormakes the job continue from that cursor. A new cycle only starts once the cursor is empty.reserveDiscoveryReadshits the defaultReadRequestsPerDayof 10 and defers to the next day. The next day it resumes from the same stuck cursor.I reproduced this end to end, without committing the harness. I ran the real
PeerTubeAdapterthroughReconsiderAccountContentDiscoveryandHandleJob, against a TLS fake channel of 3 videos with one older than 90 days. Onmainthe requests wentstart=[0 2 2 2 2 2 2 2 2 2]and ended withcursor="2",failure="account_read_budget_exhausted"andinitialCompleted=false. With this change it made a single request,cursor="", andinitialCompleted=true, with both in-window videos stored.PeerTube's side, at
v8.3.0:server/core/controllers/api/video-channels/index.ts:/:handle/videosrunspaginationValidator,videosSortValidatorandsetDefaultPagination, sostartis an offset into the sorted listing andtotalcounts the whole channel.server/core/initializers/constants.ts:publishedAtis one of the sortableVIDEOScolumns, which is whatsort=-publishedAtorders by.normalizeAccountContentVideono longer takes the window. The window check moved into the loop, where it can end the page.Testing
go test ./internal/platform/...,go test ./internal/services/analytics/...)bun run --filter @openpost/web test): no frontend changego vet,gofmt,gofumpt,golangci-lint run ./internal/platform/...: 0 issues, same asmain)TestPeerTubeAccountContentDiscoveryCursorReachesTheEnddrives discovery the way the job does, feeding eachNextCursorback. The fake channel has 30 videos: the last three predate the window, and one video on the first page has no usable publish time. The test checks the offsets are0then25and that all 26 in-window videos are returned. It fails if the cursor doesn't reach the end within 5 pages. There was no PeerTube discovery test before.Fails on unmodified
main:Passes with the fix.
go test ./internal/platform/...and./internal/services/analytics/...areok, andgo build -tags dev ./...is clean.go test -coverprofileshows every changed line runs under the new test. This PR and #265 edit different parts ofpeertube.goandpeertube_test.go.git merge-treemerges them cleanly, andgolangci-lintplus the PeerTube tests pass on the merged tree.Checklist
changes/peertube-discovery-cursor.mdBreaking Changes
Affected Components
Platform Impact
🤖 Generated with Claude Code
Summary by CodeRabbit