yetone / avante.nvim

Use your Neovim like using Cursor AI IDE!
Apache License 2.0
5.14k stars 171 forks source link

'nvim_buf_is_valid must not be called' error on submit #215

Closed isaacharrisholt closed 3 weeks ago

isaacharrisholt commented 3 weeks ago

I get the following when I try to submit any message through Avante:

Error executing luv callback:
...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:848: E5560: nvim_buf_is_valid must not be called in a lua loop callback
stack traceback:
        [C]: in function 'nvim_buf_is_valid'
        ...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:848: in function 'update_content'
        ...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:1203: in function 'on_complete'
        ...ac/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:149: in function '_user_on_exit'
        .../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:241: in function '_shutdown'
        .../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:48: in function <.../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:39>
        [C]: in function 'nvim_set_option_value'
        ...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:897: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

I'm using AstroNvim, and my Avante config ir the same as the one in the readme.

aarnphm commented 3 weeks ago

Can you provide a minimal reproducible?

isaacharrisholt commented 3 weeks ago

Errr not too good with nvim, but I'll try. Config is here if you want to take a look.

aarnphm commented 3 weeks ago
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system {
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable",
    lazypath,
  }
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup {
  spec = {
    {
      "AstroNvim/AstroNvim",
      version = "^4",
      import = "astronvim.plugins",
      opts = { -- AstroNvim options must be set here with the `import` key
        mapleader = " ", -- This ensures the leader key must be configured before Lazy is set up
        maplocalleader = ",", -- This ensures the localleader key must be configured before Lazy is set up
        icons_enabled = true, -- Set to false to disable icons (if no Nerd Font is available)
        pin_plugins = nil, -- Default will pin plugins when tracking `version` of AstroNvim, set to true/false to override
        update_notifications = true, -- Enable/disable notification about running `:Lazy update` twice to update pinned plugins
      },
    },
    {
      "yetone/avante.nvim",
      event = "VeryLazy",
      build = "make",
      opts = {},
      dependencies = {
        "nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
        "stevearc/dressing.nvim",
        "nvim-lua/plenary.nvim",
        "MunifTanjim/nui.nvim",
      },
    },
  },
  change_detection = { notify = false },
  checker = { enabled = true, frequency = 3600 * 24, notify = false },
  ui = { border = "single", backdrop = 100, wrap = false },
  dev = {
    path = "~/workspace/neovim-plugins/",
  },
}

This is the reproducible that I use, I don't see any issue?

isaacharrisholt commented 3 weeks ago

I'm getting it with this: https://github.com/isaacharrisholt/avante-bug

isaacharrisholt commented 3 weeks ago
NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1713484068
aarnphm commented 3 weeks ago

ah I see, I'm on nightly build atm let me check with the base release

yetone commented 3 weeks ago

@isaacharrisholt I tried to fix this issue in the latest version. Can you update and try again?

aarnphm commented 3 weeks ago

I'm building neovim 0.10 atm will get back to you

yetone commented 3 weeks ago

I'm building neovim 0.10 atm will get back to you

Although I tried to fix it, I couldn't reproduce it with Nvim 0.10.0. I'm updating to Nvim 0.10.1 to see if the old version can reproduce the issue and if the new version has successfully fixed it.

isaacharrisholt commented 3 weeks ago

@yetone that fixed it, but now I'm getting this: image

aarnphm commented 3 weeks ago

do you have credits on anthropic?

yetone commented 3 weeks ago

@yetone that fixed it, but now I'm getting this: image

You can try reinstalling curl:

brew reinstall curl
yetone commented 3 weeks ago

I'm building neovim 0.10 atm will get back to you

Although I tried to fix it, I couldn't reproduce it with Nvim 0.10.0. I'm updating to Nvim 0.10.1 to see if the old version can reproduce the issue and if the new version has successfully fixed it.

Nvim 0.10.1 also did not reproduce this issue on the code before the fix.

isaacharrisholt commented 3 weeks ago

do you have credits on anthropic?

Yes

You can try reinstalling curl:

No luck

aarnphm commented 3 weeks ago

what is your curl -V?

yetone commented 3 weeks ago

Can you manually execute this command in the Terminal? Remember to set the environment variables ANTHROPIC_API_KEY in advance:

curl -X POST https://api.anthropic.com/v1/messages \
-H "anthropic-beta: prompt-caching-2024-07-31" \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "system": "You are an excellent programming expert.\n",
  "max_tokens": 4096,
  "stream": true,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "<code>```sh\nL1: echo $FOO```<\/code>"
        },
        {
          "type": "text",
          "text": "<question>add incr<\/question>"
        },
        {
          "type": "text",
          "text": "Your primary task is to suggest code modifications with precise line number ranges. Follow these instructions meticulously:\n\n1. Carefully analyze the original code, paying close attention to its structure and line numbers. Line numbers start from 1 and include ALL lines, even empty ones.\n\n2. When suggesting modifications:\n   a. Use the language in the question to reply. If there are non-English parts in the question, use the language of those parts.\n   b. Explain why the change is necessary or beneficial.\n   c. Provide the exact code snippet to be replaced using this format:\n\nReplace lines: {{start_line}}-{{end_line}}\n```{{language}}\n{{suggested_code}}\n```\n\n3. Crucial guidelines for suggested code snippets:\n   - Only apply the change(s) suggested by the most recent assistant message (before your generation).\n   - Do not make any unrelated changes to the code.\n   - Produce a valid full rewrite of the entire original file without skipping any lines. Do not be lazy!\n   - Do not arbitrarily delete pre-existing comments/empty Lines.\n   - Do not omit large parts of the original file for no reason.\n   - Do not omit any needed changes from the requisite messages/code blocks.\n   - If there is a clicked code block, bias towards just applying that (and applying other changes implied).\n   - Please keep your suggested code changes minimal, and do not include irrelevant lines in the code snippet.\n\n4. Crucial guidelines for line numbers:\n   - The content regarding line numbers MUST strictly follow the format \"Replace lines: {{start_line}}-{{end_line}}\". Do not be lazy!\n   - The range {{start_line}}-{{end_line}} is INCLUSIVE. Both start_line and end_line are included in the replacement.\n   - Count EVERY line, including empty lines and comments lines, comments. Do not be lazy!\n   - For single-line changes, use the same number for start and end lines.\n   - For multi-line changes, ensure the range covers ALL affected lines, from the very first to the very last.\n   - Double-check that your line numbers align perfectly with the original code structure.\n\n5. Final check:\n   - Review all suggestions, ensuring each line number is correct, especially the start_line and end_line.\n   - Confirm that no unrelated code is accidentally modified or deleted.\n   - Verify that the start_line and end_line correctly include all intended lines for replacement.\n   - Perform a final alignment check to ensure your line numbers have not shifted, especially the start_line.\n   - Double-check that your line numbers align perfectly with the original code structure.\n\nRemember: Accurate line numbers are CRITICAL. The range start_line to end_line must include ALL lines to be replaced, from the very first to the very last. Double-check every range before finalizing your response, paying special attention to the start_line to ensure it has not shifted down. Ensure that your line numbers perfectly match the original code structure without any overall shift."
        }
      ]
    }
  ],
  "model": "claude-3-5-sonnet-20240620",
  "temperature": 0
}'
isaacharrisholt commented 3 weeks ago

what is your curl -V?

curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.16
Release-Date: 2022-01-05
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets zstd

I'll update

isaacharrisholt commented 3 weeks ago

Can you manually execute this command in the Terminal? Remember to set the environment variables ANTHROPIC_API_KEY in advance:

Works fine

isaacharrisholt commented 3 weeks ago

Still no luck after updating curl

isaacharrisholt commented 3 weeks ago

As far as I can tell from Anthropic's logs, messages aren't getting sent to the API.

yetone commented 3 weeks ago

What is your current curl version?

yetone commented 3 weeks ago

‌‌‌‌I saw a similar issue: https://github.com/composer/composer/issues/11913#issuecomment-2081516486

image
isaacharrisholt commented 3 weeks ago

What is your current curl version?

I've just updated to 8.9.1:

curl 8.9.1 (x86_64-pc-linux-gnu) libcurl/8.9.1 OpenSSL/3.3.1 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 libidn2/2.3.7 libssh2/1.11.0 nghttp2/1.61.0 librtmp/2.3 OpenLDAP/2.6.8
Release-Date: 2024-07-31
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd
aarnphm commented 3 weeks ago

I'm currently on curl 8.9.0

isaacharrisholt commented 3 weeks ago

Still no luck, I'm afraid

isaacharrisholt commented 2 weeks ago

I've experimented with this further, and it works fine on my mac - appears to only be a problem under WSL2.

yetone commented 2 weeks ago

I've experimented with this further, and it works fine on my mac - appears to only be a problem under WSL2.

The reason for the curl failure is: https://github.com/yetone/avante.nvim/issues/315#issuecomment-2315968088

isaacharrisholt commented 2 weeks ago

Works, thank you!