debug: Add extensive logging for finish_reason handling
Some checks failed
ci / build-test (push) Failing after 4m52s
Codespell / Check for spelling errors (push) Successful in 4s
sdk / sdks (push) Successful in 11m8s
rust-ci / Lint/Build — macos-14 - aarch64-apple-darwin (release) (push) Has been cancelled
rust-ci / Lint/Build — ubuntu-24.04 - x86_64-unknown-linux-musl (release) (push) Has been cancelled
rust-ci / Lint/Build — windows-11-arm - aarch64-pc-windows-msvc (release) (push) Has been cancelled
rust-ci / Lint/Build — windows-latest - x86_64-pc-windows-msvc (release) (push) Has been cancelled
rust-ci / Lint/Build — ubuntu-24.04 - x86_64-unknown-linux-musl (push) Has been cancelled
rust-ci / Lint/Build — ubuntu-24.04-arm - aarch64-unknown-linux-musl (push) Has been cancelled
rust-ci / Lint/Build — windows-11-arm - aarch64-pc-windows-msvc (push) Has been cancelled
rust-ci / Lint/Build — windows-latest - x86_64-pc-windows-msvc (push) Has been cancelled
rust-ci / Detect changed areas (push) Has been cancelled
rust-ci / Format / etc (push) Has been cancelled
rust-ci / cargo shear (push) Has been cancelled
rust-ci / Lint/Build — macos-14 - aarch64-apple-darwin (push) Has been cancelled
rust-ci / Lint/Build — macos-14 - x86_64-apple-darwin (push) Has been cancelled
rust-ci / Tests — ubuntu-24.04 - x86_64-unknown-linux-gnu (push) Has been cancelled
rust-ci / Tests — ubuntu-24.04-arm - aarch64-unknown-linux-gnu (push) Has been cancelled
rust-ci / Tests — windows-11-arm - aarch64-pc-windows-msvc (push) Has been cancelled
rust-ci / Tests — windows-latest - x86_64-pc-windows-msvc (push) Has been cancelled
rust-ci / CI results (required) (push) Has been cancelled
rust-ci / Lint/Build — ubuntu-24.04-arm - aarch64-unknown-linux-gnu (push) Has been cancelled
rust-ci / Lint/Build — ubuntu-24.04 - x86_64-unknown-linux-gnu (push) Has been cancelled
rust-ci / Tests — macos-14 - aarch64-apple-darwin (push) Has been cancelled

Added debug logging to track:
- Whether assistant_item and reasoning_item exist when finish_reason is received
- Content being emitted
- Completed event transmission

This revealed the actual bug is in HTTP client layer - responses are being
consumed immediately instead of streaming, causing "Request completed" to
appear before any SSE chunks are processed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-17 19:27:07 +01:00
parent 0841ba05a8
commit ffbd2e38ec

View File

@@ -869,13 +869,21 @@ async fn process_chat_sse<S>(
}
"stop" | "length" => {
// Regular turn without tool-call, or hit max_tokens limit.
debug!("Processing finish_reason={}, assistant_item.is_some()={}, reasoning_item.is_some()={}",
finish_reason, assistant_item.is_some(), reasoning_item.is_some());
// Emit the final assistant message as a single OutputItemDone so non-delta consumers see the result.
if let Some(item) = assistant_item.take() {
debug!("Emitting assistant_item: {:?}", item);
let _ = tx_event.send(Ok(ResponseEvent::OutputItemDone(item))).await;
} else {
debug!("No assistant_item to emit");
}
// Also emit a terminal Reasoning item so UIs can finalize raw reasoning.
if let Some(item) = reasoning_item.take() {
debug!("Emitting reasoning_item");
let _ = tx_event.send(Ok(ResponseEvent::OutputItemDone(item))).await;
} else {
debug!("No reasoning_item to emit");
}
}
_ => {
@@ -891,12 +899,14 @@ async fn process_chat_sse<S>(
}
// Emit Completed regardless of reason so the agent can advance.
debug!("Sending Completed event after finish_reason={}", finish_reason);
let _ = tx_event
.send(Ok(ResponseEvent::Completed {
response_id: String::new(),
token_usage: token_usage.clone(),
}))
.await;
debug!("Completed event sent, returning from SSE processor");
// Prepare for potential next turn (should not happen in same stream).
// fn_call_state = FunctionCallState::default();