Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions crates/bsk-cli/src/daemon/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ async fn handle_tool_dispatch(
Ok(timeout) => timeout,
Err(err) => return ResponseBody::Err(err),
};
let dispatch_timeout = tool_queue_timeout(method, timeout);
let inflight_guard = match state.tool_inflight.register(cli_rpc_id, session_id.clone()) {
Ok(guard) => guard,
Err(err) => {
Expand All @@ -344,12 +345,12 @@ async fn handle_tool_dispatch(
let outcome = if method == Method::ToolRecordStop {
state
.tool_queues
.dispatch_unlocked(&session_id, method, params, timeout, Some(entry))
.dispatch_unlocked(&session_id, method, params, dispatch_timeout, Some(entry))
.await
} else {
state
.tool_queues
.dispatch(&session_id, method, params, timeout, Some(entry))
.dispatch(&session_id, method, params, dispatch_timeout, Some(entry))
.await
};
drop(inflight_guard);
Expand Down Expand Up @@ -507,6 +508,18 @@ fn handle_cancel_with_registry_only(registry: &Arc<AbortRegistry>, params: Value
ResponseBody::Ok(serde_json::to_value(CancelResult { cancelled }).unwrap_or(Value::Null))
}

fn tool_queue_timeout(method: Method, timeout: Duration) -> Duration {
// request-help owns a user-visible timeout and must be allowed to return
// its structured `timed_out` result before the generic queue timeout fires.
// Keep the grace outside the extension-facing params so the user-visible
// deadline remains unchanged.
if method == Method::ToolRequestHelp {
timeout.saturating_add(Duration::from_secs(1))
} else {
timeout
}
}

fn tool_dispatch_timeout(params: &Value) -> Result<Duration, RpcError> {
let Some(raw) = params.get("timeout_ms") else {
return Ok(DEFAULT_TOOL_TIMEOUT);
Expand Down Expand Up @@ -1329,6 +1342,19 @@ mod tests {
assert_eq!(got, std::time::Duration::from_millis(300_000));
}

#[test]
fn request_help_queue_timeout_has_response_grace() {
let timeout = std::time::Duration::from_secs(5);
assert_eq!(
tool_queue_timeout(Method::ToolRequestHelp, timeout),
std::time::Duration::from_secs(6)
);
assert_eq!(
tool_queue_timeout(Method::ToolSnapshot, timeout),
timeout
);
}

#[test]
fn tool_dispatch_timeout_rejects_zero_timeout_ms() {
let params = serde_json::json!({
Expand Down