fix(app): settle the start state before answering and report failed stops
service_start now moves the controller to starting before it returns (Controller::start_in_background), so a stop right after it cancels the start and a second start is refused instead of the start running late. service_restart stops, then starts the same way. Stopping Strata now confirms the server is gone: `launch --stop` is ended after 2 minutes with everything it started, then the port must stop listing a model. A server still answering makes the LLM failed with the reason, and Services::stop / Running::stop return it, so the controller shows failed instead of stopped (also for a cancelled start that could not clear the server). A stop command that fails while nothing answers counts as stopped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,11 +25,12 @@ pub struct Services {
|
||||
}
|
||||
|
||||
impl Services {
|
||||
pub async fn stop(&self) {
|
||||
/// Stop everything; an error means the LLM's server may still run.
|
||||
pub async fn stop(&self) -> Result<(), String> {
|
||||
self.core.close().await;
|
||||
self.worker.close();
|
||||
self.worker_process.stop().await;
|
||||
self.llm.stop().await;
|
||||
self.llm.stop().await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +49,7 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
|
||||
let (base_url, model) = llm.start(&settings).await?;
|
||||
let brain_config = match crate::strata::write_brain_config(data_dir, &base_url, &model) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
llm.stop().await;
|
||||
return Err(format!("could not write the brain settings: {e}").into());
|
||||
}
|
||||
Err(e) => return Err(after_llm_stop(&llm, format!("could not write the brain settings: {e}")).await.into()),
|
||||
};
|
||||
|
||||
let w = &settings.voice_worker;
|
||||
@@ -64,10 +62,7 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
|
||||
wopts.env.insert("JARVIS_CONFIG_PATH".into(), brain_config.to_string_lossy().into_owned());
|
||||
let worker_process = match WorkerProcess::new(wopts) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
llm.stop().await;
|
||||
return Err(e.into());
|
||||
}
|
||||
Err(e) => return Err(after_llm_stop(&llm, e.to_string()).await.into()),
|
||||
};
|
||||
let mut process_events = worker_process.subscribe();
|
||||
worker_process.start();
|
||||
@@ -101,9 +96,16 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
|
||||
if let Err(e) = core.start().await {
|
||||
worker.close();
|
||||
worker_process.stop().await;
|
||||
llm.stop().await;
|
||||
return Err(Box::new(e));
|
||||
return Err(after_llm_stop(&llm, e.to_string()).await.into());
|
||||
}
|
||||
crate::info_log!("app", "services started");
|
||||
Ok(Services { core, events, worker, worker_process, missed, llm })
|
||||
}
|
||||
|
||||
/// Stop the LLM after a failed start; the error also says if its server may still run.
|
||||
async fn after_llm_stop(llm: &Llm, error: String) -> String {
|
||||
match llm.stop().await {
|
||||
Ok(()) => error,
|
||||
Err(stop) => format!("{error} ({stop})"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user