Skip to content

Duplicate user message in session history when point is after the source block #10

Description

@TomoeMami

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:

  1. Create one Org source blocks with a :session name:
    #+begin_src gptel :session test :dry-run yes
    hello1
    #+end_src
    
  2. 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).
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions