fix(plugins): retry transient Claude marketplace update failures
On Windows the Claude CLI swaps in a fresh marketplace clone by renaming it, which fails with EPERM while antivirus, indexers, or open sessions briefly hold the folder. Retry the update up to three times with a short backoff on EPERM, EBUSY, EACCES, or "try again" errors; other failures still stop at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5664fec100
commit
870cad66ac
2 files changed
+32
-2
No files matched your search
@@ -11,6 +11,7 @@ import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.request
|
||||
import zipfile
|
||||
|
||||
@@ -267,6 +268,16 @@ class Manager:
|
||||
else:
|
||||
run_command(arguments, self.summary, self.home)
|
||||
|
||||
def refresh_marketplace(self, client, name):
|
||||
# Windows briefly locks a fresh marketplace clone (antivirus, indexers, open sessions), so the CLI's rename fails with EPERM.
|
||||
for attempt in range(3):
|
||||
try:
|
||||
return self.command([client, 'plugin', 'marketplace', 'update', name])
|
||||
except ValueError as error:
|
||||
if attempt == 2 or not re.search(r'\b(EPERM|EBUSY|EACCES)\b|try again', str(error), re.I):
|
||||
raise
|
||||
time.sleep(5 * (attempt + 1))
|
||||
|
||||
def remove(self, record):
|
||||
if self.dry_run:
|
||||
if not self.summary:
|
||||
@@ -356,7 +367,7 @@ class Manager:
|
||||
self.save()
|
||||
return
|
||||
if item is not None and client == 'claude':
|
||||
self.command([client, 'plugin', 'marketplace', 'update', selector.rsplit('@', 1)[1]])
|
||||
self.refresh_marketplace(client, selector.rsplit('@', 1)[1])
|
||||
self.command([client, 'plugin', 'update', selector])
|
||||
if item.get('enabled') is False:
|
||||
self.command([client, 'plugin', 'enable', selector])
|
||||
@@ -376,7 +387,7 @@ class Manager:
|
||||
else:
|
||||
self.command([client, 'plugin', 'marketplace', 'add', marketplace])
|
||||
if client == 'claude':
|
||||
self.command([client, 'plugin', 'marketplace', 'update', selector.rsplit('@', 1)[1]])
|
||||
self.refresh_marketplace(client, selector.rsplit('@', 1)[1])
|
||||
arguments = [client, 'plugin', 'install', selector, '--scope', 'user'] if client == 'claude' else [client, 'plugin', 'add', selector]
|
||||
self.command(arguments)
|
||||
resolved_version = None
|
||||
|
||||
@@ -203,8 +203,27 @@ class ManagedExtensionTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, 'refresh failed'):
|
||||
self.manager().sync([plugin()], ['claude'], {'Example'})
|
||||
self.assertEqual(['claude', 'plugin', 'marketplace', 'update', 'test'], command.call_args.args[0])
|
||||
self.assertEqual(1, command.call_count)
|
||||
self.assertEqual([], self.manager().state['resources'])
|
||||
|
||||
def test_claude_marketplace_refresh_retries_transient_lock(self):
|
||||
failures = [ValueError("EPERM: operation not permitted, rename 'caveman..clone'")] * 2
|
||||
def command(args, summary, home=None):
|
||||
if args[2:4] == ['marketplace', 'update'] and failures:
|
||||
raise failures.pop()
|
||||
return self.command(args, summary, home)
|
||||
with patch.object(extensions, 'run_command', side_effect=command), patch.object(extensions.time, 'sleep') as sleep:
|
||||
self.manager().sync([plugin()], ['claude'], {'Example'})
|
||||
self.assertEqual(2, sleep.call_count)
|
||||
self.assertEqual(['claude', 'plugin', 'install', 'example@test', '--scope', 'user'], self.commands[-1])
|
||||
self.assertEqual(['Example'], [r['name'] for r in self.manager().state['resources']])
|
||||
|
||||
def test_claude_marketplace_refresh_gives_up_after_three_transient_failures(self):
|
||||
with patch.object(extensions, 'run_command', side_effect=ValueError('EBUSY')) as command, patch.object(extensions.time, 'sleep'):
|
||||
with self.assertRaisesRegex(ValueError, 'EBUSY'):
|
||||
self.manager().sync([plugin()], ['claude'], {'Example'})
|
||||
self.assertEqual(3, command.call_count)
|
||||
|
||||
@unittest.skipUnless(os.name == 'nt', 'Windows hook compatibility')
|
||||
def test_owned_caveman_hook_repair_runs_in_powershell_and_is_idempotent(self):
|
||||
entry = dict(plugin('Caveman'), codex_plugin='caveman@thinkhome-caveman')
|
||||
|
||||
Reference in new issue
Block a user