olimorris / codecompanion.nvim

✨ AI-powered coding, seamlessly in Neovim. Supports Anthropic, Copilot, Gemini, Ollama, OpenAI and xAI LLMs
MIT License
1.03k stars 78 forks source link

[Bug]: Stack Overflow (infinite recursion) with `find_key` when cycling Chats with `{` or `}` #435

Open GitMurf opened 2 hours ago

GitMurf commented 2 hours ago

Your minimal.lua config

Confirmed with minimal config...

Error messages

See screenshot below for full error.

E5108: Error executing lua: ...lazy/codecompanion.nvim/lua/codecompanion/utils/util.lua:81: stack overflow
...codecompanion.nvim/lua/codecompanion/utils/util.lua:81: in function 'find_key'

Log output

See screenshot...

image

Health check output

No response

Describe the bug

I have experienced this happening at other random times with other keymaps or actions using the plugin but what I am describing here is a guaranteed reproducible example. I started to do some debugging myself digging into the code and logging but it was getting too complicated without me knowing the ins and the outs and goals of this find_key function. I think you should probably do a deep dive / audit into it because I am pretty sure there are other problems with this, not just this example I am reproducing. Maybe add a recursion limit count and if it hits that, error out and log to the user to report it so that you can determine whether other issues. In my limited testing it seemed like it was recursing a lot given table values that are references to others like Chats and References etc.

Reproduce the bug

  1. Open nvim
  2. Open any buffer
  3. Create a new chat with :CodeCompanionChat
  4. Immediately after that create another new chat with :CodeCompanionChat
  5. Try to cycle between chats with { or }
  6. A stack overflow error is given because of infinite recursion with the find_key function

image

Final checks

GitMurf commented 2 hours ago

@olimorris fyi this is NOT something that just popped up with the new updates today / yesterday. I recall this happening in the past but just finally able to repro it consistently to report it.