← Back to Pull requests

fix(responses): persist streaming record before releasing response.completed #1238

Closed
unknown closed this pull request without merging on Sep 18, 2026 15:28 UTC
View on GitHub
unknown unknown commented on Sep 18, 2026 12:49 UTC
Author

Summary

openai_stream_events defers the terminal response.completed frame until the inner IRR stream ends, then surfaces it to the pre-IRR openai_response_store as 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, or previous_response_id continuation cannot find (#937). This adds ResponsesState::logical_stream_terminal_emitted, set only by emit_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-Continue results from persist_from_streaming_state — a fail-closed Reject when the immutable owner/request state is missing, or an Err on 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. -->

  • Unit tests — 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; plus emit_deferred_terminal arms persistence while encode_local_completion does not — full suite green)

  • Integration or functional tests — n/a: the race is timing-dependent and unobservable at the SDK layer (a post-stream GET passes pre-fix too); the guarantee lives at the protocol layer and is covered by the deterministic store-filter unit tests

  • make lint (also ran make build, make doc, and cargo clippy -p praxis-ai-apis --all-targets --features store-all)
  • Checklist

  • I reviewed every changed line and can explain the change.

  • New capabilities include an example config and functional example test. — n/a: bug fix, no new filter/config/capability

  • User-facing behavior and generated documentation are updated. — n/a: no user-facing surface or generated-doc change

  • Performance-sensitive changes include appropriate benchmark or load-test evidence. — n/a: no new buffering; persists an already-accumulated record one chunk earlier and fails closed on error

  • Commits are signed and include a Signed-off-by trailer.
  • Breaking changes

    None.

    Diff: 331 lines (+248 / -83) across 4 files Reviewer: franciscojavierarceo Review duration: 159m
    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
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.1% (MEDIUM) · Higher = larger blast radius
    47.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.6% · Safe to merge
    18.6%