Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/desktop/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# CHANGELOG


## Unreleased



## v0.32.2 (2026-11-24)

### Bug Fixes

- **desktop**: launch authoring Chromium keychain-safe and close what it owns



## v0.32.1 (2026-11-23)

### Bug Fixes
Expand All @@ -20,7 +32,6 @@
- **desktop**: preserve pinned theme bytes on checkout



## v0.31.3 (2026-11-22)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/openadapt_desktop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
+-- backends/ Storage backend plugins
"""

__version__ = "0.32.1"
__version__ = "0.32.2"
152 changes: 124 additions & 28 deletions packages/desktop/openadapt_desktop/authoring_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,47 @@ def _require_empty_cookies(browser: Any) -> None:
raise AuthoringError("Playwright Chromium did not start with empty cookies.")


def launch_empty_playwright_chromium(url: str) -> Any:
# Chromium flags for a browser Desktop launches itself: use a mock keychain and
# the basic password store so the launch never prompts for the login keychain.
OWNED_CHROMIUM_ARGS = ("--use-mock-keychain", "--password-store=basic")


class OwnedChromium:
"""A Chromium that Desktop launched, with the context, browser and driver it owns.

``close`` tears all of them down, newest first. It is idempotent and never
raises, so it can run on setup failure and on every terminal stop.
"""

def __init__(self, playwright: Any, browser: Any, context: Any, page: Any = None) -> None:
self.playwright = playwright
self.browser = browser
self.context = context
self.page = page
self.closed = False

def close(self) -> None:
if self.closed:
return
self.closed = True
for name, owner in (
("context", self.context),
("browser", self.browser),
):
if owner is None:
continue
try:
owner.close()
except Exception as exc: # noqa: BLE001 - teardown keeps going
logger.warning("authoring Chromium {} close failed: {}", name, type(exc).__name__)
if self.playwright is not None:
try:
self.playwright.stop()
except Exception as exc: # noqa: BLE001 - teardown keeps going
logger.warning("authoring Playwright stop failed: {}", type(exc).__name__)


def launch_empty_playwright_chromium(url: str, *, headless: bool = False) -> OwnedChromium:
"""Launch a fresh Chromium with empty cookies. Never attach to logged-in Chrome."""

if not isinstance(url, str) or not url.startswith("https://"):
Expand All @@ -148,17 +188,20 @@ def launch_empty_playwright_chromium(url: str) -> Any:
from playwright.sync_api import sync_playwright
except ImportError as exc:
raise AuthoringError("Playwright Chromium is unavailable.") from exc
playwright = sync_playwright().start()
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
cookies = context.cookies()
if cookies:
browser.close()
playwright.stop()
raise AuthoringError("Playwright Chromium did not start with empty cookies.")
page = context.new_page()
page.goto(url)
return page
owned = OwnedChromium(sync_playwright().start(), None, None)
try:
owned.browser = owned.playwright.chromium.launch(
headless=headless, args=list(OWNED_CHROMIUM_ARGS)
)
owned.context = owned.browser.new_context()
if owned.context.cookies():
raise AuthoringError("Playwright Chromium did not start with empty cookies.")
owned.page = owned.context.new_page()
owned.page.goto(url)
except BaseException:
owned.close()
raise
return owned


def _pack_dir(data_dir: Path, pack_id: str) -> Path:
Expand Down Expand Up @@ -607,6 +650,7 @@ def __init__(
self._coach_hint: str | None = None
self._out_dir: Path | None = None
self._playwright: Any | None = None
self._start_generation = 0

def is_bound(self) -> bool:
return self._pack is not None and self._lease_secret is not None
Expand Down Expand Up @@ -1048,22 +1092,53 @@ def _start_record(self) -> dict[str, Any]:
backend = str(self._pin.get("backend") or "macos")
if backend == "windows":
raise AuthoringCoachOnly("COACH_ONLY")

with self._lock:
self._start_generation += 1
start_gen = self._start_generation

browser = None
if backend == "web":
url = self._pin.get("url")
if not isinstance(url, str) or not url.startswith("https://"):
raise AuthoringError("A Playwright job needs a URL typed into Desktop.")
launcher = self._playwright_launcher or launch_empty_playwright_chromium
self._playwright = launcher(url)
_require_empty_cookies(self._playwright)
factory = self._recorder_factory
if factory is None:
raise AuthoringError("Authoring recorder is unavailable.")
out_dir = self._out_dir or _pack_dir(self.config.data_dir, self._pack or "p.invalidpackid")
out_dir.mkdir(parents=True, exist_ok=True)
self._recorder = factory(out_dir)
self._recording = True
self._secret_pause = False
self._secret_type_recorded = False
self._close_owned_browser()
browser = launcher(url)

with self._lock:
if self._start_generation != start_gen:
if browser is not None:
self._close_owned_browser(browser)
return {"recording": False}
self._playwright = browser

try:
if backend == "web":
_require_empty_cookies(self._playwright)
factory = self._recorder_factory
if factory is None:
raise AuthoringError("Authoring recorder is unavailable.")
out_dir = self._out_dir or _pack_dir(
self.config.data_dir, self._pack or "p.invalidpackid"
)
out_dir.mkdir(parents=True, exist_ok=True)
recorder = factory(out_dir)
except BaseException:
self._close_owned_browser()
raise

with self._lock:
if self._start_generation != start_gen:
if hasattr(recorder, "finish") and callable(recorder.finish):
recorder.finish()
self._close_owned_browser()
return {"recording": False}
self._recorder = recorder
self._recording = True
self._secret_pause = False
self._secret_type_recorded = False

self.emit("status_update", self.status_dict() or {})
return {"recording": True}

Expand Down Expand Up @@ -1122,15 +1197,34 @@ def _pause_for_input(self, args: dict[str, Any]) -> dict[str, Any]:
self.emit("status_update", self.status_dict() or {})
return {"paused": True, "param": param}

def _close_owned_browser(self, target: Any = None) -> None:
"""Close a Chromium Desktop launched. An attached browser is left open."""

if target is None:
browser, self._playwright = self._playwright, None
else:
browser = target
if self._playwright is target:
self._playwright = None
if isinstance(browser, OwnedChromium):
browser.close()

def _stop_record(self) -> dict[str, Any]:
recorder = self._recorder
with self._lock:
self._start_generation += 1
recorder = self._recorder
if recorder is None:
self._close_owned_browser()
return {"recording": False}
finish = getattr(recorder, "finish", None)
if callable(finish):
finish()
self._recording = False
self._paused = False
try:
if callable(finish):
finish()
finally:
self._close_owned_browser()
with self._lock:
self._recording = False
self._paused = False
self.emit("status_update", self.status_dict() or {})
return {"recording": False}

Expand All @@ -1156,6 +1250,7 @@ def _compile(self) -> dict[str, Any]:

def _halt(self, *, unsigned: bool, command_id: str | None) -> None:
with self._lock:
self._start_generation += 1
if self._actuation_started:
self._uncertain = True
uncertain = True
Expand All @@ -1176,6 +1271,7 @@ def _halt(self, *, unsigned: bool, command_id: str | None) -> None:
}
)
return
self._close_owned_browser()
if self._node_table is not None:
self._node_table.clear()
if unsigned and self._pack and self._lease_secret and self._transport:
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openadapt-desktop",
"version": "0.32.1",
"version": "0.32.2",
"description": "Installed companion for OpenAdapt authoring, teaching, and local pairing",
"private": true,
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "openadapt-desktop"
version = "0.32.1"
version = "0.32.2"
description = "The OpenAdapt desktop app and local engine: record a data-entry task, run it on a list, and check each saved record"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openadapt-desktop"
version = "0.32.1"
version = "0.32.2"
description = "Installed companion for OpenAdapt authoring, teaching, and local pairing"
authors = ["OpenAdapt AI"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/nicoverbruggen/tauri-v2-schema/main/schema.json",
"productName": "OpenAdapt Desktop",
"version": "0.32.1",
"version": "0.32.2",
"identifier": "ai.openadapt.desktop",
"build": {
"frontendDist": "../dist",
Expand Down
Loading