Files
leleka/control-plane/src/preflight.rs
T
Pavlo Ratushnyi 4013e0c9bd
Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
Import tracked Strata Next source snapshot
2026-10-05 18:15:08 +02:00

100 lines
4.3 KiB
Rust

//! Read-only deployment validation; never spawn a worker or acquire a listener.
use std::{env, ffi::OsStr, path::Path};
use crate::{config::Config, embedded_engine, tokenizer::Tokenizer};
pub fn check(path: Option<&Path>) -> Result<serde_json::Value, &'static str> {
// Parser errors may contain user-supplied values. Keep diagnostics to stages
// so a malformed config/tokenizer cannot echo credentials into deployment logs.
let config = Config::load_with_path(path)
.map_err(|_| "configuration or API key validation failed; check config fields, environment overrides and key-file permissions")?;
let engine = match &config.worker {
None => "unconfigured",
Some(worker) if worker.executable == OsStr::new("@embedded") => {
if !cfg!(target_os = "linux") {
return Err("embedded execution requires Linux");
}
if embedded_engine::info()["embedded"] != true {
return Err("this executable has no embedded engine");
}
"embedded"
}
Some(worker) => {
if !executable_available(&worker.executable) {
return Err(
"engine executable is not an accessible executable file; check its path or PATH",
);
}
"external"
}
};
let tokenizer_pending =
config.native_model.is_some() && config.tokenizer_dir.as_ref().is_some_and(|p| !p.exists());
if let Some(path) = &config.tokenizer_dir
&& !tokenizer_pending
{
Tokenizer::from_assets(path).map_err(|_| "tokenizer asset validation failed")?;
}
Ok(serde_json::json!({
"schema_version": 1,
"configuration_valid": true,
"platform": std::env::consts::OS,
"bind": config.bind.to_string(),
"max_in_flight_requests": config.max_in_flight_requests,
"queue_timeout_s": config.queue_timeout.map(|duration| duration.as_secs()),
"shutdown_grace_s": config.shutdown_grace.as_secs(),
"generation_timeout_s": config.worker.as_ref().and_then(|worker| worker.generation_timeout.map(|duration| duration.as_secs())),
"model": config.model,
"authentication_enabled": config.api_key.is_some(),
"response_history": if config.response_history_dir.is_some() { "durable_unchecked" } else { "memory" },
"engine": engine,
"tokenizer_validated": config.tokenizer_dir.is_some() && !tokenizer_pending,
"native_model_configured":config.native_model.is_some(),
"native_runtime_profile":config.native_model.as_ref().and_then(|native| native.runtime_profile),
"native_runtime_profile_checked":false,
"mtp_pack": if config.mtp_pack.is_some() { "pinned_structural_check_pending" } else { "unconfigured" },
"native_model_verified":false,
"inference_configured": config.worker.is_some() && config.tokenizer_dir.is_some() && !tokenizer_pending,
"readiness_checked": false,
"asset_bundles_configured": config.assets.len(),
"assets_verified": false,
"gpu_requirement": config.gpu_requirement,
"gpu_requirement_checked": false,
"cuda_memory": config.cuda_memory,
"cuda_memory_checked": false,
"engine_probe_configured": config.engine_probe,
"engine_probe_checked": false,
}))
}
fn executable_available(executable: &OsStr) -> bool {
let path = Path::new(executable);
if executable.as_encoded_bytes().contains(&b'/') {
return executable_file(path);
}
// A missing PATH is deliberately not guessed. An explicit path is portable.
env::var_os("PATH").is_some_and(|paths| {
env::split_paths(&paths).any(|directory| executable_file(&directory.join(path)))
})
}
fn executable_file(path: &Path) -> bool {
if !path.is_file() {
return false;
}
#[cfg(unix)]
{
use std::{ffi::CString, os::unix::ffi::OsStrExt};
let Ok(path) = CString::new(path.as_os_str().as_bytes()) else {
return false;
};
// SAFETY: valid NUL-terminated path, no retained pointers. This is a
// point-in-time access check, not an execution or dependency probe.
unsafe { libc::access(path.as_ptr(), libc::X_OK) == 0 }
}
#[cfg(not(unix))]
{
false
}
}