fix: add provider warmup to prevent cold-start timeout on first channel message

The first API request after daemon startup consistently timed out (120s)
when using channels (Telegram, Discord, etc.), requiring a retry before
succeeding. This happened because the reqwest HTTP client's connection
pool was cold — no TLS handshake, DNS resolution, or HTTP/2 negotiation
had occurred yet.

The fix adds a `warmup()` method to the Provider trait that establishes
the connection pool on startup by hitting a lightweight endpoint
(`/api/v1/auth/key` for OpenRouter). The channel server calls this
immediately after creating the provider, before entering the message
processing loop.

Tested on Raspberry Pi 5 (aarch64) with OpenRouter + DeepSeek v3.2 via
Telegram channel. Before: first message took 2-7 minutes (120s timeout +
retries). After: first message responds in <30s with no retries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Edvard 2026-02-14 18:43:26 -05:00
parent b931aeb56c
commit cc13fec16d
4 changed files with 37 additions and 0 deletions

View file

@ -25,6 +25,14 @@ impl ReliableProvider {
#[async_trait]
impl Provider for ReliableProvider {
async fn warmup(&self) -> anyhow::Result<()> {
if let Some((name, provider)) = self.providers.first() {
tracing::info!(provider = name, "Warming up provider connection pool");
provider.warmup().await?;
}
Ok(())
}
async fn chat_with_system(
&self,
system_prompt: Option<&str>,