From 4a577b38606b571bae5e8f99a267f675b245e279 Mon Sep 17 00:00:00 2001 From: La-Loutre Date: Fri, 8 Aug 2025 19:20:28 +0200 Subject: [PATCH] Fix(curl): Prevent hang on successful empty response A non-streaming request would hang if the server returned a successful HTTP status (200 OK) but with an empty or malformed JSON body. The sentinel function failed to call the final callback because its conditional logic required a non-nil response body on a successful request. This change makes the callback trigger dependent only on a completed HTTP status, ensuring the client is always notified and preventing the silent hang. --- gptel-curl.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gptel-curl.el b/gptel-curl.el index 45d17880..c2076cbf 100644 --- a/gptel-curl.el +++ b/gptel-curl.el @@ -423,7 +423,11 @@ PROCESS and _STATUS are process parameters." (when-let* ((reasoning (plist-get proc-info :reasoning)) ((stringp reasoning))) (funcall proc-callback (cons 'reasoning reasoning) proc-info)))) - (when (or response (not (member http-status '("200" "100")))) + ;; The original condition failed to call the callback when a request + ;; succeeded (HTTP 200) but had an empty/malformed response body. + ;; This new condition ensures the callback always fires for any completed + ;; process, preventing a silent hang. + (when http-status (with-demoted-errors "gptel callback error: %S" (funcall proc-callback response proc-info)))) (gptel--fsm-transition fsm)) ;TYPE -> next