{"record":{"id":"4e1e6ad2c73d0deb","repo":"Hmbown/CodeWhale","slug":"workspace-cannot-be-changed-while-the-thread-has-a","errorCode":null,"errorMessage":"workspace cannot be changed while the thread has an active turn","messagePattern":"workspace cannot be changed while the thread has an active turn","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":8043,"sourceCode":"                    changes.insert(\"system_prompt\".to_string(), json!(new_sys));\n                }\n            }\n            if let Some(workspace) = req.workspace\n                && thread.workspace != workspace\n            {\n                changes.insert(\"workspace\".to_string(), json!(workspace));\n                thread.workspace = workspace;\n            }\n\n            let workspace_changed = changes.contains_key(\"workspace\");\n            if workspace_changed\n                && active\n                    .engines\n                    .get(id)\n                    .and_then(|state| state.active_turn.as_ref())\n                    .is_some()\n            {\n                bail!(\"workspace cannot be changed while the thread has an active turn\");\n            }\n\n            // A posture/mode edit must reach the live engine even while a\n            // turn is running. EngineHandle publishes the authority snapshot\n            // before queueing ChangeMode; the turn loop applies that pending\n            // update before the next tool batch.\n            let posture_changed = changes.contains_key(\"auto_approve\")\n                || changes.contains_key(\"permission_posture\")\n                || changes.contains_key(\"trust_mode\")\n                || changes.contains_key(\"allow_shell\")\n                || changes.contains_key(\"mode\");\n\n            let evicted_engine = if changes.is_empty() {\n                None\n            } else {\n                thread.updated_at = Utc::now();\n                self.store.save_thread(&thread)?;\n                if workspace_changed {","sourceCodeStart":8025,"sourceCodeEnd":8061,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L8025-L8061","documentation":"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.)","triggerScenarios":"Calling update-thread with `workspace: Some(new_path)` on a thread whose engine state shows `active_turn: Some(_)`.","commonSituations":"User drags the thread to a different project folder while a long turn runs; automation switches workspaces on a schedule without checking turn state.","solutions":["Wait for the active turn to complete, then change the workspace.","Abort/cancel the current turn first, then issue the workspace update.","Create a new thread in the desired workspace instead of moving the busy one.","Gate the update behind turn-idle polling or a completion event."],"exampleFix":"// before\napi.update_thread(id, req).await?; // workspace change during turn -> error\n\n// after\nif let Some(done) = api.turn_completion(id).await {\n    done.await; // wait for idle\n}\napi.update_thread(id, req).await?;","handlingStrategy":"validation","validationCode":"let busy = api.thread_state(id).await?.active_turn.is_some();\nif busy && req.workspace.is_some() { /* defer the workspace change */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check active_turn before any workspace mutation","Split updates: apply non-workspace fields anytime, workspace only when idle","Surface a busy indicator and disable the workspace picker during turns"],"tags":["concurrency","workspace","turn-loop"],"backgroundTag":"invalid-state-transition","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}