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:
1 parent
597ac432e1
commit
5bafd000c8
13 files changed
+651
-51
No files matched your search
@@ -119,3 +119,37 @@ async fn abort_reaches_a_running_request_and_frees_the_wires() {
|
||||
assert!(!engine.abort().await.unwrap());
|
||||
engine.shutdown().await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn request_stop_signals_the_owner_without_taking_the_lock() {
|
||||
let exe_mock = mock();
|
||||
let engine = std::sync::Arc::new(
|
||||
Engine::start(
|
||||
&exe_mock.0,
|
||||
&[exe_mock.1[0].clone()],
|
||||
None,
|
||||
Duration::from_secs(10),
|
||||
)
|
||||
.await
|
||||
.unwrap(),
|
||||
);
|
||||
let holder = {
|
||||
let engine = engine.clone();
|
||||
tokio::spawn(async move {
|
||||
engine
|
||||
.generate(1000, &Sampling::default(), &[888888], |_| {})
|
||||
.await
|
||||
})
|
||||
};
|
||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||
// sync, takes no lock and sends no STOP from outside: the owning generate
|
||||
// loop sees the flag and does STOP+drain itself (no race on a later request)
|
||||
engine.request_stop();
|
||||
let held = holder.await.unwrap();
|
||||
assert!(
|
||||
matches!(&held, Err(EngineError::Refused(m)) if m == "aborted"),
|
||||
"the held request should end aborted: {held:?}"
|
||||
);
|
||||
assert!(engine.is_idle());
|
||||
engine.shutdown().await.unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user