From 634fb7d7ebd16d22f6ea108932f00343ff25584c Mon Sep 17 00:00:00 2001 From: Jabber Developer Date: Fri, 1 May 2026 11:35:09 +0000 Subject: [PATCH] fix(ai): standardize lock handling in _ai_invoke_callback Take the global lock mutex before invoking all callbacks (success and error) to ensure thread-safety. Previously some paths took the lock and others did not, creating asymmetric behavior that could lead to data races when callbacks access UI state. --- src/ai/ai_client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ai/ai_client.c b/src/ai/ai_client.c index dce0df3a..41f07e45 100644 --- a/src/ai/ai_client.c +++ b/src/ai/ai_client.c @@ -111,8 +111,10 @@ _ai_invoke_callback(ai_callback_data_t* cb_data) { log_debug("[AI-CALLBACK] _ai_invoke_callback: is_error=%d, response_cb=%p, error_cb=%p", cb_data->is_error, (void*)cb_data->response_cb, (void*)cb_data->error_cb); - /* profanity uses ncurses, not GLib main loop, so call directly */ + /* Take the global lock to ensure thread-safety when invoking callbacks that may access UI state. */ + pthread_mutex_lock(&lock); _ai_callback_invoke(cb_data); + pthread_mutex_unlock(&lock); } /* ========================================================================