fix: reconcile complete streamed reasoning items - #219
Conversation
Signed-off-by: StevenWang-CY <203932027+StevenWang-CY@users.noreply.github.com>
Signed-off-by: StevenWang-CY <203932027+StevenWang-CY@users.noreply.github.com>
Signed-off-by: StevenWang-CY <203932027+StevenWang-CY@users.noreply.github.com>
Signed-off-by: StevenWang-CY <203932027+StevenWang-CY@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR fixes streamed reasoning item reconciliation so completed response.output_item.done reasoning items reliably override/merge partial streamed state, while keeping indexed reasoning text and summary parts distinct and preserving correct ordering and storage round-trips.
Changes:
- Introduces typed, indexed reasoning text/summary payloads and updates SSE normalization + tests accordingly.
- Updates
ReasoningOutputto build from bothOutputItemAddedandOutputItemDone, apply indexed done events, and reconcile completed items as authoritative. - Refactors
ResponseAccumulatorto route reasoning lifecycle events without maintaining a second reasoning text model; adds new accumulator tests for reconciliation scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/agentic-server-core/tests/event_normalizer_test.rs | Updates tests to assert the new typed/indexed reasoning payload variants. |
| crates/agentic-server-core/src/types/io/output.rs | Adds nullable-vec deserialization, builds ReasoningOutput from done items, applies indexed done parts, and reconciles completed items. |
| crates/agentic-server-core/src/storage/models/item.rs | Strengthens storage round-trip test to ensure storage marker is stripped and fields survive. |
| crates/agentic-server-core/src/executor/accumulator.rs | Refactors reasoning in-flight handling and completion reconciliation; adds multiple reasoning streaming tests. |
| crates/agentic-server-core/src/events/types.rs | Splits reasoning payloads into distinct text vs summary delta/done variants with indexes. |
| crates/agentic-server-core/src/events/normalize.rs | Parses the new reasoning payload variants from SSE JSON. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: StevenWang-CY <203932027+StevenWang-CY@users.noreply.github.com>
50b95ad to
dab479f
Compare
|
@franciscojavierarceo Thanks for requesting the additional review. I audited all five findings against the Responses event lifecycle. Three identified the same stale-text fallback inconsistency; it is fixed in |
|
@franciscojavierarceo The refreshed head is now green across all nine repository checks, remains approved and cleanly mergeable against current main, and all review threads are resolved. When convenient, could you merge this PR? I will continue monitoring for any follow-up. |
Summary
Fixes #152.
The streaming accumulator previously merged reasoning text and summary events into one unindexed buffer and did not reconcile reasoning
response.output_item.doneevents. A streamed response could consequently omit completed content, summaries,encrypted_content, status, or a reasoning item whose added event was absent.This change:
ReasoningOutput::try_fromfor both added and done-only lifecycle events;ReasoningOutput::apply_done;nullvalues;contentorsummarycollected from preceding part-done events when the complete item omits that array;The Responses event contract defines reasoning done-event text as the full completed text.
ResponseAccumulatortherefore owns event lifecycle routing without retaining another reasoning content model or reconstructing terminal fields from deltas. No database schema or migration changes are required.Test Plan
cargo test -p agentic-server-core reasoning_output_— 3 passedcargo test -p agentic-server-core reasoning_done_text_is_authoritative_even_when_empty— 1 passedcargo test -p agentic-server-core executor::accumulator— 54 passedcargo test -p agentic-server-core --test event_normalizer_test— 40 passedcargo test -p agentic-server-core storage— 69 passed; 3 PostgreSQL environment tests ignoredcargo test -p agentic-server-core— passedcargo test --workspace -- --test-threads=8— passedcargo clippy --workspace --all-targets -- -D warnings— passedcargo fmt --all -- --check— passeduvx pre-commit==4.4.0 run --all-files— passed