Skip to content

Fix daily content cron: IG mirror silently failing since 2026-05-27#151

Draft
neverpeakev wants to merge 2 commits into
mainfrom
claude/fix-content-cron-2026-07-08
Draft

Fix daily content cron: IG mirror silently failing since 2026-05-27#151
neverpeakev wants to merge 2 commits into
mainfrom
claude/fix-content-cron-2026-07-08

Conversation

@neverpeakev

Copy link
Copy Markdown
Owner

Diagnosis

Routine health check on 2026-07-08 found today's FB post published cleanly (gen-2026-07-08-p9hrc, fb_post_id 1086292991223812_122116418852989743) but the IG mirror row still shows status='fb_published' with ig_media_id=null and error_message=null. The IG cron ran at 14:15:08 UTC and returned 200 with no log output.

Pulling recent history from generated_posts:

  • Last successful IG publish: 2026-05-27 (42 days ago).
  • Every daily post from 2026-06-29 → 2026-07-08 is stuck at fb_published with ig_published_at=null, error_message=null. Ten rows total sitting idle.
  • Immediately preceding failures (2026-05-23/24/26) were correctly recorded as ig_failed with Meta's code=100, error_subcode=33, "Authorization Error" — the token needed re-authorization or a missing scope.

What happened: after 2026-05-27, the failure point moved from inside the per-row publishToIg call (which correctly caught + marked ig_failed) to inside fetchPageContext, which runs once before the row loop. That catch block returned 200 with ok:false in the body but wrote no console.error and did not touch any row — so 42 days of failures were invisible to both Vercel runtime logs and the DB. This routine check only caught it because it cross-referenced ig_published_at history.

Almost certainly the same underlying Meta scope/token regression as the late-May ig_failed rows — the page-token likely lost instagram_basic and/or instagram_content_publish when the system-user token was last rotated — but the observability gap prevented anyone from noticing.

Changes

app/api/social/ig-mirror/route.ts

  • console.error at both failure branches (auth/page-context and the per-row publish catch) so future Meta errors surface in Vercel runtime logs.
  • When fetchPageContext throws, mark each row in pending as ig_failed with the error message. Previously the rows were left untouched and re-queued indefinitely, so the failure was doubly hidden (no log, no DB trace). Now the DB carries the diagnosis and the next routine run can grep error_message.

Immediate follow-up (operator)

After merge, the next 14:15 UTC cron will mark today's stuck row (and any others) as ig_failed with the actual Meta response in error_message. Read that error, then either:

  1. Re-issue META_MARKETING_API_TOKEN with instagram_basic + instagram_content_publish scopes, or
  2. If the IG business account got unlinked from the FB page, re-link it in Meta Business Suite.

Once the token is fixed, the 10 stuck rows can be backfilled by clearing their status back to fb_published (they're already ig_failed after this PR runs once, so the listPendingIgMirror filter would skip them).

Test plan

  • Merge, wait for next 14:15 UTC cron, confirm Vercel runtime logs show [ig-mirror] auth/page-context failed: with the Meta error body.
  • Confirm today's row transitions from fb_publishedig_failed with a populated error_message.
  • Fix Meta scopes, then verify next day the row lands as ig_published with an ig_media_id.

Generated by Claude Code

The auth/page-context catch in /api/social/ig-mirror silently returned
200 with no console.error and no DB update, so a Meta scope/token
regression on 2026-05-27 went unnoticed for 42 days. Every daily FB
post since then landed as fb_published with ig_published_at=null and
no error_message — the routine health check had nothing to grab onto.

- console.error at every failure branch so Vercel runtime logs surface
  the exact Meta response.
- When fetchPageContext throws, mark each pending row as ig_failed with
  the error message so the DB carries the diagnosis and rows stop
  re-queuing forever.

Immediate operator action after merge: check the next ig_failed row's
error_message for the Meta error and re-issue META_MARKETING_API_TOKEN
with instagram_basic + instagram_content_publish scopes.
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
momfluence Ready Ready Preview, Comment Jul 8, 2026 2:53pm
momfluence-platform Ready Ready Preview, Comment Jul 8, 2026 2:53pm

Request Review

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.

2 participants