Skip to content

[Bug]: A list call during Update (force reinstall) drops the extension's enabled state #5985

Open

Description

@vnktadithya

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

  1. Run the script in "Minimal Code Sample" from a source checkout: uv run python probe_update_reenables.py. It drives InstallationManager directly, so no server is needed.
  2. It installs a test extension, disables it, then runs update() while pausing shutil.copytree inside install() (after the old directory is removed) until a list_installed() call from another thread has finished.
  3. Compare the enabled value before and after the update.

Acceptance Criteria

  • Updating or force-reinstalling a disabled extension keeps enabled: false even when GET /api/plugins/installed runs 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: false in .installed.json, even when list_installed() / GET /api/plugins/installed runs 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 source to "local"; after the update the entry's source and enabled equal their pre-update values.
  • Through the product path, POST /api/plugins/installed/{name}/refresh on a disabled plugin leaves it disabled when GET /api/plugins/installed is issued concurrently during the refresh.
  • .installed.json keeps its existing shape (same fields and types for extensions, 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 enabled and source outcomes above; it fails on the current code and passes after the fix.

Activity

  1. added
    priority:lowFor bugs, affects only non-mainstream cases, or is annoying but with a clear workaround.
    ready-for-devIssue meets development readiness criteria
    on Oct 14, 2026
  2. vnktadithya commented on Oct 14, 2026

    @vnktadithya
    ContributorAuthor

    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 previous enabled/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}/refresh with concurrent GET /api/plugins/installed. This builds on #5690, so I'll open the PR once that lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:lowFor bugs, affects only non-mainstream cases, or is annoying but with a clear workaround.ready-for-devIssue meets development readiness criteria

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions