We Fixed a Bug That Was Cutting Your Briefs Short

Hakivo Team
updateschangelogbugfixengineering
We Fixed a Bug That Was Cutting Your Briefs Short

If you've been using Hakivo over the past few days and noticed some of your daily briefs seemed unusually short or ended abruptly—you weren't imagining things. We found and fixed a bug that was causing some briefs to get truncated mid-sentence.

Here's what happened, what we learned, and how we made sure it won't happen again.

What We Noticed

A user reported that their daily brief looked different from previous ones. Instead of the usual detailed breakdown with news analysis, legislation links, and expert quotes, the brief was surprisingly short—just a few paragraphs that ended mid-URL.

When we dug into the database, we found a pattern: between December 29th and January 3rd, several briefs had only 400-800 characters of content instead of the expected 4,000-8,000 characters. Some literally cut off mid-word.

The Root Cause: AI Rate Limits

Here's what was happening under the hood.

Hakivo generates your daily briefs using Google's Gemini AI. We send it your policy interests, recent legislation, and news articles, and it writes a personalized analysis for you.

During peak times—especially in the morning when most users get their briefs—we were making many requests to Gemini simultaneously. When you hit an AI service's rate limits, something interesting happens: instead of giving you an error, the service sometimes returns a partial response. It starts writing your content, then stops early.

Our system wasn't checking if the response was complete. It just accepted whatever came back and saved it to your brief. So if Gemini said "here's 300 words" instead of "here's 1,500 words," we shrugged and moved on.

What We Learned

This bug taught us an important lesson about working with AI APIs: always validate completeness, not just success.

Most developers are trained to check if an API call succeeded or failed. But with generative AI, there's a third state: partial success. The request didn't fail—you got data back—but you didn't get all the data.

Gemini's API includes a field called finishReason that tells you why the model stopped generating. The options include:

  • STOP: The model finished naturally (this is what you want)
  • MAX_TOKENS: The model hit a length limit
  • SAFETY: Content was filtered for safety reasons
  • OTHER: Something else interrupted generation

We weren't checking this field. Now we do.

The Fix

We added two safeguards:

1. Check why the AI stopped

Before accepting any generated content, we now verify that finishReason equals "STOP". If it's anything else—especially "MAX_TOKENS" or "OTHER"—we throw an error and retry the generation instead of saving truncated content.

2. Minimum word count validation

Even if the API says it finished successfully, we count the words. If a brief has fewer than 400 words, something went wrong, and we reject it. Your daily brief should be substantive enough to actually brief you.

Here's the actual code we added:

// Validate response completeness

const finishReason = response.candidates?.[0]?.finishReason;

if (finishReason && finishReason !== 'STOP') {

throw new Error(`Article generation incomplete: ${finishReason}`);

}

// Validate minimum word count

const wordCount = article.split(/\s+/).length;

if (wordCount < 400) {

throw new Error(`Article truncated: only ${wordCount} words`);

}

Simple checks, but they make a big difference.

Going Forward

This fix has been deployed and is now live. New briefs will always be validated for completeness before being saved.

For the briefs that were already truncated, we're looking into regenerating them. If you have a brief from the past week that seems incomplete, it should be fixed soon.

The Bigger Lesson

Building with AI is different from building with traditional APIs. When you call a database, you either get your data or you don't. When you call an AI model, you might get some of your data—and that partial response can look valid enough to slip through.

As we continue building Hakivo, we're applying this lesson across our entire stack: always verify that AI responses are complete, coherent, and meet quality thresholds. Your daily brief is only useful if it's actually complete.

Thanks for your patience, and thanks to the user who reported the issue. Bug reports like this help us make Hakivo better for everyone.