When using :session in an ob-gptel source block and the point (cursor) is positioned after the character c of #+end_src line , the current block's body is incorrectly included in the session history. This causes the same user message to appear twice in the final messages array sent to the API.
Steps to reproduce:
- Create one Org source blocks with a
:session name:
#+begin_src gptel :session test :dry-run yes
hello1
#+end_src
- In the src block, place the cursor after the
#+end_src line (simply at the very end of the #+end_src line, after the final character c).
- Execute the block with
C-c C-c.
Expected behavior:
The :dry-run output should show hello1 only once in the messages array:
: (:model "deepseek-v4-pro" :messages [(:role "user" :content "hello1")]
: :stream :json-false :temperature 1.0)
Actual behavior:
The messages array contains hello1 twice as consecutive user messages:
: (:model "deepseek-v4-pro" :messages
: [(:role "user" :content "hello1")
: (:role "user" :content "hello1")]
: :stream :json-false :temperature 1.0)
If the cursor is placed on or before the last character c of the #+end_src line (i.e., still inside the block's body area or on the #+end_src line itself), the duplication does not occur.
When using
:sessionin anob-gptelsource block and the point (cursor) is positioned after the charactercof#+end_srcline , the current block's body is incorrectly included in the session history. This causes the same user message to appear twice in the finalmessagesarray sent to the API.Steps to reproduce:
:sessionname:#+end_srcline (simply at the very end of the#+end_srcline, after the final characterc).C-c C-c.Expected behavior:
The
:dry-runoutput should showhello1only once in themessagesarray:Actual behavior:
The
messagesarray containshello1twice as consecutive user messages:If the cursor is placed on or before the last character
cof the#+end_srcline (i.e., still inside the block's body area or on the#+end_srcline itself), the duplication does not occur.