From 2e3d24a8c7c7d6771ba0bab3921497318ca3490a Mon Sep 17 00:00:00 2001 From: Marcel Menzel Date: Thu, 16 Jul 2026 10:55:55 +0000 Subject: [PATCH] Fix synchronous context_augment firing two GPT requests for one model MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When your context_augment function calls the callback synchronously (e.g., return function(task, content, cb) cb('some context') end), the pending_fetches counter drops to 0 inside the callback, triggering maybe_proceed() which calls proceed(). Then control returns to the main flow where the now-redundant guard also sees pending_fetches == 0 and calls proceed(nil) a second time — this time without the context snippet. The else branch (line 1324) already handles the case where none of the context features are enabled, so the removed fallback was purely a duplicate path for synchronous callbacks. --- src/plugins/lua/gpt.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/plugins/lua/gpt.lua b/src/plugins/lua/gpt.lua index 0bc6488ad0..1b4b21d06b 100644 --- a/src/plugins/lua/gpt.lua +++ b/src/plugins/lua/gpt.lua @@ -1316,11 +1316,6 @@ local function gpt_check(task) maybe_proceed() end end - - -- If no fetches were initiated, proceed immediately - if pending_fetches == 0 then - proceed(nil) - end else proceed(nil) end -- 2.47.3