branch: externals/ellama
commit 7af3178434d1469bec55c5f2604487371a22808c
Merge: 89cddbec57 bb53970a32
Author: Sergey Kostyaev <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #393 from s-kostyaev/fix-new-session
Improve new session handling in ellama-chat
---
NEWS.org | 33 +++++++++++++++++++--------------
ellama.el | 12 ++++++++----
tests/test-ellama.el | 29 +++++++++++++++++++++++++++++
3 files changed, 56 insertions(+), 18 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index aebe260bd2..3920a5caec 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,24 +1,29 @@
+* Version 1.12.17
+- Improved new session handling in ~ellama-chat~ by refactoring session
+ resolution logic to conditionally create new sessions when the create-session
+ flag is set.
+- Added test to verify that using the create-session flag forces creation of a
+ new session independent of existing sessions.
* Version 1.12.16
- Improve ephemeral context behavior for interactive commands.
~ellama-ask-about~, ~ellama-code-review~, ~ellama-write~, and
~ellama-code-add~ now explicitly add region/buffer context as ephemeral for
one request.
-- Add safer region replacement flow for editing commands.
- ~ellama-stream~ now accepts ~:replace-beg~ and ~:replace-end~ to replace text
- in place, and restore buffer content on request errors. ~ellama-change~,
+- Add safer region replacement flow for editing commands. ~ellama-stream~ now
+ accepts ~:replace-beg~ and ~:replace-end~ to replace text in place, and
+ restore buffer content on request errors. ~ellama-change~,
~ellama-code-edit~, ~ellama-code-improve~, and ~ellama-make-format~ now use
this path.
-- Improve request cancellation handling across related buffers.
- Request state is now tracked as a shared request context, so cancellation
- through ~C-g~ works consistently from both main and reasoning buffers and
- does not affect unrelated active requests.
-- Fix chat session recovery after buffer revert.
- Session resolution now uses stable runtime UIDs and restores session state
- after ~revert-buffer~, improving robustness across renames and legacy session
- files.
-- Add development helper targets to the Makefile.
- New targets: ~make format-elisp~ for formatting project Elisp files and
- ~make test-detailed~ for running tests with detailed ERT failure output.
+- Improve request cancellation handling across related buffers. Request state
+ is now tracked as a shared request context, so cancellation through ~C-g~
+ works consistently from both main and reasoning buffers and does not affect
+ unrelated active requests.
+- Fix chat session recovery after buffer revert. Session resolution now uses
+ stable runtime UIDs and restores session state after ~revert-buffer~,
+ improving robustness across renames and legacy session files.
+- Add development helper targets to the Makefile. New targets: ~make
+ format-elisp~ for formatting project Elisp files and ~make test-detailed~ for
+ running tests with detailed ERT failure output.
* Version 1.12.15
- Fix compilation warnings. This change resolves compilation warnings found
during building.
diff --git a/ellama.el b/ellama.el
index 5024b5a40c..b2b6de6fd6 100644
--- a/ellama.el
+++ b/ellama.el
@@ -6,7 +6,7 @@
;; URL: http://github.com/s-kostyaev/ellama
;; Keywords: help local tools
;; Package-Requires: ((emacs "28.1") (llm "0.24.0") (plz "0.8") (transient
"0.7") (compat "29.1") (yaml "1.2.3"))
-;; Version: 1.12.16
+;; Version: 1.12.17
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Created: 8th Oct 2023
@@ -2233,9 +2233,13 @@ the full response text when the request completes (with
BUFFER current)."
ellama-provider
(ellama-get-first-ollama-chat-model))))
(ephemeral (plist-get args :ephemeral))
- (explicit-session (ellama--resolve-session
- (plist-get args :session)
- (plist-get args :session-id)))
+ (explicit-session-arg (plist-get args :session))
+ (explicit-session-id (plist-get args :session-id))
+ (explicit-session (when (or explicit-session-arg
+ explicit-session-id)
+ (ellama--resolve-session
+ explicit-session-arg
+ explicit-session-id)))
(current-session (or explicit-session
(ellama--resolve-session nil
ellama--current-session-id)))
(need-new-session (and (not explicit-session)
diff --git a/tests/test-ellama.el b/tests/test-ellama.el
index e8dca852b8..af099ef2ef 100644
--- a/tests/test-ellama.el
+++ b/tests/test-ellama.el
@@ -1282,6 +1282,35 @@ region, season, or type)! 🍎🍊"))))
(should (equal global-callback-text "final"))
(should (equal local-callback-text "final")))))
+(ert-deftest test-ellama-chat-create-session-flag-forces-new-session ()
+ (let* ((provider (make-llm-fake :chat-action-func (lambda () "ok")))
+ (ellama-provider provider)
+ (ellama-coding-provider provider)
+ (ellama-major-mode 'text-mode)
+ (ellama-session-auto-save nil)
+ (ellama-chat-translation-enabled nil)
+ (session-1 (ellama-new-session provider "initial prompt" t))
+ (uid-1 (ellama--session-uid session-1))
+ (buffer-1 (ellama-get-session-buffer uid-1))
+ uid-2
+ buffer-2)
+ (unwind-protect
+ (progn
+ (cl-letf (((symbol-function 'ellama-stream)
+ (lambda (&rest _args) :stubbed)))
+ (ellama-chat "next prompt" t))
+ (setq uid-2 ellama--current-session-uid
+ buffer-2 (ellama-get-session-buffer uid-2))
+ (should uid-2)
+ (should (not (equal uid-1 uid-2)))
+ (should (buffer-live-p buffer-2)))
+ (when (buffer-live-p buffer-1)
+ (kill-buffer buffer-1))
+ (when (and buffer-2
+ (buffer-live-p buffer-2)
+ (not (eq buffer-2 buffer-1)))
+ (kill-buffer buffer-2)))))
+
(ert-deftest test-ellama-remove-reasoning ()
(should (equal