feat(voice): in a game, partial transcription waits while an answer is written

- the app's ready message says whether the game stage runs (llm ready game=true); the worker then
  holds partial passes while a reply is being written and runs them again, the newest audio per
  speaker, when no answer is; finals never wait; without a game nothing changes
- M0 gamemode_tune decision: the game placement answered 1.7 times faster with partials held
  (64.9 against 37.5 tok/s with a partial pass every 2 s)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-14 10:58:11 +09:00
parent 5316f4e9b0
commit 3d58cf8ab1
8 changed files with 138 additions and 20 deletions

View File

@@ -214,7 +214,8 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
pub trait LlmBrain: Send + Sync {
/// Announce a switch; its number for `wait_llm_idle`.
fn llm_switching(&self, notice: Option<&str>) -> u64;
fn llm_state(&self, state: &str) -> bool;
/// `ready` (with whether a game runs) or `paused`.
fn llm_state(&self, state: &str, game: bool) -> bool;
async fn wait_llm_idle(&self, id: u64, t: std::time::Duration) -> bool;
/// The STT worker's model is loaded (on the graphics card).
fn stt_on_card(&self) -> bool;
@@ -225,8 +226,8 @@ impl LlmBrain for WorkerClient {
fn llm_switching(&self, notice: Option<&str>) -> u64 {
WorkerClient::llm_switching(self, notice)
}
fn llm_state(&self, state: &str) -> bool {
WorkerClient::llm_state(self, state)
fn llm_state(&self, state: &str, game: bool) -> bool {
if state == "ready" { WorkerClient::llm_ready(self, game) } else { WorkerClient::llm_state(self, state) }
}
async fn wait_llm_idle(&self, id: u64, t: std::time::Duration) -> bool {
WorkerClient::wait_llm_idle(self, id, t).await
@@ -305,7 +306,8 @@ async fn perf_loop(settings: crate::settings::Settings, llm: Arc<Llm>, brain: Ar
back
}
};
brain.llm_state(if ended == Stage::Paused { "paused" } else { "ready" });
// In the game stage partial passes wait while an answer is written (M0 gamemode_tune).
brain.llm_state(if ended == Stage::Paused { "paused" } else { "ready" }, ended == Stage::Gaming);
}
}
@@ -350,8 +352,8 @@ mod perf_tests {
self.0.lock().unwrap().push(format!("switching{}", notice.map(|n| format!(": {n}")).unwrap_or_default()));
1
}
fn llm_state(&self, state: &str) -> bool {
self.0.lock().unwrap().push(state.into());
fn llm_state(&self, state: &str, game: bool) -> bool {
self.0.lock().unwrap().push(if game { format!("{state} (game)") } else { state.into() });
true
}
async fn wait_llm_idle(&self, _id: u64, _t: Duration) -> bool {
@@ -389,8 +391,8 @@ mod perf_tests {
panic!("never {want}: {:?}", brain.0.lock().unwrap());
}
};
until("ready").await;
assert_eq!(*brain.0.lock().unwrap(), ["switching: 잠깐만요, 게임 모드로 바꾸는 중이에요", "waited", "ready"]);
until("ready (game)").await;
assert_eq!(*brain.0.lock().unwrap(), ["switching: 잠깐만요, 게임 모드로 바꾸는 중이에요", "waited", "ready (game)"]);
assert!(launches(&l).last().unwrap().contains("--context 16384"), "{:?}", launches(&l));
assert_eq!(llm.stage_view()["stage"], serde_json::json!("gaming"));
// The game ends (no wait set): back to the normal stage.
@@ -506,7 +508,7 @@ mod perf_tests {
self.0.lock().unwrap().push(("switching".into(), std::time::Instant::now()));
1
}
fn llm_state(&self, state: &str) -> bool {
fn llm_state(&self, state: &str, _game: bool) -> bool {
self.0.lock().unwrap().push((state.into(), std::time::Instant::now()));
true
}

View File

@@ -379,7 +379,16 @@ impl WorkerClient {
/// Tell the brain the LLM is `ready` (answer what waited) or `paused` (answer nothing).
pub fn llm_state(&self, state: &str) -> bool {
let m = json!({"type": "llm", "state": state});
self.set_llm(json!({"type": "llm", "state": state}))
}
/// Tell the brain the LLM is ready, and whether a game runs (then partial passes wait while an
/// answer is written).
pub fn llm_ready(&self, game: bool) -> bool {
self.set_llm(json!({"type": "llm", "state": "ready", "game": game}))
}
fn set_llm(&self, m: Value) -> bool {
let mut llm = self.inner.llm.lock().unwrap();
*llm = Some(m.clone());
self.send_json(m)