Fix daily content cron: Claude response truncated by low max_tokens#136
Draft
neverpeakev wants to merge 2 commits into
Draft
Fix daily content cron: Claude response truncated by low max_tokens#136neverpeakev wants to merge 2 commits into
neverpeakev wants to merge 2 commits into
Conversation
Today's fb-daily-generate failed all 3 attempts because the Opus 4.7 response was truncated mid-caption, breaking JSON.parse. The schema allows captions up to 2000 chars (~600 tokens) which leaves no headroom when paired with the other JSON fields. Also logs a secondary finding: ig-mirror has been silently exiting without publishing for 7+ days. Flagged in routine log for a follow-up diagnosis run. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HvVjdDhC3HHG5sSdcmxp2Y
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HvVjdDhC3HHG5sSdcmxp2Y
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bump
MAX_TOKENSinlib/social/post-generator.tsfrom 1500 → 4000 so Claude Opus 4.7 has enough budget to emit a full caption inside the JSON envelope without truncation.Diagnosis
Today's
/api/social/fb-daily-generatecron failed at 14:00:42 UTC with no row inserted intogenerated_posts. Vercel runtime log:The response was always cut off mid-
captionvalue, so every retry hit the sameJSON.parsefailure. The schema inGeneratedPostSchemaallows captions up to 2000 chars (~600 tokens), and once the model picks a chatty "anecdote"-format draft the rest of the JSON envelope (display, body, rationale, etc.) consumes the remaining ~900 tokens beforecaptioncan fully emit. 1500 was always too tight; today's run finally surfaced it.Fix
lib/social/post-generator.ts:MAX_TOKENS = 4000with an inline note explaining the headroom math.Secondary finding (not in this PR)
Every row from 2026-06-19 → 2026-06-24 shows
status = 'fb_published'withig_published_at = nulland noig_failedrows. The IG mirror cron returns 200 daily but isn't reaching the publish call — it's exiting silently in the early bail-out path (nothing to mirror/auth/page-context). Yesterday's 14:15:08 UTC invocation has no log lines beyond the request itself.Details in
docs/routine-logs/health-2026-06-25.md. Logged here so it's not lost — a follow-up routine run should diagnose (likely candidates: expiredMETA_MARKETING_API_TOKEN, IG account unlinked, or an unintended status mutation breakinglistPendingIgMirror's.eq("status", "fb_published")filter).Test plan
curl -X POST https://momfluence.app/api/social/fb-daily-generate -H "Authorization: Bearer $CRON_SECRET"generated_postswithstatus='fb_published'and a validfb_post_id.Generated by Claude Code