Hmbown/CodeWhale · error

workspace cannot be changed while the thread has an active…

Error message

workspace cannot be changed while the thread has an active turn

What it means

Changing a thread's `workspace` is forbidden while the thread has an active turn. The running turn holds open file context and a workspace snapshot; mutating the workspace mid-turn would invalidate its tool sandbox. (Note: mode/posture edits are allowed mid-turn via the pending-update snapshot — only workspace is blocked.)

Solutions

  1. Wait for the active turn to complete, then change the workspace.
  2. Abort/cancel the current turn first, then issue the workspace update.
  3. Create a new thread in the desired workspace instead of moving the busy one.
  4. Gate the update behind turn-idle polling or a completion event.

Example fix

// before
api.update_thread(id, req).await?; // workspace change during turn -> error

// after
if let Some(done) = api.turn_completion(id).await {
    done.await; // wait for idle
}
api.update_thread(id, req).await?;
Defensive patterns

Strategy: validation

Validate before calling

let busy = api.thread_state(id).await?.active_turn.is_some();
if busy && req.workspace.is_some() { /* defer the workspace change */ }

Prevention

When it happens

Trigger: Calling update-thread with `workspace: Some(new_path)` on a thread whose engine state shows `active_turn: Some(_)`.

Common situations: User drags the thread to a different project folder while a long turn runs; automation switches workspaces on a schedule without checking turn state.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/4e1e6ad2c73d0deb. Report an issue: GitHub.

Appendix: source

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

                    changes.insert("system_prompt".to_string(), json!(new_sys));
                }
            }
            if let Some(workspace) = req.workspace
                && thread.workspace != workspace
            {
                changes.insert("workspace".to_string(), json!(workspace));
                thread.workspace = workspace;
            }

            let workspace_changed = changes.contains_key("workspace");
            if workspace_changed
                && active
                    .engines
                    .get(id)
                    .and_then(|state| state.active_turn.as_ref())
                    .is_some()
            {
                bail!("workspace cannot be changed while the thread has an active turn");
            }

            // A posture/mode edit must reach the live engine even while a
            // turn is running. EngineHandle publishes the authority snapshot
            // before queueing ChangeMode; the turn loop applies that pending
            // update before the next tool batch.
            let posture_changed = changes.contains_key("auto_approve")
                || changes.contains_key("permission_posture")
                || changes.contains_key("trust_mode")
                || changes.contains_key("allow_shell")
                || changes.contains_key("mode");

            let evicted_engine = if changes.is_empty() {
                None
            } else {
                thread.updated_at = Utc::now();
                self.store.save_thread(&thread)?;
                if workspace_changed {

View on GitHub (pinned to 73e0f67d83)