← Back to Pull requests

feat(agent): add streaming delivery boundary with bounded format repair (T39) #179

Closed
unknown closed this pull request without merging on Oct 21, 2026 15:51 UTC
View on GitHub
unknown unknown commented on Oct 21, 2026 02:21 UTC
Author

Describe what this PR does / why we need it

Second and closing part of T39 (#142): brings the structured delivery contract of #173 to the streaming path and adds the bounded format repair. Streaming consumers so far could only observe raw text deltas — no validated delivery boundary existed, and a format-repair retry had no guarantee against replaying side-effectful tools.

Does this pull request fix one issue?

Fixes #142

Describe how you did it

  • ReactAgent.streamResult(...), mirroring the streamMessages entries, returns a Flux<AgentResult>: text-delta chunks are re-published as provisional results with a null status — explicitly unvalidated — and the final aggregated response (located through the existing argiFinalResponse protocol convention, no protocol change) is buffered and finalized once the stream completes, so unverified chunks are never reported as a delivery. A run that ends without a terminal response is reported as INTERRUPTED, never as completed. The terminal usage comes from the final response itself (the streaming path's NodeOutput.tokenUsage is unknown).

  • Bounded format repair inside the finalizer: when validation fails and the agent has a chat client, exactly one single-turn repair re-ask is issued — the request carries no tools (ToolChoice.none()) and never touches the graph, so side-effectful tools cannot be replayed. The repaired output is re-validated without a second attempt (bounded like ModelRetryInterceptor's attempt model); a still-invalid result is marked REPAIRED_STILL_INVALID, and a failing repair client leaves the original failure untouched.

  • callResult automatically gains the repair capability through the same finalizer.
  • Describe how to verify it

  • StructuredOutputFinalizerTest (+3): repair turns an invalid output into a completed delivery (one client call); a still-invalid repair is marked and not retried; a failing repair client keeps the original failure.

  • ReactAgentStreamResultTest (4 cases, scripted streaming client end to end): provisional chunks carry null status and the last element is the validated COMPLETED delivery with usage; an invalid stream output is repaired exactly once; without repair capability the delivery reports VALIDATION_FAILED; and a guard test asserting the legacy streamMessages behavior is untouched.

  • ReactAgentCallResultTest: two cases adapted to the repair semantics.

  • Run:
  •   ./mvnw -pl argi-agent-framework -am test -DskipTests=false \
        -Dtest='StructuredOutputFinalizerTest,ReactAgentStreamResultTest,ReactAgentCallResultTest' \
        -Dsurefire.failIfNoSpecifiedTests=false
      

  • Full regression: graph-core 829 + agent-framework 1217 tests; only the documented pre-existing Windows-environment failures remain (identical on clean main).
  • Special notes for reviews

  • No protocol change: argiFinalResponse already marks the final aggregated block; streamResult is a consumer-side extension, and AgentChatProtocol/NodeExecutor are untouched.

  • Provisional chunks deliberately reuse the AgentResult shape with a null status instead of extending the four-state terminal vocabulary — the terminal statuses describe deliveries, and a delta is not a delivery.

  • The repair prompt includes the previous output verbatim (needed for the model to fix it); issue summaries returned to callers still never echo the full content.

  • The repair prompt/construction is minimal by design per the agreed "keep it simple" scope; parameterizing attempts/prompt template can follow later.
  • Diff: 444 lines (+333 / -111) across 5 files Reviewer: yuluo-yx Review duration: 810m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 444 lines diff across 5 files
    0.45
    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%
    56%
    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.365
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #179"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 45.3% (MEDIUM) · Higher = larger blast radius
    45.3%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 19.6% · Safe to merge
    19.6%