Skip to content

Fix daily content cron: Claude response truncated by low max_tokens#136

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

Fix daily content cron: Claude response truncated by low max_tokens#136
neverpeakev wants to merge 2 commits into
mainfrom
claude/fix-content-cron-2026-06-25

Conversation

@neverpeakev

Copy link
Copy Markdown
Owner

Summary

Bump MAX_TOKENS in lib/social/post-generator.ts from 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-generate cron failed at 14:00:42 UTC with no row inserted into generated_posts. Vercel runtime log:

[fb-daily-generate] failed at stage=generate:
generateDailyPost failed after 3 attempts.
Last error: not valid JSON (first 200 chars: {"angle_tag":"carpool-line-snack-pouch-rec","content_format":"anecdote", ... "eligibility punct)
Last raw response: ... "caption":"A

The response was always cut off mid-caption value, so every retry hit the same JSON.parse failure. The schema in GeneratedPostSchema allows 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 before caption can fully emit. 1500 was always too tight; today's run finally surfaced it.

Fix

  • lib/social/post-generator.ts: MAX_TOKENS = 4000 with 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' with ig_published_at = null and no ig_failed rows. 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: expired META_MARKETING_API_TOKEN, IG account unlinked, or an unintended status mutation breaking listPendingIgMirror's .eq("status", "fb_published") filter).

Test plan

  • Merge → wait for next 14:00 UTC fire, or trigger manually:
    curl -X POST https://momfluence.app/api/social/fb-daily-generate -H "Authorization: Bearer $CRON_SECRET"
  • Confirm a new row appears in generated_posts with status='fb_published' and a valid fb_post_id.
  • Separately diagnose the IG mirror silent-stall (out of scope here).

Generated by Claude Code

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
@vercel

vercel Bot commented Jun 25, 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 Jun 25, 2026 2:51pm
momfluence-platform Ready Ready Preview, Comment Jun 25, 2026 2:51pm

Request Review

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HvVjdDhC3HHG5sSdcmxp2Y
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