Skip to content

Commit 5cc115b

Browse files
ericdalloeca-agent
andcommitted
Fix inline completion auth renewal crash
Use a zero-arity renewing callback for inline completion so expired auth renewal does not call clojure.core/identity without arguments. Closes #437 🤖 Generated with [eca](https://eca.dev) Co-Authored-By: eca-agent <git@eca.dev>
1 parent aa162b0 commit 5cc115b

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Bugfix: avoid `Divide by zero` crash in chat auto-compact when models.dev reports `0` for a model's context/output limits (e.g. `openai/chatgpt-image-latest`); such limits are now normalized to `nil` and `auto-compact?` skips models without a known positive context window.
6+
- Fix inline completion crash when renewing auth tokens before completion requests. #437
67

78
## 0.130.1
89

src/eca/features/completion.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
[provider model] (shared/full-model->provider+model full-model)
3535
_ (f.login/maybe-renew-auth-token!
3636
{:provider provider
37-
:on-renewing identity
37+
:on-renewing (fn [] nil)
3838
:on-error (fn [error-msg] (logger/error logger-tag (format "Auth token renew failed: %s" error-msg)))}
3939
{:db* db*
4040
:messenger messenger
Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,49 @@
1-
(ns eca.features.completion-test)
1+
(ns eca.features.completion-test
2+
(:require
3+
[clojure.test :refer [deftest is testing]]
4+
[eca.db :as db]
5+
[eca.features.completion :as f.completion]
6+
[eca.features.login :as f.login]
7+
[eca.llm-api :as llm-api]
8+
[eca.test-helper :as h]))
9+
10+
(h/reset-components-before-test)
11+
12+
(deftest complete-renews-expired-auth-test
13+
(testing "Renews expired auth before requesting inline completion"
14+
(h/reset-components!)
15+
(h/config! {:env "test"
16+
:completion {:model "github-copilot/gpt-4o"
17+
:systemPrompt "Complete the code."}})
18+
(swap! (h/db*) assoc
19+
:models {"github-copilot/gpt-4o" {:reason? true
20+
:tools true
21+
:web-search true}})
22+
(swap! (h/db*) assoc-in [:auth "github-copilot"] {:api-key "expired"
23+
:expires-at 1})
24+
(let [login-ctx* (atom nil)
25+
api-opts* (atom nil)
26+
result (with-redefs [db/update-global-cache! (fn [& _] nil)
27+
f.login/login-step
28+
(fn [{:keys [db*] :as ctx}]
29+
(reset! login-ctx* ctx)
30+
(swap! db* assoc-in [:auth "github-copilot"] {:api-key "renewed"
31+
:expires-at 9999999999}))
32+
llm-api/sync-prompt!
33+
(fn [opts]
34+
(reset! api-opts* opts)
35+
{:output-text "completion"})]
36+
(f.completion/complete {:doc-text "abc"
37+
:doc-version 3
38+
:position {:line 1 :character 4}}
39+
(h/db*) (h/config) (h/messenger) (h/metrics)))]
40+
(is (= "github-copilot" (:provider @login-ctx*)))
41+
(is (= :login/renew-token (:step @login-ctx*)))
42+
(is (= "github-copilot" (:provider @api-opts*)))
43+
(is (= "gpt-4o" (:model @api-opts*)))
44+
(is (= {:api-key "renewed" :expires-at 9999999999} (:provider-auth @api-opts*)))
45+
(is (= {:items [{:text "completion"
46+
:doc-version 3
47+
:range {:start {:line 1 :character 4}
48+
:end {:line 1 :character 4}}}]}
49+
result)))))

0 commit comments

Comments
 (0)