Hmbown/CodeWhale · error · anyhow::Error

Thread execution settings changed while preparing the turn;

Error message

Thread execution settings changed while preparing the turn; retry

What it means

Start-turn race detection: the thread's execution settings (mode/posture) changed between preparing the turn and claiming it under the active lock. Rather than running a turn with a stale policy snapshot, the start aborts and the caller is told to retry with the new settings.

Source

Thrown at crates/tui/src/runtime_threads.rs:6120

            .clone()
            .reserve_owned()
            .await
            .map_err(|_| anyhow!("Failed to start turn: engine operation channel closed"))?;

        let acceptance_rx = {
            // Lock order is active -> thread_mutation. Neither guard crosses
            // an await, and spawning the owned lifecycle task is synchronous.
            let mut active = self.active.lock().await;
            let Some(state) = active.engines.get_mut(thread_id) else {
                bail!("Thread engine not loaded");
            };
            if state.active_turn.is_some() {
                bail!("Thread already has an active turn");
            }
            let _thread_mutation = self.store.thread_mutation.lock();
            let mut current_thread = self.store.load_thread(thread_id)?;
            if !thread_execution_state_matches(&thread, &current_thread) {
                bail!("Thread execution settings changed while preparing the turn; retry");
            }
            let previous_active_route = (state.route_identity.clone(), state.route_model.clone());
            state.active_turn = Some(ActiveTurnState {
                turn_id: turn_id.clone(),
                interrupt_requested: false,
                compaction_id: None,
            });
            state.route_identity = provider_identity;
            state.route_model.clone_from(&model);

            let persistence_result = (|| -> Result<()> {
                self.store.save_item(&user_item)?;
                self.store.save_turn(&turn)?;
                current_thread.latest_turn_id = Some(turn_id.clone());
                current_thread.updated_at = now;
                self.store.save_thread(&current_thread)
            })();
            if let Err(persistence_error) = persistence_result {

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Retry the turn start — it will pick up the new settings
  2. Avoid changing execution settings concurrently with turn starts
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/tui/src/runtime_threads.rs:6120 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/6a21e0f170485954. Report an issue: GitHub.