Skip to content

feat(posts): keep post counters fresh and re-check publishing permissions - #1776

Merged
viethung0o0 merged 1 commit into
mainfrom
feat/posts-fresh-metrics
Nov 25, 2026
Merged

viethung0o0 merged 1 commit into
mainfrom
feat/posts-fresh-metrics

Conversation

@viethung0o0

@viethung0o0 viethung0o0 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #1769 and #1775.

Problem

  • A post's comment, reaction and share counts came only from the 6-hour sync (newest 2,000 posts per inbox). A post first created by an incoming comment never got its counts, so it could show 0 comments while its comments window listed stored comments.
  • The Facebook comment total did not include replies (comments.summary without filter(stream)).
  • "Refresh from channel" only queued a job and the open page did not update.

Changes

  • Fresh counters on view: the Posts page sends the ids of the posts on screen; posts read more than 5 minutes ago are claimed one by one (Redis, 5-minute window) and read by one background job per inbox, so a post is read at most once per window however requests overlap. The list refreshes when the job finishes.
  • Batch reads: new optional post.getPostsMetrics channel action. Facebook uses one Graph batch request (≤ 50 sub-requests); Instagram reads each media. A post the platform answers as gone or unreadable (Graph code 10) is skipped on its own and the rest of the batch is still written; auth and rate-limit answers stop the batch, and a permission error is raised only when no post of the batch could be read. Channels without a batch read are skipped.
  • Metrics-only write mode: the refresh writes only the counts and the observation time (fenced, never an older observation), leaving caption, thumbnail, metadata retry, live state and removal untouched.
  • New post from a comment: its counts are read right away.
  • Threads: its API reports no comment count, so new comments are counted at the webhook (once per stored comment, chosen by a channel capability, never overwritten by a platform read). Counting starts when the inbox is connected.
  • Refresh from channel: reads the post inside the request (shared with the background job, 60 s cooldown, 15 s timeout) and returns { outcome, post }; the deprecated queued: true is kept for existing clients.
  • API / CLI: POST /v1/channel-posts/management/refresh-metrics (channel-posts refresh-metrics), docs updated.

Publishing permissions re-check (Connect tab)

  • When the Connect tab opens, each destination's granted permissions are re-read from the platform, at most every 10 minutes per destination (Redis claim, one background job per workspace, stops on a rate-limit answer).
  • Sources, from the official docs: Facebook Page and Instagram via Facebook Login → debug_token (scopes, is_valid) on the stored Page token; TikTok → the scope of the existing token refresh response (now stored); Instagram Login and Threads document no way to read a token's granted permissions, so they are not re-checked.
  • The write is a compare-and-swap on the inbox token fingerprint and the previous checkedAt, so a re-check that started before a reconnect never overwrites it. A permissionMissing recorded from a refused publish is cleared only when the same token now has every required permission.
  • input_token and appsecret_proof are redacted from logs and error messages.
  • The Connect tab refetches only on events that change a destination; the reconnect button now reads "Reconnect".
  • API / CLI: POST /v1/posts/destinations/recheck-permissions (post-destinations recheck-permissions) → { queued, fresh, failed, skipped }.

Checks

  • pnpm check-types, pnpm lint (invariants, i18n, schema drift)
  • Tests: logger 35, utils 1325, sdk 241, channel-registry 185, database 2145 (+ DB integration test for the permission write), business 11843, messenger 802, instagram 268, instagram-facebook 182, threads 135, tiktok 207, worker 5741, cli 90, builder 12360

@github-actions github-actions Bot added the feature New feature or request label Nov 25, 2026
@viethung0o0 viethung0o0 changed the title feat(posts): keep post counters fresh and refresh a post right away feat(posts): keep post counters fresh and re-check publishing permissions Nov 25, 2026
@viethung0o0
viethung0o0 force-pushed the feat/posts-fresh-metrics branch 2 times, most recently from eb76f0d to 5da98ec Compare November 25, 2026 08:53
@viethung0o0
viethung0o0 marked this pull request as ready for review November 25, 2026 09:03
…ions

- Refresh the counters of the posts on screen when they are older than five minutes, one background read per inbox
- Read Facebook counts with one Graph batch request; a post that is gone no longer stops the other posts of the batch
- Read a new post's counts as soon as its first comment creates it, and count Threads comments from the webhook
- Make Refresh from channel read the post in the request and return the result
- Re-check publishing permissions from the platform when the Connect tab opens, and shorten the reconnect button
- Redact debug_token tokens from logs and error messages
- Add the refresh-metrics and recheck-permissions public APIs and CLI commands
@viethung0o0
viethung0o0 force-pushed the feat/posts-fresh-metrics branch from 5da98ec to cb99ee6 Compare November 25, 2026 09:57
@viethung0o0
viethung0o0 merged commit 3a70261 into main Nov 25, 2026
14 checks passed
sung17 pushed a commit to gitpascal/ChatbotX that referenced this pull request Nov 26, 2026
Resolve conflicts with ChatbotXIO#1769, ChatbotXIO#1776 and ChatbotXIO#1783:
- keep grantedScopes from the direct code exchange next to loginType
- route main's new post listing/management calls (me/media, me/stories,
  managed media) through the login-type-aware Graph client
- keep the AhaChat import availability wrapper on the Instagram picker
- merge the connectSessions.get description with main's selectable guidance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants