feat(app): chat channel name/topic sync, TTS speed, safe window close
Review follow-ups to M5. - Chat channel names and topics (app/src/channel_sync.rs): a channel with syncDiscord (default on) gets its name and description as its Discord name and topic when saved; registering fills them from Discord; Discord's form of the name is written back; a topic over 1,024 characters is refused before saving; a rate-limited edit is pending and retried once by itself with the latest text; a missing permission fails with the reason and the app keeps the text. Commands discord_channel_info and channel_sync_status. Checked on real Discord with a temporary channel (fill, edit, rate limit, automatic retry). - voice.tts.speed (0.5-2.0) on the model screen, passed to the worker as --melo-speed. MeloTTS's Korean model has one voice, so no voice choice. - Closing the window runs AdminApi::shutdown first: an install in progress is cancelled and waited for, the services stop, a failed run's leftovers (Strata) are cleared (Controller::shutdown). If that fails the window stays open with the reason; closing again quits. - WebView2 data goes in the data folder (cache/webview), or a temp scratch folder before one is chosen, removed at the next start: %APPDATA%\JarvisBot holds only the location file. - Command output that is not UTF-8 (CP949 on a PC without the UTF-8 option) is decoded in the OEM code page instead of ending the reading. Verified on the win-ci VM: closing during the install leaves no process, no --location keeps only location.json under %APPDATA%, the unit tests on Windows 168/168. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,10 @@ pub trait Host: Send + Sync + 'static {
|
||||
fn llm(&self) -> Value {
|
||||
Value::Null
|
||||
}
|
||||
/// After a failed run (a start or a stop that could not clear everything): stop what may be left.
|
||||
async fn cleanup(&self) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct Inner {
|
||||
@@ -211,6 +215,40 @@ impl Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/// The app is closing: stop what runs (a start in progress is cancelled and waited for, up to
|
||||
/// 150 s), then, if the state is failed, clear what may be left. Ok means nothing is left running.
|
||||
pub async fn shutdown(&self) -> Result<(), String> {
|
||||
if matches!(self.state(), State::Running | State::Starting) {
|
||||
let _ = self.stop().await;
|
||||
}
|
||||
let until = Instant::now() + Duration::from_secs(150);
|
||||
while matches!(self.state(), State::Starting | State::Stopping) {
|
||||
if Instant::now() >= until {
|
||||
return Err("서비스가 아직 멈추지 않았습니다".into());
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
if self.state() != State::Failed {
|
||||
return Ok(());
|
||||
}
|
||||
match self.host.cleanup().await {
|
||||
Ok(()) => {
|
||||
let mut i = self.inner.lock().unwrap();
|
||||
i.state = State::Stopped;
|
||||
i.error = None;
|
||||
drop(i);
|
||||
crate::info_log!("app", "cleared what the failed run left");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
let e = crate::logs::redact(&e, &self.host.secrets());
|
||||
crate::error_log!("app", "could not clear what the failed run left: {e}");
|
||||
self.inner.lock().unwrap().error = Some(e.clone());
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn restart(&self) -> Result<(), String> {
|
||||
if self.state() == State::Running {
|
||||
self.stop().await?;
|
||||
@@ -297,6 +335,14 @@ impl Host for ServicesHost {
|
||||
fn llm(&self) -> Value {
|
||||
json!(self.llm.status())
|
||||
}
|
||||
|
||||
async fn cleanup(&self) -> Result<(), String> {
|
||||
if self.llm.status().state == crate::strata::LlmState::Failed {
|
||||
self.llm.stop().await
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -328,6 +374,8 @@ mod tests {
|
||||
starts: AtomicU32,
|
||||
stops: AtomicU32,
|
||||
stop_fails: std::sync::atomic::AtomicBool,
|
||||
cleanups: AtomicU32,
|
||||
cleanup_fails: std::sync::atomic::AtomicBool,
|
||||
}
|
||||
|
||||
struct FakeRunning(Arc<Counts>);
|
||||
@@ -378,6 +426,10 @@ mod tests {
|
||||
fn secrets(&self) -> Vec<String> {
|
||||
self.0.secrets()
|
||||
}
|
||||
async fn cleanup(&self) -> Result<(), String> {
|
||||
self.0.counts.cleanups.fetch_add(1, Ordering::SeqCst);
|
||||
if self.0.counts.cleanup_fails.load(Ordering::SeqCst) { Err("Strata를 끄지 못했습니다".into()) } else { Ok(()) }
|
||||
}
|
||||
}
|
||||
(Controller::new(Shared(host.clone())), counts, host)
|
||||
}
|
||||
@@ -464,6 +516,23 @@ mod tests {
|
||||
assert_eq!(c.state(), State::Running);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn closing_the_app_after_a_failed_stop_clears_what_is_left_or_says_it_could_not() {
|
||||
let (c, counts, _) = controller(0);
|
||||
c.shutdown().await.unwrap(); // nothing ran: nothing to do
|
||||
assert_eq!(counts.cleanups.load(Ordering::SeqCst), 0);
|
||||
c.start().await.unwrap();
|
||||
counts.stop_fails.store(true, Ordering::SeqCst);
|
||||
counts.cleanup_fails.store(true, Ordering::SeqCst);
|
||||
assert!(c.shutdown().await.is_err(), "the stop and the clean-up both failed");
|
||||
assert_eq!(c.state(), State::Failed);
|
||||
counts.cleanup_fails.store(false, Ordering::SeqCst);
|
||||
c.shutdown().await.unwrap();
|
||||
let s = c.snapshot().await;
|
||||
assert_eq!((s["state"].clone(), s["error"].clone()), (json!("stopped"), Value::Null));
|
||||
assert_eq!(counts.cleanups.load(Ordering::SeqCst), 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn start_and_stop_follow_the_state_rules() {
|
||||
let (c, counts, _) = controller(0);
|
||||
|
||||
Reference in New Issue
Block a user