Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Warm up Laya once it comes online so the first query isn't a cold-start timeout

Oleksandr Ivanchenko02d05e1dd74c
diff --git a/src/router/laya.rs b/src/router/laya.rs
index 8b8314ac..2fe19445 100644
--- a/src/router/laya.rs
+++ b/src/router/laya.rs
@@ -56,6 +56,22 @@ impl LayaRouter {
.unwrap_or(false)
}
+ /// Sends a throwaway decision so the first real query doesn't pay the
+ /// model's cold-start cost (which can exceed the 1.5s routing timeout).
+ pub async fn warm_up(&self) {
+ let payload = json!({
+ "state": {"prompt": "hello, can you help me plan a trip?"},
+ "questions": {"warmup": {"type": "choice", "instructions": "Who should answer?",
+ "criteria": {"a": "travel and planning", "b": "software engineering"}}}
+ });
+ let endpoint = format!("{}/v1/systemone", self.base_url.trim_end_matches('/'));
+ for _ in 0..2 {
+ let started = std::time::Instant::now();
+ let res = self.client.post(&endpoint).json(&payload).timeout(Duration::from_secs(60)).send().await;
+ tracing::info!(ok = res.is_ok(), ms = started.elapsed().as_millis() as u64, "Laya warm-up");
+ }
+ }
+
/// Routes a prompt to the optimal model using Laya (/v1/systemone),
/// falling back gracefully to local heuristics if Laya is unreachable.
pub async fn route_prompt(&self, prompt: &str, context: &str) -> Result<RouteDecision, RouterError> {
diff --git a/src/router/sidecar.rs b/src/router/sidecar.rs
index 94f71b34..397ba7d2 100644
--- a/src/router/sidecar.rs
+++ b/src/router/sidecar.rs
@@ -60,6 +60,7 @@ pub fn spawn(router: LayaRouter, opts: SidecarOptions, shutdown: CancellationTok
async fn supervise(router: LayaRouter, opts: SidecarOptions, shutdown: CancellationToken) {
if router.is_reachable().await {
router.set_status(LayaState::External, "Using the Laya service already running", false);
+ router.warm_up().await;
return monitor_external(router, shutdown).await;
}
@@ -150,6 +151,7 @@ async fn run_until_exit(
online = true;
tick = tokio::time::interval(Duration::from_secs(15));
tracing::info!(url = %router.base_url, "Laya sidecar online");
+ router.warm_up().await;
router.set_status(LayaState::Online, "Model-based routing is active", true);
} else if !up && online {
router.set_status(LayaState::Starting, "Laya stopped answering; waiting for it", true);
@@ -169,6 +171,7 @@ async fn monitor_external(router: LayaRouter, shutdown: CancellationToken) {
let current = router.status();
if up && !current.is_up() {
router.set_status(LayaState::External, "Using the Laya service already running", false);
+ router.warm_up().await;
} else if !up && current.is_up() {
router.set_status(LayaState::Offline, "Laya stopped answering; using keyword routing", false);
}