Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions gptel-transient-memory-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;;; gptel-transient-memory-test.el --- Test for memory-report compatibility -*- lexical-binding: t; -*-

;; This test verifies that the fix for GitHub issue #1032 works correctly.
;; The issue was that memory-report would fail when trying to compute the
;; size of gptel's transient history data containing backend structs.

;;; Code:

(require 'gptel-transient)
(require 'gptel-gemini)

;; Create a test backend
(defvar test-backend (gptel-make-gemini "Test-Gemini"
:key "test-key"
:stream t))

;; Create a provider object as used in gptel-menu
(defvar test-provider-obj (make-instance 'gptel-provider-variable
:backend 'gptel-backend
:variable 'gptel-model))

;; The fix: history-key and history-default should be nil to prevent
;; storing the backend struct in transient-history
(message "Testing memory-report compatibility fix...")
(message "history-key is nil: %s" (null (oref test-provider-obj history-key)))
(message "history-default is nil: %s" (null (oref test-provider-obj history-default)))

;; This prevents the backend struct (with its bytecode) from being
;; stored in transient-history, which was causing memory-report errors
(if (and (null (oref test-provider-obj history-key))
(null (oref test-provider-obj history-default)))
(message "✓ Fix verified: Backend structs will not be stored in transient history")
(error "✗ Fix failed: Backend structs may still cause memory-report errors"))

(provide 'gptel-transient-memory-test)
;;; gptel-transient-memory-test.el ends here
5 changes: 4 additions & 1 deletion gptel-transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,10 @@ This is used only for setting this variable via `gptel-menu'.")
((backend :initarg :backend)
(backend-value :initarg :backend-value)
(always-read :initform t)
(set-value :initarg :set-value :initform #'set))
(set-value :initarg :set-value :initform #'set)
;; Prevent storing the backend struct in transient history to avoid memory-report errors
(history-default :initform nil)
(history-key :initform nil))
"Class used for gptel-backends.")

(cl-defmethod transient-format-value ((obj gptel-provider-variable))
Expand Down