Skip to content

clone

clone

Conductor clone support — isolated conductor instances for safe testing.

When --conductor-clone is passed to any Marianne CLI command, all daemon interactions are routed to a clone conductor instead of the production one. The clone owns its IPC and stdio MCP sockets, PID file, state DB, profiler files, and log file.

This enables safe testing of Marianne CLI commands and daemon features without risking the production conductor. The production conductor continues running undisturbed.

Usage

mzt start --conductor-clone # Start default clone mzt start --conductor-clone=staging # Start named clone mzt run score.yaml --conductor-clone # Submit to default clone mzt status --conductor-clone=staging # Query named clone

Architecture
  • A module-level _clone_name stores the active clone (set by CLI callback)
  • _resolve_socket_path() in detect.py checks get_clone_name() before falling back to SocketConfig defaults
  • resolve_clone_paths() computes all isolated paths from a clone name
  • build_clone_config() produces a DaemonConfig with clone-specific paths

Attributes

Classes

ClonePaths dataclass

ClonePaths(socket, pid_file, state_db, log_file)

Isolated paths for a conductor clone instance.

Attributes
log_root property
log_root

Directory that owns this clone's logs.

log_name property
log_name

Primary event log file name for this clone.

Functions:

set_clone_name

set_clone_name(name)

Set the active clone name. Called by CLI --conductor-clone callback.

Also establishes tmux-socket isolation: the conductor's startup orphan sweep kills every mzt-* session on its tmux socket on the premise that nothing else owns them — true for a lone conductor, FALSE when a clone starts beside production. A clone therefore gets its own tmux socket (exported via the env var every TmuxControl honors; fork-based daemonization inherits it). An explicit pre-existing override wins.

Source code in src/marianne/daemon/clone.py
def set_clone_name(name: str | None) -> None:
    """Set the active clone name. Called by CLI --conductor-clone callback.

    Also establishes tmux-socket isolation: the conductor's startup orphan
    sweep kills every ``mzt-*`` session on its tmux socket on the premise
    that nothing else owns them — true for a lone conductor, FALSE when a
    clone starts beside production. A clone therefore gets its own tmux
    socket (exported via the env var every TmuxControl honors; fork-based
    daemonization inherits it). An explicit pre-existing override wins.
    """
    global _clone_name, _clone_tmux_socket_exported
    _clone_name = name

    import os

    from marianne.execution.instruments.interactive.tmux import SOCKET_ENV_VAR

    if name is not None:
        if SOCKET_ENV_VAR not in os.environ:
            suffix = _sanitize_name(name) or "default"
            os.environ[SOCKET_ENV_VAR] = f"mzt-clone-{suffix}"
            _clone_tmux_socket_exported = True
    elif _clone_tmux_socket_exported:
        os.environ.pop(SOCKET_ENV_VAR, None)
        _clone_tmux_socket_exported = False

get_clone_name

get_clone_name()

Get the active clone name. None = production mode.

Source code in src/marianne/daemon/clone.py
def get_clone_name() -> str | None:
    """Get the active clone name. None = production mode."""
    return _clone_name

is_clone_active

is_clone_active()

Check if a clone is currently active.

Source code in src/marianne/daemon/clone.py
def is_clone_active() -> bool:
    """Check if a clone is currently active."""
    return _clone_name is not None

resolve_clone_paths

resolve_clone_paths(name)

Compute isolated paths for a clone instance.

Parameters:

Name Type Description Default
name str | None

Clone name (None or empty for default clone, string for named clone).

required

Returns:

Type Description
ClonePaths

ClonePaths with socket, PID, state DB, and log paths.

ClonePaths

Runtime artifacts (socket/PID/log) live in ~/.config/mzt (#227,

ClonePaths

matching the production convention); state DB in ~/.marianne.

Source code in src/marianne/daemon/clone.py
def resolve_clone_paths(name: str | None) -> ClonePaths:
    """Compute isolated paths for a clone instance.

    Args:
        name: Clone name (None or empty for default clone, string for named clone).

    Returns:
        ClonePaths with socket, PID, state DB, and log paths.
        Runtime artifacts (socket/PID/log) live in ~/.config/mzt (#227,
        matching the production convention); state DB in ~/.marianne.
    """
    suffix = _sanitize_name(name)
    tag = f"-{suffix}" if suffix else ""

    from marianne.daemon.config import mzt_runtime_dir

    runtime_dir = mzt_runtime_dir()
    marianne_dir = Path.home() / ".marianne"

    return ClonePaths(
        socket=runtime_dir / f"clone{tag}.sock",
        pid_file=runtime_dir / f"clone{tag}.pid",
        state_db=marianne_dir / f"clone{tag}-state.db",
        log_file=runtime_dir / f"clone{tag}.log",
    )

build_clone_config

build_clone_config(name, *, base_config=None)

Build a DaemonConfig with clone-specific paths.

Inherits all non-path settings from base_config (or defaults). Overrides owned runtime, state, and profiler paths with clone-specific values. Configured stdio MCP sockets move into a conductor-specific directory; external transports retain their configured endpoints.

Parameters:

Name Type Description Default
name str | None

Clone name (None for default clone).

required
base_config DaemonConfig | None

Production DaemonConfig to inherit from.

None

Returns:

Type Description
DaemonConfig

A DaemonConfig with isolated clone paths.

Source code in src/marianne/daemon/clone.py
def build_clone_config(
    name: str | None,
    *,
    base_config: DaemonConfig | None = None,
) -> DaemonConfig:
    """Build a DaemonConfig with clone-specific paths.

    Inherits all non-path settings from base_config (or defaults).
    Overrides owned runtime, state, and profiler paths with clone-specific values.
    Configured stdio MCP sockets move into a conductor-specific directory;
    external transports retain their configured endpoints.

    Args:
        name: Clone name (None for default clone).
        base_config: Production DaemonConfig to inherit from.

    Returns:
        A DaemonConfig with isolated clone paths.
    """
    # Deferred import to avoid circular dependency
    import hashlib

    from marianne.daemon.config import DaemonConfig

    paths = resolve_clone_paths(name)
    config_dict = (base_config or DaemonConfig()).model_dump()
    config_dict["socket"]["path"] = paths.socket
    config_dict["pid_file"] = paths.pid_file
    config_dict["state_db_path"] = paths.state_db
    # A clone's state DB sits in the shared ~/.marianne, so "beside the DB"
    # would still be the shared snapshots dir; give the clone its own (GH #432).
    config_dict["snapshot_dir"] = paths.state_db.with_name(paths.state_db.stem + "-snapshots")
    config_dict["logging"] = {
        **config_dict["logging"],
        "root": paths.log_root,
        "event_log_name": paths.log_name,
    }
    config_dict["log_file"] = paths.log_file
    config_dict["profiler"] = {
        **config_dict["profiler"],
        "storage_path": paths.state_db.with_name(paths.state_db.stem + "-monitor.db"),
        "jsonl_path": paths.state_db.with_name(paths.state_db.stem + "-monitor.jsonl"),
    }
    conductor_component = hashlib.sha256(paths.socket.stem.encode()).hexdigest()[:16]
    mcp_dir = paths.socket.parent / f"clone-mcp-{conductor_component}"
    for server_name, entry in config_dict["mcp_pool"]["servers"].items():
        if entry["transport"] == "stdio":
            # Names are untrusted dictionary keys. A fixed hash component keeps
            # sockets inside their conductor directory without lossy sanitizing.
            component = hashlib.sha256(server_name.encode()).hexdigest()[:16]
            entry["socket"] = str(mcp_dir / f"{component}.sock")
    return DaemonConfig.model_validate(config_dict)

active_registry_db_path

active_registry_db_path()

The registry DB of the conductor the CLI is currently addressing.

Production DAEMON_STATE_DB_PATH unless --conductor-clone selected a clone, in which case the clone's own state DB (GH #401). Every offline registry reader (recover, diagnose, status fallbacks, dashboard stream) must go through this instead of the constant. Lives on the daemon side because it depends on clone selection; core/ never imports daemon/ (GH #414).

Source code in src/marianne/daemon/clone.py
def active_registry_db_path() -> Path:
    """The registry DB of the conductor the CLI is currently addressing.

    Production ``DAEMON_STATE_DB_PATH`` unless ``--conductor-clone`` selected
    a clone, in which case the clone's own state DB (GH #401). Every offline
    registry reader (recover, diagnose, status fallbacks, dashboard stream)
    must go through this instead of the constant. Lives on the daemon side
    because it depends on clone selection; ``core/`` never imports ``daemon/``
    (GH #414).
    """
    if is_clone_active():
        return resolve_clone_paths(get_clone_name()).state_db.expanduser()
    return DAEMON_STATE_DB_PATH.expanduser()