Update failure!

Description

Always get this error whenever I update the addon.

```
Anki 26.09.2 (bb0dd6d1) (ao)
Python 3.13.15 Qt 6.11.2 PyQt 6.11.0
Platform: Windows-11-10.0.26200-SP0

Traceback (most recent call last):
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\send2trash\win\modern.py”, line 55, in send2trash
pywintypes.com_error: (-2144927704, ‘OLE error 0x80270028’, None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\utils.py”, line 1040, in send_to_trash
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\send2trash\win\modern.py”, line 63, in send2trash
OSError: [WinError -2144927704] OLE error 0x80270028: ‘C:\Users\USER\AppData\Roaming\Anki2\addons21\124672614’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\taskman.py”, line 152, in raise_exception
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\taskman.py”, line 148, in _on_closures_pending
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\taskman.py”, line 88, in
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\addons.py”, line 1285, in _download_done
File “concurrent\futures_base.py”, line 453, in result
File “concurrent\futures_base.py”, line 402, in __get_result
File “concurrent\futures\thread.py”, line 59, in run
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\addons.py”, line 1262, in
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\addons.py”, line 1278, in _download_all
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\addons.py”, line 1223, in download_and_install_addon
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\addons.py”, line 477, in install
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\addons.py”, line 503, in _install
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\addons.py”, line 527, in deleteAddon
File “D:\a\anki\anki\out\installer\build\anki\windows\visualstudio\x64\Release\app_packages\aqt\utils.py”, line 1045, in send_to_trash
File “shutil.py”, line 790, in rmtree
File “shutil.py”, line 629, in _rmtree_unsafe
File “shutil.py”, line 625, in _rmtree_unsafe
PermissionError: [WinError 5] Access is denied: ‘C:\Users\USER\AppData\Roaming\Anki2\addons21\124672614\_cache\pydantic_core_pkg\pydantic_core\_pydantic_core.cp313-win_amd64.pyd’
```

Steps to Reproduce

  1. Update the AnkiMCP addon.

Environment

  • Anki 26.09.2 (bb0dd6d1) (ao)
    Python 3.13.15 Qt 6.11.2 PyQt 6.11.0
    Platform: Windows-11-10.0.26200-SP0

Thanks for the report. This is a bug on our side, not something wrong with your setup.

What’s happening: the add-on keeps a native library (pydantic_core) in a _cache folder inside its own add-on directory. While Anki is running, Windows locks that file. When Anki tries to replace the add-on folder during an update, it can’t delete it. macOS and Linux don’t lock files this way, so it only shows up on Windows. We’re working on a fix that moves that cache out of the add-on folder.

A few questions that would help us:

  1. After you get this error and restart Anki, does the add-on still work, or is it broken until you reinstall?
  2. Which version does it show afterwards (Tools → AnkiMCP Server Settings)? Does it stay on the old version?
  3. You wrote it always happens. Has an update of this add-on ever gone through cleanly for you on Windows?
  4. Right after the error, before restarting, which subfolders are still in C:\Users\<you>\AppData\Roaming\Anki2\addons21\124672614?

Thanks for the report — I reproduced this on a Windows 11 machine today and got exactly your traceback. It’s a bug on our side, not something wrong with your setup, and it affects every Windows user.

What’s happening: the add-on keeps a native library (pydantic_core) in a _cache folder inside its own add-on directory. While Anki is running, Windows won’t let that file be deleted, so when Anki tries to replace the add-on folder during an update, the delete fails halfway. Worse, by that point most of the add-on’s files are already gone — so after restarting Anki you get a “Setup Failed” message and the add-on doesn’t load. macOS and Linux allow deleting a file that’s in use, which is why it only shows up on Windows.

How to update until the fix is out (tested today):

  1. Tools → Add-ons → select AnkiMCP Server → Toggle Enabled (this disables it)
  2. Restart Anki
  3. Tools → Add-ons → Check for Updates → install the update
  4. Tools → Add-ons → select AnkiMCP Server → Toggle Enabled again (Anki keeps it disabled after the update, so this step matters)
  5. Restart Anki

With the add-on disabled the library is never loaded, so Anki can replace the folder normally.

If the add-on is currently broken (you see “Setup Failed” or “Add-on Startup Failed” on start): try Check for Updates once more — in most cases the second attempt goes through. If it fails again with an error mentioning user_files, close Anki, delete the folder C:\Users\<you>\AppData\Roaming\Anki2\addons21\124672614, start Anki and reinstall the add-on with code 124672614. You’ll need to sign in to the tunnel again if you use it.

We’re working on a proper fix that moves that cache out of the add-on folder, so updates just work.

One question that would help: do you have “log to file” turned on in the add-on’s config (log_to_file)? And after the error, did a second update attempt work for you, or did you have to reinstall?

What was happening: the add-on kept a native library (pydantic_core) inside its own add-on folder. Windows won’t delete a file that a running program has loaded, and Anki updates an add-on by deleting its whole folder — so the delete failed halfway and left the add-on broken. macOS and Linux allow deleting a file that’s in use, which is why it only showed up on Windows.

The fix is done and tested, and will be released shortly as v0.29.1. The library now lives outside the add-on folder, so Anki can replace the folder freely. I verified on Windows that updating and uninstalling both work, even while the add-on is running.

One catch: the update to v0.29.1 is still carried out by the old version, so it needs one careful step. When the release is out:

  1. Tools → Add-ons → select AnkiMCP Server → Toggle Enabled (disables it)
  2. Restart Anki
  3. Check for Updates and install
  4. Select the add-on again → Toggle Enabled (Anki keeps it disabled after an update) → restart Anki

After that one update, future updates just work.

If the add-on is already broken from a failed update (you see “Setup Failed” on start), running Check for Updates again gets it installed — with nothing loaded, Anki can replace the folder.

Thank you once again for the report, it looks that this issue was a long time and nobody reported. I fixed it in 0.29.1 and just released. You will need one last time to “dance” to make this upgrade, but every following upgrade will work fine.
See details here: https://ankiweb.net/shared/info/124672614

Thanks for the thorough investigation. Disabling the add-on before updating worked well. I’ll try updating without it in future versions and keep you noted.

1 Like