fix(ai): standardize lock handling in _ai_invoke_callback
Some checks failed
CI Code / Check spelling (pull_request) Successful in 20s
CI Code / Check coding style (pull_request) Successful in 34s
CI Code / Code Coverage (pull_request) Failing after 1m6s
CI Code / Linux (debian) (pull_request) Failing after 2m59s
CI Code / Linux (ubuntu) (pull_request) Failing after 3m11s
CI Code / Linux (arch) (pull_request) Failing after 3m19s

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.
This commit is contained in:
2026-05-01 11:35:09 +00:00
parent 461c0c32dd
commit 634fb7d7eb

View File

@@ -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);
}
/* ========================================================================