Repository navigation
fix(responses): preserve raw reasoning_content without an explicit summary request - #14689
kshivam4781 wants to merge 15 commits into
Conversation
…mmary request Dynamo's Responses API converter silently dropped non-empty backend reasoning_content whenever the request did not set reasoning.summary, even though the raw-reasoning event/output-item lifecycle it builds does not actually depend on summary mode. Removes the reasoning_summary_requested() gate from both the streaming and non-streaming reasoning-conversion paths so raw reasoning is preserved whenever the backend returns it, and updates the two tests that had locked in the old (gate-on) behavior. Fixes ai-dynamo#14069. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WfK6bG4HF5WFxKypPaRYUv Signed-off-by: Shivam <[email protected]>
… request Companion change to the mod.rs fix: the streaming converter gated the raw-reasoning event lifecycle (response.reasoning_text.*) on reasoning.summary being requested, so a streaming Responses call lost backend reasoning_content entirely when the caller only asked for the final response (no reasoning.summary). Removes that gate and updates the test that had locked in the old (gate-on) behavior. Part of ai-dynamo#14069. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WfK6bG4HF5WFxKypPaRYUv Signed-off-by: Shivam <[email protected]>
|
👋 Hi kshivam4781! Thank you for contributing to ai-dynamo/dynamo. Just a reminder: The 🚀 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review. WalkthroughThe Responses API now preserves non-empty backend ChangesReasoning preservation
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~15 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Raw reasoning content is preserved consistently for streaming and non-streaming Responses requests without changing requested-summary behavior. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Comment |
| #[test] | ||
| fn test_reasoning_text_requires_explicit_request() { | ||
| fn test_reasoning_text_preserved_without_explicit_summary_request() { | ||
| // Regression test for #14069: reasoning.summary is not the only way to |
There was a problem hiding this comment.
The test name and assertions already state this regression's lasting behavior; the added comment only repeats them and records issue history.
🤖 AI Fix
Remove the comment.
| #[test] | ||
| fn test_reasoning_without_requested_summary_emits_no_events() { | ||
| fn test_reasoning_without_requested_summary_still_streams_raw_reasoning() { | ||
| // Regression test for #14069: reasoning.summary is not the only way to |
There was a problem hiding this comment.
This repeats the test name and event assertions while adding only issue-history context, so it does not preserve a non-obvious constraint.
🤖 AI Fix
Remove the comment.
Per review feedback (dynamo-review-agent) on PR ai-dynamo#14689: the comment restated the test name and assertions without adding a non-obvious constraint. Removed. Signed-off-by: Shivam <[email protected]>
Per review feedback (dynamo-review-agent) on PR ai-dynamo#14689: the comment restated the test name and assertions without adding a non-obvious constraint. Removed. Signed-off-by: Shivam <[email protected]>
|
/ok to test 2f2d59d |
KrishnanPrash
left a comment
There was a problem hiding this comment.
Hey @kshivam4781,
Could you take a look at the review comments and address them? 🙂
… output, fix reasoning-only completed backstop Addresses @KrishnanPrash's review: - stream_converter.rs: dropped the `!self.message_started` gate entirely on reasoning deltas. `append_reasoning_delta` already opens a fresh reasoning item whenever one isn't active, so this now matches the non-streaming path (which has no ordering gate at all) instead of silently dropping reasoning that resumes after visible text/a tool call, or reasoning preceded by a whitespace-only content delta. - Both files: `reasoning.is_empty()` -> `reasoning.trim().is_empty()`, matching aggregator.rs's `move_reasoning_to_content_when_empty` check, so whitespace-only reasoning_content no longer opens an item with nothing in it. - mod.rs: the `if output.is_empty()` empty-message backstop no longer fires for a reasoning-only turn (output now always contains the reasoning item, so it's never actually empty). Replaced with an explicit check for a message/function-call item, gated on `!output_limit_reached` so an incomplete reasoning-only turn still stays reasoning-only. - Removed the duplicate 5-line policy comment from stream_converter.rs (kept in mod.rs); documented why `summary` on ReasoningItem is deliberately always empty now. - Updated/added tests for all of the above, including renaming the two tests that were locking in the old (dropped) behavior. Validation: `cargo test -p dynamo-llm --lib --no-default-features protocols::openai::responses::` - 112 passed, 0 failed (up from 107 before this commit). `cargo fmt --check` clean. `cargo clippy -p dynamo-llm --lib --no-default-features` clean on both changed files (2 pre-existing warnings elsewhere, in codec.rs, are unrelated to this change). Still open, documentation-only per the review: the context-cost note about raw reasoning being echoed back into multi-turn input as plaintext - will add to the PR description directly rather than as a code comment. Signed-off-by: Shivam <[email protected]>
The just-merged main brought in an unrelated refactor (responses_incomplete_reason(), replacing the old output_limit_reached: bool with incomplete_reason: Option<&str> so incomplete responses can also carry a content_filter reason, not just max_output_tokens). git merged that cleanly with no conflict markers, but left my empty-output backstop check referencing the now-removed output_limit_reached, which does not compile. Fixed by switching to incomplete_reason.is_none() (same failing-CI job that caught it: lib/bindings/kvbm rust-tests/rust-clippy, which resolve this crate against a fresh lockfile including main's changes, unlike my own no-default-features build which had not picked up the rename yet). Rebuilt full local Debug + no-default-features tree against the merged branch tip: cargo check -p dynamo-llm --lib clean; cargo test -p dynamo-llm --lib protocols::openai::responses:: -- 119 passed, 0 failed (was 112 before the merge; the 7 new tests are main's own thinking_token_budget additions, unaffected by this change); cargo fmt -p dynamo-llm --check clean. Signed-off-by: Shivam <[email protected]>
|
/ok to test 6622b20 |
| && !reasoning.is_empty() | ||
| && !self.message_started | ||
| && self.params.reasoning_summary_requested() | ||
| && !reasoning.trim().is_empty() |
There was a problem hiding this comment.
BEFORE:
if let Some(reasoning) = delta.reasoning_content.as_deref()
&& !reasoning.trim().is_empty()
{
AFTER:
if let Some(reasoning) = delta.reasoning_content.as_deref()
&& !reasoning.is_empty()
&& (self.active_reasoning_index.is_some() || !reasoning.trim().is_empty())
{
My earlier trim suggestion was wrong for this site: it runs per token delta, and Qwen-family tokenizers emit a bare " " before every digit, so streamed reasoning reads add2 and3 while unary keeps add 2 and 3. Skip whitespace only when it would open an item.
| // still a real, if empty-looking, output item -- output_index 0), so | ||
| // the reasoning that follows lands after it, not before. | ||
| let output = conv.completed_output(); | ||
| assert!(matches!(output[0], OutputItem::Message(_))); |
There was a problem hiding this comment.
// The whitespace content delta opened the message item first (it's
// still a real, if empty-looking, output item -- output_index 0), so
// the reasoning that follows lands after it, not before.
let output = conv.completed_output();
assert!(matches!(output[0], OutputItem::Message(_)));
This locks in the wrong order: a leading "\n" opens the message item before any answer, so SSE returns [message, reasoning] while unary returns [reasoning, message]. Holding whitespace-only content until the first real text, as the preprocessor does with pending_content, keeps the unary order.
| /// for the same generation. | ||
| #[test] | ||
| fn test_reasoning_text_ignores_updates_after_visible_output() { | ||
| fn test_reasoning_text_resumes_as_new_item_after_visible_output() { |
There was a problem hiding this comment.
fn test_reasoning_text_resumes_as_new_item_after_visible_output() {
With Length instead of Stop after the resumed reasoning, SSE marks the message incomplete as well as the second reasoning item, because terminal_output_index ignores reasoning and nothing closes the message when reasoning resumes. Function calls get that close in append_reasoning_delta.
| // not left with just a reasoning item; an incomplete turn (Length or | ||
| // ContentFilter) is left as reasoning-only, since the model was cut off | ||
| // mid-thought and never got to an answer. | ||
| if incomplete_reason.is_none() |
There was a problem hiding this comment.
BEFORE:
if incomplete_reason.is_none()
&& !output
.iter()
.any(|item| matches!(item, OutputItem::Message(_) | OutputItem::FunctionCall(_)))
{
AFTER:
if output.is_empty()
|| (incomplete_reason.is_none()
&& !output
.iter()
.any(|item| matches!(item, OutputItem::Message(_) | OutputItem::FunctionCall(_))))
{
This also removes the empty message from a truncated turn with no reasoning: an empty Length turn returned [message "" incomplete] on main and now returns output: []. Keeping output.is_empty() || limits the change to reasoning-only turns, as the comment above says.
| // delta (e.g. a bare "\n\n" left by a parser that does not trim) is treated | ||
| // as no reasoning at all. Unlike the old gate, this no longer depends on | ||
| // `message_started`: reasoning resuming after visible output still opens a | ||
| // new item via `append_reasoning_delta` below, matching the unary path, |
There was a problem hiding this comment.
// `message_started`: reasoning resuming after visible output still opens a
// new item via `append_reasoning_delta` below, matching the unary path,
// which does not gate on delivery order at all.
This parity claim is false: unary merges resumed reasoning into one item and trims once on the whole string, so item count and text differ. Please drop it; the field doc at line 55 also still says items reopen only after a tool call.
| } | ||
|
|
||
| /// Reasoning resuming after visible output is captured as a new reasoning | ||
| /// item, matching the unary path (mod.rs), which does not gate reasoning on |
There was a problem hiding this comment.
/// Reasoning resuming after visible output is captured as a new reasoning
/// item, matching the unary path (mod.rs), which does not gate reasoning on
/// delivery order at all -- so streaming and unary return the same reasoning
/// for the same generation.
The test never runs the unary path, and unary returns one merged item ("summaryresumed") where this stream returns two, so "the same reasoning" does not hold. Describe only what the test checks.
KrishnanPrash
left a comment
There was a problem hiding this comment.
@kshivam4781 can you take a look at the latest round of comments 🙂
… backstop Addresses all 6 open review comments from @KrishnanPrash: - Skip whitespace only when it would open a reasoning item, not per-token (fixes Qwen space-before-digit deltas) - Hold whitespace-only content deltas (pending_content) until first real text, matching unary item ordering - Close the open message item when reasoning resumes after visible output, so terminal_output_index doesn't wrongly mark an already-finished message incomplete - output.is_empty() || (...) backstop so an empty Length turn with no reasoning still gets [] instead of a stray empty message... (see diff for exact condition) - Removed the false streaming/unary "same reasoning" parity claims from comments, updated the reasoning_items field doc - Reworded a test doc comment to describe only the streaming behavior under test cargo test -p dynamo-llm --lib --no-default-features protocols::openai::responses:: — 121 passed, 0 failed (up from 112), including 2 new regression tests. cargo fmt clean. cargo clippy clean (one unrelated pre-existing lint in codec.rs suppressed, not touched by this change). Signed-off-by: Shivam <[email protected]>
|
/ok to test 1a7d624 |
|
@kshivam4781 Can you please fix the merge conflicts and rebase on latest main? |
Signed-off-by: Krishnan Prashanth <[email protected]>
…-summary Signed-off-by: Krishnan Prashanth <[email protected]>
|
I pushed two commits to this branch to close the last review round and the merge conflict:
What the fix changes in
Five new regression tests cover these cases. Each one fails on 1a7d624 and passes here. Two tool-call behaviors stay the same as on main: argument fragments that arrive after resumed reasoning, and unfinished calls marked completed on error. They are out of scope for this PR. Thank you for working through the review rounds. |
|
/ok to test 7497409 |
1 similar comment
|
/ok to test 7497409 |
⏹️ Dynamo PR CI cancelled — run 38002224800 (attempt 1) on
|
| Other | Jobs |
|---|---|
| dynamo-runtime | ⏹️ 1 |
| planner | ⏹️ 2 ✅ 3 |
Failure details
No job failed outright: the 3 cancelled jobs were not fail-fast or manual/concurrency cancels. GitHub cancelled each one when it hit its job time limit (annotation: "The job has exceeded the maximum execution time").
- ⏹️ dynamo-runtime / image / Build multi-arch cuda13.0: hit the 1h0m0s job limit during
Build and Push Test Image. The multi-arch build was still going (the arm64test_imagestage started at 23:36) when it was cancelled at 00:01. Logs show no build error. - ⏹️ planner / Compliance cpu, arm64 and planner / Compliance cpu, amd64: both hit the 15m0s job limit (
compliance_timeout_minutes: 15) duringCompliance scan, so no compliance CSV was produced.
These look like slow runners or builds rather than code errors. Rerunning the failed jobs is likely enough.
For agents
{"pr": 14689, "run_id": 38002224800, "run_attempt": 1, "head_sha": "7497409e3bdf0e566c2e294a1e578a01c927d2c1",
"failures": [],
"cancelled": [{"job": "dynamo-runtime / image / Build multi-arch cuda13.0", "job_id": 114062905999, "step": "Build and Push Test Image", "signature": "job exceeded maximum execution time of 1h0m0s", "log_cmd": "gh run view --job 114062905999 -R ai-dynamo/dynamo --log"},
{"job": "planner / Compliance cpu, arm64", "job_id": 114076169890, "step": "Compliance scan", "signature": "job exceeded maximum execution time of 15m0s", "log_cmd": "gh run view --job 114076169890 -R ai-dynamo/dynamo --log"},
{"job": "planner / Compliance cpu, amd64", "job_id": 114076169901, "step": "Compliance scan", "signature": "job exceeded maximum execution time of 15m0s", "log_cmd": "gh run view --job 114076169901 -R ai-dynamo/dynamo --log"}]}Posted automatically by Devin for run 38002224800. Updated on every full-CI run of this PR.
…-summary Signed-off-by: Shivam <[email protected]>
The prior merge-conflict resolution on this branch left one extra closing brace after the function-call-delta `if` block in append_chunk_events, which broke the file structure and caused CI to fail with "unexpected closing delimiter" at compile time. This removes that single extra `}` line; no other logic changes. Signed-off-by: Shivam <[email protected]>
The previous commit's web-editor edit (removing a stray brace) was built from a base64-decoded byte string treated as Unicode text, which double-encoded two non-ASCII characters elsewhere in the file (an em-dash and an emoji/CJK comment) into mojibake. This redoes that edit with proper UTF-8 decoding, restoring those two lines to their original bytes while keeping the brace fix. Signed-off-by: Shivam <[email protected]>
Overview:
Dynamo's Responses API converter silently drops non-empty backend
reasoning_contentwhenever the request did not setreasoning.summary, even though the raw-reasoning event/output-item lifecycle it builds does not actually depend on summary mode. This PR removes that gate so reasoning is preserved whenever the backend returns it.Details:
lib/llm/src/protocols/openai/responses/mod.rs: removed thereasoning_summary_requested()gate from the non-streaming reasoning-conversion path (chat_completion_to_response), and removed the now-unusedreasoning_summary_requested()helper.lib/llm/src/protocols/openai/responses/stream_converter.rs: removed the equivalent gate from the streaming conversion path (ResponseStreamConverter::append_chunk_events).reasoning.summarywas requested.Where should the reviewer start?
lib/llm/src/protocols/openai/responses/mod.rsaround line 1159 (non-streaming) andlib/llm/src/protocols/openai/responses/stream_converter.rsaround line 411 (streaming) — these are the two gate removals the issue points at directly.Related Issues
🔗 This PR is linked to an issue:
Closes #14069
Summary
reasoning_contentis now surfaced as aReasoningItem(rawcontent, emptysummary) whenever the backend returns it, for both/v1/responsesstreaming and non-streaming paths, regardless of whether the request setreasoning.summary.ResponseParams::reasoning_summary_requested()helper (no remaining callers after the gate removal).Validation
cargo test -p dynamo-llm --lib --no-default-features protocols::openai::responses::(run withCARGO_PROFILE_TEST_DEBUG=0to fit the local build machine's memory): 107 passed; 0 failed; 0 ignored, including both rewritten regression tests:stream_converter::tests::test_reasoning_without_requested_summary_still_streams_raw_reasoning ... oktests::test_reasoning_text_preserved_without_explicit_summary_request ... okcargo check -p dynamo-llm --liband--tests(default features, i.e. includingblock-manager/CUDA/NIXL): both pass cleanly with no errors, so the change also type-checks under the default feature set used by CI.grep -rnacrosslib/thatreasoning_summary_requested()had exactly two call sites before this change (one per file) and no other references anywhere, so removing both gates and the helper itself leaves no dangling references.Fixes #14069.
Summary by CodeRabbit
Context cost of preserving raw reasoning
Per review: once raw
reasoning_contentis always surfaced as aReasoningItem, a caller that feeds the assistant's prior output back in as input for a follow-up turn (the standard multi-turnItem::Reasoningecho path) is echoing that raw chain-of-thought back in as plaintext, not just a summary.encrypted_contentonReasoningItemis alwaysNonehere, so there is no encrypted-blob alternative to point callers at.Two things follow from that: (1) a real per-turn token/context cost, since raw reasoning is typically far longer than a
reasoning.summarywould have been, and (2) a mild content-exposure consideration for multi-turn conversations, since the model's raw reasoning for turn N becomes part of the literal prompt text for turn N+1 rather than staying server-side. Neither is new to this PR's core behavior change (any caller already got the raw reasoning back once per turn whenreasoning.summarywas requested) — this PR just removes the last case where that could silently not happen, so it widens how often the cost applies rather than introducing it.