Harden direct provider lifecycle handling

This commit is contained in:
2026-08-16 09:11:22 -05:00
parent 04bc7f7055
commit ae3a8c7b40
10 changed files with 1003 additions and 64 deletions
@@ -313,6 +313,8 @@ impl ResponseStream {
"ask_user_question_enabled": params.ask_user_question_enabled,
"orchestration_enabled": params.orchestration_enabled,
"is_remote_session": params.session_context.is_remote(),
"llm_finished": false,
"response_stream_terminal": false,
"identifiers": serde_json::to_value(ai_identifiers).unwrap_or_else(|_| serde_json::json!({})),
}),
},
@@ -372,6 +374,14 @@ impl ResponseStream {
"reason".to_string(),
serde_json::json!(stream_finished_reason_name(&finished_event.reason)),
);
context.insert(
"llm_finished".to_string(),
serde_json::json!(stream_finished_llm_finished(&finished_event.reason)),
);
context.insert(
"response_stream_terminal".to_string(),
serde_json::json!(true),
);
context.insert(
"elapsed_ms".to_string(),
serde_json::json!(self.time_to_latest_event.num_milliseconds()),
@@ -417,6 +427,11 @@ impl ResponseStream {
serde_json::json!(self.time_to_latest_event.num_milliseconds()),
);
context.insert("recovery".to_string(), serde_json::json!(recovery));
context.insert("llm_finished".to_string(), serde_json::json!(false));
context.insert(
"response_stream_terminal".to_string(),
serde_json::json!(true),
);
context.insert(
"error".to_string(),
serde_json::json!(remote_logging::sanitize_error(error)),
@@ -1115,6 +1130,15 @@ fn stream_finished_reason_name(
}
}
#[cfg(not(target_family = "wasm"))]
fn stream_finished_llm_finished(reason: &Option<response_event::stream_finished::Reason>) -> bool {
matches!(
reason,
None | Some(response_event::stream_finished::Reason::Done(_))
| Some(response_event::stream_finished::Reason::MaxTokenLimit(_))
)
}
#[cfg(not(target_family = "wasm"))]
fn token_usage_context(
token_usage: &[response_event::stream_finished::TokenUsage],
@@ -1,4 +1,24 @@
use super::is_interactive_remote_command;
use warp_multi_agent_api::response_event::stream_finished;
use super::{is_interactive_remote_command, stream_finished_llm_finished};
#[test]
fn response_finish_reason_reports_whether_the_llm_completed() {
assert!(stream_finished_llm_finished(&None));
assert!(stream_finished_llm_finished(&Some(
stream_finished::Reason::Done(stream_finished::Done {})
)));
assert!(stream_finished_llm_finished(&Some(
stream_finished::Reason::MaxTokenLimit(stream_finished::ReachedMaxTokenLimit {})
)));
assert!(!stream_finished_llm_finished(&Some(
stream_finished::Reason::Other(stream_finished::Other {})
)));
assert!(!stream_finished_llm_finished(&Some(
stream_finished::Reason::LlmUnavailable(stream_finished::LlmUnavailable {})
)));
}
#[test]
fn raw_interactive_ssh_is_treated_as_remote_for_acp() {
for command in [