@@ -215,8 +215,7 @@ class ChatViewModel(
215215 fun send(text: String): Boolean {
216216 val conn = connection ?: return false
217217 val trimmed = text.trim()
218− if (trimmed.isEmpty() || _running.value) return false
219− _running.value = true
218+ if (trimmed.isEmpty() || !_running.compareAndSet(false, true)) return false
220219 _error.value = null
221220 _failedDraft.value = null
222221 // Clear the in-memory draft for the UI immediately, but don't persist the clear
@@ -255,8 +254,7 @@ class ChatViewModel(
255254 /** Invoke a slash-command by name via the server's /command endpoint. */
256255 fun runCommand(command: Command) {
257256 val conn = connection ?: return
258− if (_running.value) return
259− _running.value = true
257+ if (!_running.compareAndSet(false, true)) return
260258 _error.value = null
261259 viewModelScope.launch {
262260 runCatching {