Skip to content

Self-improving AI Employees for everyone

revert(paths): drop the legacy-layout auto-migration

trohitg2d858b9a08eb
diff --git a/.env.template b/.env.template
index a22bf3f9..a052e01b 100644
--- a/.env.template
+++ b/.env.template
@@ -60,9 +60,10 @@ TEMPORAL_BACKEND=postgres
# - absolute → used verbatim
# - relative → resolved under repo root (back-compat)
#
-# Set to `.machina` if you want pre-cutover repo-local behaviour.
-# MachinaOs auto-migrates the legacy `data/` + `workflows/` layout
-# on first boot (`migrate_legacy_layout`).
+# Set to `.machina` (or `data`) if you want repo-local behaviour
+# instead. Pre-cutover layouts (`<repo>/data/`, `<repo>/workflows/`)
+# do NOT auto-migrate — see `server/core/paths.py` for the manual
+# `mv` checklist if you're upgrading from an older release.
DATA_DIR=~/.machina
# Per-workflow workspace (nodes save files here, resolved under DATA_DIR)
diff --git a/.gitignore b/.gitignore
index 183e67fb..8d626695 100644
--- a/.gitignore
+++ b/.gitignore
@@ -131,16 +131,14 @@ pnpm-store/
.claude/
# MachinaOs runtime root (`server/core/paths.py::machina_root`). Holds
# claude/, workspaces/, workflows/, whatsapp/, credentials.db,
-# machina.db — every machine-local artefact. Override path via
-# `DATA_DIR` env var in `.env`. Auto-migrated from the legacy `data/`
-# + `workflows/` layout on first boot.
+# workflow.db — every machine-local artefact. Override path via
+# `DATA_DIR` env var in `.env` (default is `~/.machina`, the user
+# home dir; not normally present at the repo root).
/.machina/
-# Legacy data dir (pre-cutover layout). Auto-migrated into `.machina/`
-# on first boot but the empty husk may linger if rmdir failed; keep
-# ignored so partial state can't accidentally land in commits.
+# Legacy data + workflows dirs from the pre-cutover layout. Operators
+# upgrading from older releases either set `DATA_DIR=data` to keep
+# the old layout or `mv` the contents to `~/.machina/` manually.
/data/
-# Legacy workflows dir (pre-cutover layout). Auto-migrated into
-# `.machina/workflows/` on first boot.
/workflows/
# Patch archive left behind by `git format-patch` during one-off
# merges (see ../.merge-archive cleanup commits). Never committed.
diff --git a/server/core/config.py b/server/core/config.py
index 90e17192..36c07f86 100644
--- a/server/core/config.py
+++ b/server/core/config.py
@@ -180,9 +180,10 @@ class Settings(BaseSettings):
# (``~/.claude/``), Stripe (``~/.config/stripe/``), ngrok
# (``~/.ngrok2/``). Survives ``rm -rf`` of the repo. Resolution
# rules (``~``, absolute, repo-relative) live in
- # :func:`core.paths.machina_root`. One-time auto-migration of
- # the pre-cutover ``data/`` + ``workflows/`` layout runs on
- # startup via :func:`core.paths.migrate_legacy_layout`.
+ # :func:`core.paths.machina_root`. No auto-migration from the
+ # pre-cutover ``data/`` + ``workflows/`` layout — operators
+ # either set ``DATA_DIR=data`` to keep the old layout or move
+ # the contents manually (see ``paths.py`` docstring).
data_dir: str = Field(default="~/.machina", env="DATA_DIR")
# Credentials Database (separate encrypted database for API keys and OAuth tokens)
diff --git a/server/core/paths.py b/server/core/paths.py
index 46b76fbd..01f7a14b 100644
--- a/server/core/paths.py
+++ b/server/core/paths.py
@@ -33,14 +33,20 @@ DATA_DIR resolution rules (see :func:`machina_root`):
- Relative path → resolved under the repo root (back-compat for
callers who set ``DATA_DIR=data`` to keep the pre-cutover layout).
-Auto-migration of existing ``<repo>/data/`` and ``<repo>/workflows/``
-trees happens in :func:`migrate_legacy_layout` — see
-``server/main.py``'s startup event.
+Migration of pre-cutover ``<repo>/data/`` + ``<repo>/workflows/``
+trees is the operator's responsibility — set ``DATA_DIR`` to the
+legacy path (e.g. ``DATA_DIR=data``) to keep using the old layout,
+or move the contents manually:
+
+ mv server/data/claude-machina ~/.machina/claude
+ mv server/data/workspaces ~/.machina/workspaces
+ mv server/data/workflow.db ~/.machina/workflow.db
+ mv server/data/credentials.db ~/.machina/credentials.db
+ mv workflows ~/.machina/workflows
"""
from __future__ import annotations
-import shutil
from pathlib import Path
from core.logging import get_logger
@@ -140,196 +146,6 @@ def credentials_db_path() -> Path:
return machina_root() / "credentials.db"
-# ---------------------------------------------------------------------------
-# One-time auto-migration on app startup
-# ---------------------------------------------------------------------------
-
-# Map of legacy on-disk locations → new locations under ``.machina/``.
-# Each entry is renamed exactly once: only when the source exists and
-# the destination does not. Subsequent boots are no-ops.
-_LEGACY_RENAMES: list[tuple[Path, Path]] = []
-
-
-def _legacy_renames() -> list[tuple[Path, Path]]:
- """Build the rename plan from current settings (lazy — needs Settings).
-
- Sources are always under the repo root (where the pre-cutover code
- wrote them); destinations are under whatever ``machina_root()``
- currently resolves to (``~/.machina/`` by default). Renames may
- cross filesystems on multi-disk setups — :func:`migrate_legacy_layout`
- falls back to ``shutil.move`` (copy + delete) when ``Path.rename``
- fails with ``OSError``.
- """
- root = machina_root()
- src_root = project_root()
- return [
- # 1. workflows/ → ~/.machina/workflows/
- (src_root / "workflows", root / "workflows"),
- # 2. data/ → ~/.machina/ (handled below by per-subdir moves
- # to keep the flat layout; the bare-rename of ``data/`` itself
- # would re-introduce the nested structure)
- # 2a. data/claude-machina/ → ~/.machina/claude/
- (src_root / "data" / "claude-machina", root / "claude"),
- # 2b. data/workspaces/ → ~/.machina/workspaces/
- (src_root / "data" / "workspaces", root / "workspaces"),
- # 2c. data/whatsapp/ → ~/.machina/whatsapp/
- (src_root / "data" / "whatsapp", root / "whatsapp"),
- # 2d. data/credentials.db → ~/.machina/credentials.db
- (src_root / "data" / "credentials.db", root / "credentials.db"),
- # 2e. data/machina.db → ~/.machina/machina.db
- (src_root / "data" / "machina.db", root / "machina.db"),
- ]
-
-
-def _merge_into_destination(src: Path, dst: Path, log_label: str) -> int:
- """Recursively move ``src`` contents into ``dst`` skipping conflicts.
-
- Three cases:
-
- 1. **``dst`` doesn't exist** — atomic ``rename`` (with ``shutil.move``
- fallback for cross-fs). Returns ``1``.
- 2. **Both exist as files** — log WARNING and skip (the operator
- picks which to keep). Returns ``0``.
- 3. **Both exist as dirs** — recurse into ``src``'s children;
- any child that doesn't exist in ``dst`` gets moved. Empty
- ``src`` afterwards is ``rmdir``'d. Returns the count of
- child items successfully moved.
-
- This solves the real-user breakage where ``~/.machina/claude/``
- might already exist with a stale ``npm/`` subdir (from a smoke
- test or partial install) while the actual auth + session JSONLs
- still live in ``<repo>/data/claude-machina/``. The plain
- ``rename`` would skip; recursive merge moves the real data
- into the new location item-by-item.
- """
- if not src.exists():
- return 0
-
- if not dst.exists():
- try:
- dst.parent.mkdir(parents=True, exist_ok=True)
- try:
- src.rename(dst)
- except OSError:
- shutil.move(str(src), str(dst))
- logger.info("[%s] moved %s -> %s", log_label, src, dst)
- return 1
- except Exception as exc:
- logger.warning(
- "[%s] failed move %s -> %s: %s", log_label, src, dst, exc,
- )
- return 0
-
- # Destination exists.
- if src.is_file() or dst.is_file():
- logger.warning(
- "[%s] conflict %s vs %s — both exist; manual merge required",
- log_label, src, dst,
- )
- return 0
-
- # Both are dirs — recurse into src.
- merged = 0
- try:
- children = list(src.iterdir())
- except OSError as exc:
- logger.warning(
- "[%s] cannot list %s: %s — skipping merge", log_label, src, exc,
- )
- return 0
- for item in children:
- merged += _merge_into_destination(item, dst / item.name, log_label)
-
- # Try removing src if empty now (all children either moved or
- # conflicting). Leave in place otherwise so the operator can see
- # what wasn't migrated.
- try:
- src.rmdir()
- except OSError:
- # Not empty — leave it. The earlier WARNINGs identify what
- # held it back.
- pass
- return merged
-
-
-def migrate_legacy_layout() -> int:
- """Migrate pre-cutover ``<repo>/data/`` + ``<repo>/workflows/`` into
- the new ``machina_root()`` layout.
-
- Called once on app startup from ``main.py``. Idempotent: a marker
- file at ``<machina_root>/.migrated`` short-circuits subsequent
- calls. Returns the count of items moved.
-
- Recursive merge semantics (see :func:`_merge_into_destination`):
- when both source and destination exist as directories, walks into
- src and moves any child that doesn't conflict with dst. Files in
- both locations are flagged at WARNING and left for manual
- resolution. This handles the real-user case where the destination
- has been partially populated by a smoke-test / earlier upgrade
- attempt — the actual user data still in ``data/claude-machina/``
- gets moved into ``~/.machina/claude/`` item-by-item instead of
- silently skipped.
- """
- root = machina_root()
- try:
- root.mkdir(parents=True, exist_ok=True)
- except OSError as exc:
- logger.warning(
- "[paths] cannot create machina root %s: %s — skipping migration",
- root, exc,
- )
- return 0
-
- stamp = root / ".migrated"
- if stamp.exists():
- logger.debug(
- "[paths] migration already ran (stamp %s present); skipping",
- stamp,
- )
- return 0
-
- moved = 0
- for src, dst in _legacy_renames():
- moved += _merge_into_destination(src, dst, log_label="paths")
-
- # If ``data/`` is empty after per-subdir merges, remove it so the
- # user's tree is clean. Don't force-remove if anything's still
- # in there (could be user-authored content).
- legacy_data = project_root() / "data"
- if legacy_data.is_dir():
- try:
- legacy_data.rmdir() # only succeeds if empty
- logger.info("[paths] removed empty legacy data/ dir")
- except OSError:
- # Not empty — leave it alone.
- pass
-
- # Write the stamp regardless of whether anything moved. On a
- # fresh install with no legacy layout, this still prevents future
- # boots from re-walking the empty source dirs.
- try:
- stamp.write_text(
- "MachinaOs migrated this directory from the pre-cutover "
- "<repo>/data/ + <repo>/workflows/ layout. Delete this file "
- "to force migration to re-run on next startup.\n",
- encoding="utf-8",
- )
- except OSError as exc:
- logger.debug("[paths] could not write migration stamp: %s", exc)
-
- if moved:
- logger.info(
- "[paths] migration complete: %d items moved into %s",
- moved, root,
- )
- else:
- logger.debug(
- "[paths] migration complete: nothing to migrate (fresh install "
- "or already-migrated state)",
- )
- return moved
-
-
__all__ = [
"project_root",
"machina_root",
@@ -340,5 +156,4 @@ __all__ = [
"workflows_dir",
"whatsapp_dir",
"credentials_db_path",
- "migrate_legacy_layout",
]
diff --git a/server/main.py b/server/main.py
index 9e96e828..f8c67974 100644
--- a/server/main.py
+++ b/server/main.py
@@ -506,20 +506,6 @@ except Exception as exc: # pragma: no cover — defensive; MCP must not block s
logger.warning("[main] failed to mount CLI agent MCP server: %s", exc)
-# One-time on-disk layout migration: rename pre-cutover ``data/`` +
-# ``workflows/`` trees into the flat ``.machina/`` root. Idempotent;
-# no-op on subsequent boots. Must run BEFORE any lockfile sweep or
-# CLI service init so those consumers see the new paths. See
-# ``server/core/paths.py::migrate_legacy_layout``.
[email protected]_event("startup")
-async def _migrate_legacy_layout_on_startup() -> None:
- try:
- from core.paths import migrate_legacy_layout
- migrate_legacy_layout()
- except Exception as exc: # pragma: no cover — defensive
- logger.warning("[main] legacy-layout migration failed: %s", exc)
-
-
# Stale lockfile sweep on startup — mirrors VSCode's behavior. PIDs in
# leftover lockfiles that are no longer alive get cleaned up.
@app.on_event("startup")
diff --git a/server/tests/conftest.py b/server/tests/conftest.py
index 447ed34f..67737ded 100644
--- a/server/tests/conftest.py
+++ b/server/tests/conftest.py
@@ -110,7 +110,6 @@ _make_submodule("core", "paths", {
"workflows_dir": lambda: _TEST_MACHINA_ROOT / "workflows",
"whatsapp_dir": lambda: _TEST_MACHINA_ROOT / "whatsapp",
"credentials_db_path": lambda: _TEST_MACHINA_ROOT / "credentials.db",
- "migrate_legacy_layout": lambda: 0,
})