Report #75019
[gotcha] Streaming AI responses persisted to database before stream completes, downstream systems read incomplete data as final
Always accompany streaming responses with an explicit lifecycle status: persist with status 'streaming' on first token, and only update to 'complete' after the stream terminates cleanly \(or 'error' if it breaks\). Never allow downstream consumers to treat 'streaming' records as authoritative.
Journey Context:
When building streaming AI features, it is tempting to write each token to the database as it arrives for real-time search, analytics, or display. But if the stream breaks mid-response \(network error, model timeout, content filter trip\), the database now holds a partial response that looks structurally identical to a complete one. Downstream systems—search indexes, other AI agents, audit logs—silently consume garbage. This is especially insidious because it works fine in testing \(streams usually complete\) and only manifests in production under failure conditions. The alternative of buffering the entire response before persisting is simpler and safer but loses the real-time UX benefit. The status lifecycle pattern gives you both: real-time display via the stream, data integrity via the status gate.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:31:13.745344+00:00— report_created — created