Repository navigation
Description
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
InstallationManager.install(force=True), which Update uses (POST /api/plugins/installed/{name}/refresh → update() → install(force=True)), removes the existing extension directory and copies the new one before opening its metadata session. The directory swap therefore runs outside the metadata load-save cycle, and outside the lock #5690 adds.
If a GET /api/plugins/installed lands in that window, validate_tracked sees the directory missing, removes the entry, and saves. The reinstall's session then finds no existing entry, so the previous enabled value isn't carried over and a disabled extension comes back enabled.
A list landing after the copy but before the reinstall's session instead rediscovers the directory as source="local". The reinstall overwrites that, but it's visible transiently. In the API runs on #5690 this showed up as 1 rediscovery in 30 cycles with that fix applied.
Expected Behavior
Updating a disabled extension keeps it disabled, regardless of concurrent list calls.
Actual Behavior
With a list call forced into the window, enabled goes from false to true after Update. The source stays correct.
Steps to Reproduce
- Run the script in "Minimal Code Sample" from a source checkout:
uv run python probe_update_reenables.py. It drivesInstallationManagerdirectly, so no server is needed. - It installs a test extension, disables it, then runs
update()while pausingshutil.copytreeinsideinstall()(after the old directory is removed) until alist_installed()call from another thread has finished. - Compare the
enabledvalue before and after the update.
Acceptance Criteria
- Updating or force-reinstalling a disabled extension keeps
enabled: falseeven whenGET /api/plugins/installedruns concurrently. - A concurrent list never removes, or rediscovers as
source="local", an extension whose directory is being replaced. - A regression test forces a list call into the directory-swap window.
Installation Method
Source checkout (git clone + uv sync), editable workspace install
If you selected "Other", please specify
No response
SDK Version
1.54.0
Version Confirmation
- I have confirmed this bug exists on the LATEST version of OpenHands SDK
Python Version
3.13.14
Model Name (if applicable)
No response
Operating System
Windows
Logs and Error Messages
On main @ 0bd5cc2d3:
before update: enabled = False
after update with concurrent list: enabled = True | source ok = True
Minimal Code Sample
"""Residual race: force-reinstall (Update) vs concurrent list, with the fix applied."""
import json, shutil, tempfile, threading, logging
from pathlib import Path
from pydantic import BaseModel
from openhands.sdk.extensions.installation import InstallationInterface, InstallationManager
import openhands.sdk.extensions.installation.manager as manager_module
logging.disable(logging.CRITICAL)
class Ext(BaseModel):
name: str; version: str = "0.0.1"; description: str = "x"
class Iface(InstallationInterface):
@staticmethod
def load_from_dir(extension_dir: Path) -> Ext:
return Ext.model_validate_json((extension_dir / "extension.json").read_text())
root = Path(tempfile.mkdtemp())
src = root / "magic-test"; src.mkdir()
(src / "extension.json").write_text(Ext(name="magic-test").model_dump_json())
inst = root / "installed"
mgr = InstallationManager(installation_dir=inst, installation_interface=Iface())
mgr.install(str(src)); mgr.disable("magic-test")
print("before update: enabled =", json.loads((inst/".installed.json").read_text())["extensions"]["magic-test"]["enabled"])
in_window, listed = threading.Event(), threading.Event()
real_copytree = shutil.copytree
def copytree(a, b, *k, **kw):
if threading.current_thread().name == "update":
in_window.set(); listed.wait(5) # old dir removed, new not copied yet
return real_copytree(a, b, *k, **kw)
manager_module.shutil.copytree = copytree
t1 = threading.Thread(target=lambda: mgr.update("magic-test"), name="update")
t2 = threading.Thread(target=lambda: (in_window.wait(5), mgr.list_installed(), listed.set()), name="list")
t1.start(); t2.start(); t1.join(10); t2.join(10)
e = json.loads((inst/".installed.json").read_text())["extensions"]["magic-test"]
print("after update with concurrent list: enabled =", e["enabled"], "| source ok =", e["source"] == str(src))Evidence and Additional Context
Follow-up to #5496 / #5690: the review there noted this window should be tracked.
Possible fixes: hold the metadata lock across the directory swap (simplest, but lock hold time then includes the copy), or capture the previous entry before removing the directory. I'd like to work on this once #5690 lands, and I'm happy to go with whichever approach you prefer.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
The report reproduces a real race in the shared installation layer. InstallationManager.install(force=True) — used by POST /api/plugins/installed/{name}/refresh → update_plugin() → update() — removes the old extension directory and copies the new one outside the metadata load-save cycle, so a concurrent list_installed() (equivalently GET /api/plugins/installed) can prune the entry (dropping the remembered enabled value) or rediscover the directory as source="local" before the reinstall's metadata session writes. The fix belongs in this repository's shared openhands.sdk.extensions.installation layer, because plugins, skills, and canvas extensions all delegate to it.
Scope: make the directory replacement in install(force=True) invisible to a concurrent metadata sync, so a list call landing during the swap cannot observe the extension as missing or untracked, and the pre-update enabled and source values are preserved. The acceptance criteria below constrain the approach to serializing the swap with the metadata cycle (or an equivalently atomic swap); the metadata lock introduced by #5690 is the mechanism to reuse.
Non-goals: the .installed.json write atomicity and cross-process lock itself (#5690 / #5496); refresh-endpoint semantics (#5653); the canvas-extensions staged check/apply flow, which already exists; and any change to the .installed.json schema, to enable/disable/list semantics, or to new REST endpoints. This issue assumes #5690 has landed, as the author states.
Acceptance Criteria
- Updating (or force-reinstalling) a disabled extension leaves
enabled: falsein.installed.json, even whenlist_installed()/GET /api/plugins/installedruns concurrently during the directory replacement. - Updating an enabled extension leaves it
enabled: true. - A concurrent list during the directory replacement neither deletes the extension's metadata entry nor rewrites its
sourceto"local"; after the update the entry'ssourceandenabledequal their pre-update values. - Through the product path,
POST /api/plugins/installed/{name}/refreshon a disabled plugin leaves it disabled whenGET /api/plugins/installedis issued concurrently during the refresh. -
.installed.jsonkeeps its existing shape (same fields and types forextensions,enabled,source); metadata written before the change still loads, and an entry rewritten by the fixed code round-trips without loss. - After a successful update, exactly one metadata entry and one install directory exist for the extension, the directory holds the newly fetched version, and no leftover temporary directory remains.
- A regression test forces a list call into the directory-replacement window (after the old directory is removed, before the new one is complete) and asserts the
enabledandsourceoutcomes above; it fails on the current code and passes after the fix.
Activity
vnktadithya commentedon Oct 14, 2026
I'll take this, following the triage.
install(force=True)will copy the new version into a dot-prefixed staging directory next to the install path (which discovery already skips). Then, inside its existing metadata session, under #5690's lock, it will swap the staged directory into place, keep the previousenabled/source, write the metadata, and remove the old directory and any staging leftovers. The lock is held for the swap and metadata write, not for the copy. Tests will force a list call into the swap window (failing on current code) and cover the product path:POST /api/plugins/installed/{name}/refreshwith concurrentGET /api/plugins/installed. This builds on #5690, so I'll open the PR once that lands.