From 3291ae86e5ea958c821cb65c84e850813c14d2d0 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 23 Aug 2026 04:29:33 +0200 Subject: [PATCH] Prioritize Session Zero over background inference --- crates/ghostlight-dungeon/src/main.rs | 56 ++++++++++++------- .../ghostlight-dungeon-session-zero.md | 8 +++ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/crates/ghostlight-dungeon/src/main.rs b/crates/ghostlight-dungeon/src/main.rs index d490a11..6dc543a 100644 --- a/crates/ghostlight-dungeon/src/main.rs +++ b/crates/ghostlight-dungeon/src/main.rs @@ -1910,11 +1910,14 @@ async fn begin_session_zero( if let Some(compiler) = state.compiler.clone() { let mesh_state = state.clone(); tokio::spawn(async move { - if let Err(error) = populate_opening_suggestions( - compiler, - runtime, - snapshot, - mesh_state.clone(), + if let Err(error) = run_live_model_work( + &mesh_state, + populate_opening_suggestions( + compiler, + runtime, + snapshot, + mesh_state.clone(), + ), ) .await { @@ -2339,14 +2342,16 @@ fn schedule_session_zero_dm_response( let kernel = runtime.kernel.clone(); let mesh_state = state.clone(); tokio::spawn(async move { - match director - .respond( + match run_live_model_work( + &mesh_state, + director.respond( &snapshot, &channel_id, member_id.as_deref(), supersedes_countered_decision_id.as_deref(), - ) - .await + ), + ) + .await { Ok((delta, receipts)) => { let applied = kernel @@ -2678,12 +2683,15 @@ async fn resolve_session_zero_decision( let role_state = state.clone(); let role_snapshot = result.state.clone(); tokio::spawn(async move { - if let Err(error) = populate_role_suggestions( - compiler, - role_runtime, - role_snapshot, - opening, - role_state.clone(), + if let Err(error) = run_live_model_work( + &role_state, + populate_role_suggestions( + compiler, + role_runtime, + role_snapshot, + opening, + role_state.clone(), + ), ) .await { @@ -2865,7 +2873,7 @@ async fn compile_session_zero( let kernel = runtime.kernel.clone(); let mesh_state = state.clone(); tokio::spawn(async move { - match compiler.compile_approved_brief(&brief).await { + match run_live_model_work(&mesh_state, compiler.compile_approved_brief(&brief)).await { Ok((preview, receipts)) => { if let Err(error) = kernel .command(SessionZeroCommand::InstallPreview { @@ -5295,6 +5303,11 @@ async fn await_background_work( } } +async fn run_live_model_work(state: &AppState, work: impl std::future::Future) -> T { + let _live = LiveTurnGuard::enter(state).await; + work.await +} + async fn app_session_refresh_loop(state: AppState) { let mut pulse = tokio::time::interval(std::time::Duration::from_secs(60)); pulse.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip); @@ -5927,17 +5940,18 @@ mod tests { } #[tokio::test] - async fn live_turn_cancels_background_inference_and_excludes_its_commit_gate() { + async fn interactive_model_work_cancels_background_inference_and_excludes_its_commit_gate() { let dir = tempfile::tempdir().unwrap(); let state = empty_app_state(dir.path()); let trigger_state = state.clone(); let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); let (release_tx, release_rx) = tokio::sync::oneshot::channel(); let trigger = tokio::spawn(async move { - let guard = LiveTurnGuard::enter(&trigger_state).await; - let _ = entered_tx.send(()); - let _ = release_rx.await; - drop(guard); + run_live_model_work(&trigger_state, async move { + let _ = entered_tx.send(()); + let _ = release_rx.await; + }) + .await; }); let result = tokio::time::timeout( diff --git a/docs/architecture/ghostlight-dungeon-session-zero.md b/docs/architecture/ghostlight-dungeon-session-zero.md index 4a7cf55..40c5ee0 100644 --- a/docs/architecture/ghostlight-dungeon-session-zero.md +++ b/docs/architecture/ghostlight-dungeon-session-zero.md @@ -88,6 +88,14 @@ fail, the kernel may append a fixed local DM notice to the conversation while leaving contract, characters, decisions, boundaries, approvals, and model receipts unchanged. +Every player-triggered Session Zero model task enters the same live-inference +priority gate as campaign play. This includes opening and role suggestions, DM +turns, counter replacements, and world compilation. Entering the gate cancels +an in-flight strategic model wave before it can commit and prevents new +background inference from launching until the interactive task leaves. A quiet +campaign cannot consume provider concurrency while a player is waiting at the +table. + One Interpreter turn has one owner per typed lane. A shared turn may directly edit the draft contract or offer a contract decision, never both; a private turn may directly edit the ordinary character draft or offer a character-patch