From 11d3e816e5cde09335081aacc28fc5bd3e4743a4 Mon Sep 17 00:00:00 2001 From: Illia Polosukhin Date: Tue, 3 Feb 2026 00:13:40 -0800 Subject: [PATCH] Add timeout and logging to NEAR AI provider - Add 2 minute timeout to HTTP client for LLM calls - Add debug logging for requests and error logging for failures - Prevents indefinite hangs when NEAR AI is slow or unavailable Co-Authored-By: Claude Opus 4.5 --- src/llm/nearai.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/llm/nearai.rs b/src/llm/nearai.rs index dfa6c96e..86f52b3a 100644 --- a/src/llm/nearai.rs +++ b/src/llm/nearai.rs @@ -26,10 +26,13 @@ pub struct NearAiProvider { impl NearAiProvider { /// Create a new NEAR AI provider. pub fn new(config: NearAiConfig) -> Self { - Self { - client: Client::new(), - config, - } + // Create client with reasonable timeout + let client = Client::builder() + .timeout(std::time::Duration::from_secs(120)) // 2 minute timeout for LLM calls + .build() + .unwrap_or_else(|_| Client::new()); + + Self { client, config } } fn api_url(&self, path: &str) -> String { @@ -47,6 +50,8 @@ impl NearAiProvider { ) -> Result { let url = self.api_url(path); + tracing::debug!("Sending request to NEAR AI: {}", url); + let response = self .client .post(&url) @@ -57,7 +62,11 @@ impl NearAiProvider { .header("Content-Type", "application/json") .json(body) .send() - .await?; + .await + .map_err(|e| { + tracing::error!("NEAR AI request failed: {}", e); + e + })?; let status = response.status(); if !status.is_success() {