Skip to content

fix(facebook): read a post's newest comments first when collecting engagement - #267

Open
kevin9327 wants to merge 1 commit into
getopenpost:mainfrom
kevin9327:fix/facebook-newest-comments
Open

kevin9327 wants to merge 1 commit into
getopenpost:mainfrom
kevin9327:fix/facebook-newest-comments

Conversation

@kevin9327

@kevin9327 kevin9327 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

FacebookAdapter.ListComments read a single page of GET /{object-id}/comments and passed no order. With the default toplevel filter the Graph API lists comments oldest first. Once a post had more comments than fit on one page, every engagement poll got back the same oldest page, and no later comment ever reached the inbox. The fix requests order=reverse_chronological, so the page holds the newest comments.

Motivation

The engagement inbox is incremental. persistEngagementComment upserts what each poll returns and never removes comments that a later poll no longer lists. So what matters is that each poll sees the newest comments; older ones were already stored when they were new. Reading oldest first gets this backwards, and it happens on exactly the posts that get the most engagement.

Graph API reference for the comments edge:

  • filter: "toplevel - This is the default. It returns all top-level comments in chronological order, as ordered on Facebook."
  • order: chronological is "Comments sorted by the oldest comments first", and reverse_chronological is "Comments sorted by the newest comments first."
  • The edge is cursor-paginated (results guide: "Stop paging when the next link no longer appears"), and the adapter reads only the first page.

I kept it to the ordering rather than following paging.next. That keeps each poll to one request, which matters for fresh posts that are polled every five minutes. It is the same approach the YouTube adapter already takes with order=time on commentThreads.

Testing

  • Backend tests pass (go test ./internal/platform/...)
  • 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 TestFacebookListCommentsReadsNewestCommentsFirst serves the edge the way the reference describes it. The post has 30 comments and each page holds 25, listed oldest first unless order=reverse_chronological is sent. The test checks that the newest comment is collected. The existing TestFacebookListCommentsMarksPageCommentsAsOurs still passes.

Fails on unmodified main:

=== RUN   TestFacebookListCommentsReadsNewestCommentsFirst
    facebook_comments_test.go:71:
        	Error:      	[]string{"post-1_c1", "post-1_c2", ..., "post-1_c25"} does not contain "post-1_c30"
        	Messages:   	the newest comment must be collected
--- FAIL: TestFacebookListCommentsReadsNewestCommentsFirst (0.00s)

Passes with the fix. go test ./internal/platform/... is ok, and go build -tags dev ./... is clean. go test -coverprofile shows the changed line runs under the new test. I have not tested this against a live Page. The behavior is taken from the Graph API reference quoted above.

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/facebook-newest-comments.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

  • Facebook

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Facebook comments are now retrieved newest first, ensuring recent comments on busy posts appear in the engagement inbox.
  • Documentation
    • Added release notes describing the Facebook comment retrieval fix.

…gagement

ListComments read one page of GET /{object-id}/comments without an
order. With the default top-level filter the Graph API lists comments
oldest first, so once a post had more comments than one page, every
poll returned the same oldest page and new comments never reached the
inbox. Ask for reverse_chronological order, as the YouTube adapter
already does with order=time.

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

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 32b06e4b-8d55-4859-a24d-29f4f2b3d834

📥 Commits

Reviewing files that changed from the base of the PR and between 542f87b and 43b1612.

📒 Files selected for processing (3)
  • apps/server/internal/platform/facebook.go
  • apps/server/internal/platform/facebook_comments_test.go
  • changes/facebook-newest-comments.md

Included review availability: Your plan provides up to 4 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The Facebook adapter now requests top-level comments in reverse chronological order. Tests cover retrieval when comments exceed one page. The changelog records the fix for busy Facebook posts.

Changes

Facebook comment ordering

Layer / File(s) Summary
Newest-first comment retrieval
apps/server/internal/platform/facebook.go, apps/server/internal/platform/facebook_comments_test.go, changes/facebook-newest-comments.md
ListComments adds order=reverse_chronological. Tests verify that the newest comment appears in the returned page. The changelog documents the change.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 43b16

The newest comments are requested and covered by a focused paginated-response test. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: reading Facebook post comments newest-first during engagement collection.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 …
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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