Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

fix(extensions): a disable no longer fails on the owner's progress record (#8261)

Mike Bradley73d5efd4e962
diff --git a/ods/bin/ods-host-agent.py b/ods/bin/ods-host-agent.py
index 93859df6e..2562262e7 100755
--- a/ods/bin/ods-host-agent.py
+++ b/ods/bin/ods-host-agent.py
@@ -8455,6 +8455,22 @@ def _resolve_local_gguf_filename(model_id: str, models_dir: Path) -> str | None:
return None
+def _clear_disabled_progress(service_id: str) -> None:
+ """Remove a just-disabled service's progress record.
+
+ A recent ``started`` record outranks a disabled selection on the Extensions
+ page. The host writes these records as the install owner, so where that
+ owner is not UID 1000 the Dashboard cannot remove them, and its disable
+ failed with HTTP 500 after the service had stopped (Workstation06,
+ 2026-10-27). The selection is already committed; a leftover record is
+ logged rather than reported as a failed disable.
+ """
+ try:
+ (DATA_DIR / "extension-progress" / f"{service_id}.json").unlink(missing_ok=True)
+ except OSError as exc:
+ logger.warning("Could not clear the progress record of disabled %s: %s", service_id, exc)
+
+
def _read_progress_status(service_id: str) -> str | None:
"""Return the ``status`` field of the progress file, or None if absent/unreadable.
@@ -12767,6 +12783,8 @@ class AgentHandler(BaseHTTPRequestHandler):
if outcome == "already_disabled":
json_response(self, 409, {"error": f"Extension already disabled: {service_ids[0]}"})
return
+ if outcome == "disabled":
+ _clear_disabled_progress(service_ids[0])
json_response(self, 200, {"status": "ok", "service_ids": service_ids, "action": outcome})
def _handle_extension_sync_config(self):
diff --git a/ods/extensions/services/dashboard-api/routers/extensions.py b/ods/extensions/services/dashboard-api/routers/extensions.py
index 1071e881c..7ab3eae19 100644
--- a/ods/extensions/services/dashboard-api/routers/extensions.py
+++ b/ods/extensions/services/dashboard-api/routers/extensions.py
@@ -5252,8 +5252,8 @@ def disable_extension(service_id: str, include_data_info: bool = Query(True), ap
# time, so companions go first.
for target in (*companions, service_id):
_select_extensions_on_host("disable", [target])
- progress_file = Path(DATA_DIR) / "extension-progress" / f"{target}.json"
- progress_file.unlink(missing_ok=True)
+ # The host clears its own record; this covers an older host agent.
+ _clear_progress(target)
logger.info("Disabled extension: %s (companions: %s)", service_id, companions or "none")
@@ -5369,8 +5369,7 @@ def uninstall_extension(service_id: str, include_data_info: bool = Query(True),
shutil.rmtree(backup)
_invalidate_extension_digest_cache(ext_dir, backup)
- progress_file = Path(DATA_DIR) / "extension-progress" / f"{service_id}.json"
- progress_file.unlink(missing_ok=True)
+ _clear_progress(service_id)
logger.info("Uninstalled extension: %s (stopped first: %s)", service_id, stopped_before_removal)
message = "Extension uninstalled. Docker volumes may remain; run 'docker volume ls' to check."
@@ -5448,8 +5447,7 @@ def purge_extension_data(
# Also clean up the per-service install-progress file so
# _compute_extension_status does not keep showing a stale "installing"
# entry after the user purges an extension's data.
- progress_file = Path(DATA_DIR) / "extension-progress" / f"{service_id}.json"
- progress_file.unlink(missing_ok=True)
+ _clear_progress(service_id)
return {"id": service_id, "action": "purged", "size_gb_freed": size_gb}
diff --git a/ods/extensions/services/dashboard-api/tests/test_extensions.py b/ods/extensions/services/dashboard-api/tests/test_extensions.py
index aa4e0db28..ed8fbe6ef 100644
--- a/ods/extensions/services/dashboard-api/tests/test_extensions.py
+++ b/ods/extensions/services/dashboard-api/tests/test_extensions.py
@@ -1687,6 +1687,36 @@ class TestDisableExtension:
assert resp.status_code == 200
assert not progress_file.exists()
+ def test_disable_completes_when_the_owner_record_cannot_be_removed(
+ self, test_client, monkeypatch, tmp_path, caplog,
+ ):
+ """Workstation06 (2026-10-27): the host agent writes start records as the
+ install owner, UID 1001. This API runs as UID 1000 and could not remove
+ them, so a disable that had already stopped the service answered 500."""
+ user_dir = _setup_user_ext(tmp_path, "my-ext", enabled=True)
+ _patch_mutation_config(monkeypatch, tmp_path, user_dir=user_dir)
+ progress_file = tmp_path / "extension-progress" / "my-ext.json"
+ progress_file.parent.mkdir(parents=True, exist_ok=True)
+ progress_file.write_text('{"status": "started", "updated_at": "2026-10-27T08:26:00+00:00"}')
+ real_unlink = Path.unlink
+
+ def owner_only(path, *args, **kwargs):
+ if path == progress_file:
+ raise PermissionError(13, "Permission denied", str(path))
+ return real_unlink(path, *args, **kwargs)
+
+ monkeypatch.setattr(Path, "unlink", owner_only)
+ with caplog.at_level(logging.WARNING):
+ resp = test_client.post(
+ "/api/extensions/my-ext/disable",
+ headers=test_client.auth_headers,
+ )
+
+ assert resp.status_code == 200
+ assert resp.json()["action"] == "disabled"
+ assert (user_dir / "my-ext" / "compose.yaml.disabled").exists()
+ assert "Failed to clear progress file for my-ext" in caplog.text
+
def test_disable_already_disabled_409(self, test_client, monkeypatch, tmp_path):
"""409 when extension is already disabled."""
user_dir = _setup_user_ext(tmp_path, "my-ext", enabled=False)
diff --git a/ods/extensions/services/dashboard-api/tests/test_host_agent.py b/ods/extensions/services/dashboard-api/tests/test_host_agent.py
index 6f4c05605..95f0e53ec 100644
--- a/ods/extensions/services/dashboard-api/tests/test_host_agent.py
+++ b/ods/extensions/services/dashboard-api/tests/test_host_agent.py
@@ -320,6 +320,47 @@ def test_host_selection_endpoint_requires_auth_and_preserves_batch(
thread.join(timeout=2)
+def test_host_disable_clears_the_progress_record_it_wrote(
+ monkeypatch, tmp_path, host_agent_wire_client,
+):
+ """The host writes start records as the install owner; where that owner is
+ not UID 1000 only the host can remove them (Workstation06, 2026-10-27)."""
+ from http.server import HTTPServer
+
+ from fastapi import HTTPException
+
+ from routers import extensions as ext_router
+
+ monkeypatch.setattr(_mod, "AGENT_API_KEY", "selection-wire-secret")
+ monkeypatch.setattr(_mod, "DATA_DIR", tmp_path)
+ outcomes = iter(["disabled", "already_disabled"])
+ monkeypatch.setattr(
+ _mod, "_apply_extension_selection",
+ lambda service_ids, activate, expected_sha256=None: next(outcomes),
+ )
+ record = tmp_path / "extension-progress" / "whisper.json"
+ record.parent.mkdir()
+ server = HTTPServer(("127.0.0.1", 0), _mod.AgentHandler)
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
+ thread.start()
+ try:
+ host_agent_wire_client(server.server_address[1], key="selection-wire-secret")
+ record.write_text('{"status": "started"}', encoding="utf-8")
+ assert ext_router._select_extensions_on_host("disable", ["whisper"])["action"] == "disabled"
+ assert not record.exists()
+
+ # Nothing was disabled, so the record stays.
+ record.write_text('{"status": "started"}', encoding="utf-8")
+ with pytest.raises(HTTPException) as refused:
+ ext_router._select_extensions_on_host("disable", ["whisper"])
+ assert refused.value.status_code == 409
+ assert record.exists()
+ finally:
+ server.shutdown()
+ server.server_close()
+ thread.join(timeout=2)
+
+
@pytest.mark.parametrize("model,settings,override", [
("Systran/faster-whisper-base", "AUDIO_STT_MODEL=Systran/faster-whisper-base\n", False),
("deepdml/faster-whisper-large-v3-turbo-ct2", "GPU_BACKEND=nvidia\n", False),