fix(responses): persist streaming record before releasing response.completed #1238
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 331 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.347
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1238"
general
weight: 0.35
franciscojavierarceo
Summary
openai_stream_eventsdefers the terminalresponse.completedframe until the inner IRR stream ends, then surfaces it to the pre-IRRopenai_response_storeas a non-end-of-stream chunk — ahead of the empty end-of-stream callback where streaming persistence historically ran — so a client could observe completion for a record a later GET, DELETE, orprevious_response_idcontinuation cannot find (#937). This addsResponsesState::logical_stream_terminal_emitted, set only byemit_deferred_terminal, so the store persists synchronously before releasing the terminal chunk and then skips the redundant end-of-stream persist, while a buffered local completion (encode_local_completion) leaves the flag unset and still persists at end-of-stream where its body is written only after the store runs. Non-Continueresults frompersist_from_streaming_state— a fail-closedRejectwhen the immutable owner/request state is missing, or anErron a persistence failure — propagate instead of releasing an unpersisted terminal. It is the smallest complete change: one request-scoped flag plus fail-closed propagation, with no new buffering.Related issue
<!-- Contributors must be assigned to the issue before opening a PR. -->
Closes #937
Validation
<!-- List exact commands and any manual or backend-backed proof. -->
cargo test -p praxis-ai-apis --features store-all(streaming terminal persist-before-release, fail-closed on upsert error, reject-propagation on missing owner, EOS fallback; plusemit_deferred_terminalarms persistence whileencode_local_completiondoes not — full suite green)make lint(also ranmake build,make doc, andcargo clippy -p praxis-ai-apis --all-targets --features store-all)Checklist
Signed-off-bytrailer.Breaking changes
None.