Skip to content

fix(community): declare the fixed discovery page size as the minimum - #269

Open
kevin9327 wants to merge 1 commit into
getopenpost:mainfrom
kevin9327:fix/discovery-fixed-page-size
Open

kevin9327 wants to merge 1 commit into
getopenpost:mainfrom
kevin9327:fix/discovery-fixed-page-size

Conversation

@kevin9327

@kevin9327 kevin9327 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Lemmy, PieFed, and PeerTube account content discovery read fixed-size pages (20, 20 and 25) and ignore AccountContentDiscoveryRequest.PageSize. They declared no MinPageSize, though. Near the 250-item initial limit the discovery job asks for the smaller remainder, then rejects the provider's full page as oversized. An account with more than 250 items in the 90-day window therefore failed on the same page every hour and never finished its initial cycle, so routine discovery never started.

The fix declares each adapter's fixed page size as its MinPageSize. X already uses this mechanism for its minimum of 5.

Motivation

In internal/services/analytics/discovery.go (handleAccountContentDiscovery and commitDiscoveryPage):

  • During the initial cycle, pageSize = min(pageSize, remaining) with remaining = 250 - InitialItemsDiscovered. Only when remaining < MinPageSize does it call finishDiscoveryCap instead.
  • commitDiscoveryPage returns provider returned %d discovery items for page size %d when len(page.Items) > pageSize. That is recorded as failed / invalid_provider_page with a one-hour backoff. The cursor and counters are unchanged, so every retry asks for the same page again.

The other eleven discoverers honor the requested size with min(max(1, input.PageSize), …), or with a floor of 5 in X's case. These three can't do that cleanly. Lemmy and PieFed number their pages at a fixed limit, so shrinking the last page would change which posts it covers. Declaring the size they actually read lets the job stop at the limit instead. With 20-item pages that means 240 items rather than 250, and the coverage message is the job's existing "Initial discovery stopped after the 250-item account history limit".

I reproduced this end to end, without committing the harness. I ran the real LemmyAdapter through ReconsiderAccountContentDiscovery and HandleJob against a TLS fake with 300 posts in the window. On main it read pages 1 to 13 and then stopped with cursor="13", status="failed", failure="invalid_provider_page", discovered=240 and initialCompleted=false, next retry in an hour. With this change the initial cycle completes with 240 items stored and the next routine cycle is scheduled.

Testing

  • Backend tests pass (go test ./internal/platform/..., go test ./internal/services/analytics/...)
  • Frontend tests pass (bun run --filter @openpost/web test): no frontend change
  • Linting passes (go vet, gofmt, gofumpt, golangci-lint run ./internal/platform/...: 0 issues, same as main)
  • Manually tested: new TestFixedPageDiscoveryNeverReturnsMoreThanTheSmallestRequestedPage checks the contract the job enforces for each of the three adapters. It asks for the smallest page the adapter declares (max(1, MinPageSize), as the job does), serves a full provider page of in-window items, and requires the page to fit.

Fails on unmodified main:

=== RUN   TestFixedPageDiscoveryNeverReturnsMoreThanTheSmallestRequestedPage/lemmy
        	Error:      	"20" is not less than or equal to "1"
        	Messages:   	a page must fit the smallest page size the adapter declares
=== RUN   TestFixedPageDiscoveryNeverReturnsMoreThanTheSmallestRequestedPage/piefed
        	Error:      	"20" is not less than or equal to "1"
=== RUN   TestFixedPageDiscoveryNeverReturnsMoreThanTheSmallestRequestedPage/peertube
        	Error:      	"25" is not less than or equal to "1"
--- FAIL: TestFixedPageDiscoveryNeverReturnsMoreThanTheSmallestRequestedPage (0.00s)

Passes with the fix. go test ./internal/platform/... and ./internal/services/analytics/... are ok, and go build -tags dev ./... is clean. go test -coverprofile shows every changed line runs under the new test. This PR also edits peertube.go, one function away from #265 and #266. git merge-tree merges all of them cleanly, and lint, build and the platform and analytics tests pass on the merged tree.

Checklist

  • My code follows the project's coding conventions
  • I have added tests that prove my fix is effective
  • I have updated documentation if needed: added changes/discovery-fixed-page-size.md
  • I have used Conventional Commits for my commit messages
  • I have checked that there are no other PRs open for the same issue/feature

Breaking Changes

  • Yes
  • No

Affected Components

  • Backend (Go)

Platform Impact

  • Lemmy
  • PieFed
  • PeerTube

🤖 Generated with Claude Code

Lemmy, PieFed, and PeerTube discovery read fixed pages of 20, 20, and
25 and ignore the requested page size, but declared no MinPageSize.
Near the 250-item initial limit the discovery job asks for the smaller
remainder and rejects a page with more items than it asked for, so an
account with more than 250 items in the window failed on the same page
every hour and never finished its initial cycle. Declaring the fixed
size as the minimum lets the job stop at the limit instead, the way it
already does for X.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 95d0e5a4-cd52-4b1a-8c67-64c29c381053

📥 Commits

Reviewing files that changed from the base of the PR and between 542f87b and 76185f8.

📒 Files selected for processing (5)
  • apps/server/internal/platform/account_content_test.go
  • apps/server/internal/platform/lemmy.go
  • apps/server/internal/platform/peertube.go
  • apps/server/internal/platform/piefed.go
  • changes/discovery-fixed-page-size.md

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.

❤️ Share

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

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