Respond to code review: sampling defaults, abort race, hardening + README

Bug fixes (from review/README.md):
- Apply config sampling defaults field-by-field, so an absent temperature no
  longer means greedy; expose top_k/min_p/repetition_penalty on ChatRequest;
  top_k=0 is "disabled" (-> 64), not greedy.
- Fix cross-request abort race: Engine::request_stop() sets the cancel flag only;
  the owning generate loop does STOP+drain itself, instead of a spawned abort()
  that could hit a later request holding the lock.
- Initialize tracing-subscriber (RUST_LOG, default info); events were dropped.
- TempFilesGuard removes materialized images on every exit path (error/panic/drop);
  build_prompt runs in spawn_blocking off the async worker; ureq image fetch gets a
  15s timeout, a 32MB cap and a basic SSRF guard (literal loopback/private hosts).
- Non-blocking shutdown (STOP+QUIT without taking the request lock first) and a
  bounded drain_to_done that marks the engine dead on timeout.

Operational hardening:
- Graceful shutdown on SIGTERM as well as SIGINT.
- Warn when binding a non-loopback address (no auth, allowed_hosts not enforced).
- Configurable startup/silence timeouts (optional config keys, default 600s).

Docs:
- Add README.md (English): what strata-ctl is, why Rust for stable server use,
  architecture, usage, honest status, and credits to Strata / Niko1221.

76 tests green + 2 real-file ignored; clippy clean; cargo fmt applied.
Deferred (heavy): automatic engine restart after a crash.
This commit is contained in:
adm committed 2026-11-24 18:42:56 +01:00
1 parent 597ac432e1
commit 5bafd000c8
13 files changed
+651 -51

No files matched your search

+32
View File
@@ -14,6 +14,7 @@
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use std::time::Duration;
use serde::Deserialize;
@@ -79,6 +80,13 @@ pub struct Config {
#[serde(default)]
pub sampling: SamplingDefaults,
/// Startup (wait for `READY`) and silence-watchdog timeouts, in seconds.
/// Optional: both default to 600s when absent.
#[serde(default)]
pub startup_timeout_secs: Option<u64>,
#[serde(default)]
pub silence_timeout_secs: Option<u64>,
/// Keys we understand but don't act on yet are NOT listed above, so they
/// arrive here untouched — the "ignore what isn't ours" guarantee.
#[serde(flatten)]
@@ -165,6 +173,16 @@ impl Config {
cli.or(self.port).unwrap_or(8095)
}
/// Timeout waiting for the engine's `READY` line (default 600s).
pub fn startup_timeout(&self) -> Duration {
Duration::from_secs(self.startup_timeout_secs.unwrap_or(600))
}
/// Silence watchdog: max gap between engine output lines (default 600s).
pub fn silence_timeout(&self) -> Duration {
Duration::from_secs(self.silence_timeout_secs.unwrap_or(600))
}
/// The top-level keys present in the file that we are not acting on —
/// reported by `--check` so the shared-file contract stays visible.
pub fn ignored_keys(&self) -> Vec<&str> {
@@ -281,4 +299,18 @@ mod tests {
let keys = s.keys();
assert_eq!(keys, " temperature=1.0");
}
#[test]
fn timeouts_default_and_override() {
let cfg = Config::parse(REAL, "test").unwrap();
assert_eq!(cfg.startup_timeout(), Duration::from_secs(600));
assert_eq!(cfg.silence_timeout(), Duration::from_secs(600));
let cfg2 = Config::parse(
r#"{"exe":"/x/e","startup_timeout_secs":30,"silence_timeout_secs":120}"#,
"test",
)
.unwrap();
assert_eq!(cfg2.startup_timeout(), Duration::from_secs(30));
assert_eq!(cfg2.silence_timeout(), Duration::from_secs(120));
}
}