Skip to content

Do not re-use the same chatId forever#51

Merged
joaopluigi merged 3 commits intomainfrom
renew-chat-id
Oct 11, 2025
Merged

Do not re-use the same chatId forever#51
joaopluigi merged 3 commits intomainfrom
renew-chat-id

Conversation

@joaopluigi
Copy link
Copy Markdown
Contributor

@joaopluigi joaopluigi commented Oct 10, 2025

Context

Chat keeps context even when nvim is closed and re-opened because the chatId sent to the server is always 1. This makes the context become huge; consequently, paying more tokens that it was supposed to.

Example:
2025-10-09_17-45

Solution

Sends chatId as nil and them use the value the server send back as the chatId, saving it to the state

joaopluigi and others added 2 commits October 10, 2025 16:43
Add a focused test suite validating that:
- mediator/state track and expose the current chat-id
- chat/prompt requests omit chatId before one is assigned and include it afterwards
- reopening Neovim starts with no chat-id and uses a new one once provided by the server

This safeguards the change to use a new chat-id when reopening Neovim and prevents regressions.

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <noreply@eca.dev>
@joaopluigi joaopluigi marked this pull request as ready for review October 10, 2025 19:53
Copilot AI review requested due to automatic review settings October 10, 2025 19:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where chat context persists between Neovim sessions by implementing dynamic chat ID management. Instead of using a hardcoded chat ID, the system now starts with nil and updates to use the server-provided chat ID.

  • Replaces hardcoded chat ID with dynamic ID from server responses
  • Adds state management for tracking current chat ID
  • Ensures fresh chat sessions when reopening Neovim

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/test_chat_id.lua Comprehensive test suite covering chat ID lifecycle scenarios
lua/eca/state.lua Adds id field and logic to update chat ID from server responses
lua/eca/sidebar.lua Changes to use mediator's dynamic chat ID instead of hardcoded value
lua/eca/mediator.lua Adds id() method to retrieve current chat ID from state

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread lua/eca/mediator.lua Outdated
end

function mediator:id()
return (self.state and self.state.id)
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The parentheses around the return expression are unnecessary and don't add clarity. Consider removing them for cleaner code.

Suggested change
return (self.state and self.state.id)
return self.state and self.state.id

Copilot uses AI. Check for mistakes.
@joaopluigi joaopluigi changed the title Use a new chat-id when re-opening nvim Do not re-use the same chatId forever Oct 10, 2025
@joaopluigi joaopluigi merged commit e6e31d0 into main Oct 11, 2025
3 checks passed
@joaopluigi joaopluigi deleted the renew-chat-id branch October 11, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants