refactor(freezer): drop Bottle from commit signature

Freezer._freeze only ever used bottle.name, which is always
f"bot-bottle-{agent.slug}". Remove the Bottle parameter from
commit() and _freeze(), derive the container name from agent.slug
directly in each subclass, and delete the _NamedBottle stub that
existed solely to paper over this.
This commit is contained in:
2026-06-23 07:46:38 +00:00
committed by didericis
parent 311cd46185
commit cb321f7ad4
6 changed files with 44 additions and 83 deletions
+3 -3
View File
@@ -526,9 +526,9 @@ from .docker import DockerBottleBackend # noqa: E402 # pylint: disable=wrong-i
from .macos_container import MacosContainerBottleBackend # noqa: E402 # pylint: disable=wrong-import-position
from .smolmachines import SmolmachinesBottleBackend # noqa: E402 # pylint: disable=wrong-import-position
# Freezer is imported after the backend classes for the same reason
# Freezer.commit_slug constructs ActiveAgent, so the dataclass must be
# fully defined first.
# Freezer is imported after the backend classes for the same reason:
# Freezer.commit_slug constructs ActiveAgent, which must be fully
# defined first.
from .freeze import CommitCancelled, Freezer, get_freezer # noqa: E402 # pylint: disable=wrong-import-position
+4 -3
View File
@@ -2,7 +2,7 @@
from __future__ import annotations
from .. import ActiveAgent, Bottle
from .. import ActiveAgent
from ..freeze import Freezer
from .util import commit_container
from ...log import info
@@ -13,9 +13,10 @@ class DockerFreezer(Freezer):
backend_name = "docker"
def _freeze(self, agent: ActiveAgent, bottle: Bottle) -> str:
def _freeze(self, agent: ActiveAgent) -> str:
container = f"bot-bottle-{agent.slug}"
image_tag = f"bot-bottle-committed-{agent.slug}:latest"
commit_container(bottle.name, image_tag)
commit_container(container, image_tag)
return image_tag
def _export_hint(self, slug: str, image_ref: str) -> None:
+10 -41
View File
@@ -6,16 +6,16 @@ print resume hint) and backend-specific subclasses in their respective
backend directories.
Entry points:
Freezer.commit(agent, bottle) — for use within a live launch context
Freezer.commit_slug(slug) — for cmd_commit when no live Bottle exists
get_freezer(backend_name) — factory
Freezer.commit(agent) — freeze by ActiveAgent
Freezer.commit_slug(slug) — convenience wrapper for cmd_commit
get_freezer(backend_name) — factory
"""
from __future__ import annotations
from abc import ABC, abstractmethod
from . import ActiveAgent, Bottle, ExecResult
from . import ActiveAgent
from ..bottle_state import mark_preserved, write_committed_image
from ..log import die, info
@@ -38,8 +38,8 @@ class Freezer(ABC):
backend_name: str
def commit(self, agent: ActiveAgent, bottle: Bottle) -> None:
"""Freeze `bottle` to a resumable artifact.
def commit(self, agent: ActiveAgent) -> None:
"""Freeze the bottle for `agent` to a resumable artifact.
Calls _freeze for the backend-specific snapshot, then writes the
committed image reference to per-bottle state and marks the bottle
@@ -48,14 +48,14 @@ class Freezer(ABC):
Raises CommitCancelled if the user declines an interactive
confirmation prompt (e.g. the macos-container stop prompt).
"""
image_ref = self._freeze(agent, bottle)
image_ref = self._freeze(agent)
write_committed_image(agent.slug, image_ref)
mark_preserved(agent.slug)
info(f"to resume from this snapshot: ./cli.py resume {agent.slug}")
self._export_hint(agent.slug, image_ref)
@abstractmethod
def _freeze(self, agent: ActiveAgent, bottle: Bottle) -> str:
def _freeze(self, agent: ActiveAgent) -> str:
"""Backend-specific snapshot. Returns the image tag or artifact path
stored by write_committed_image. Raises CommitCancelled if the user
declines a stop-confirmation prompt."""
@@ -65,11 +65,7 @@ class Freezer(ABC):
Overridden by backends that provide a meaningful export command."""
def commit_slug(self, slug: str) -> None:
"""Convenience entry for cmd_commit when no live Bottle is available.
Constructs a minimal ActiveAgent from per-bottle state and a
name-only Bottle stub, then delegates to commit(). Freezer
subclasses must not call exec / exec_agent / cp_in on the stub."""
"""Convenience entry for cmd_commit when only a slug is available."""
from ..bottle_state import read_metadata
metadata = read_metadata(slug)
agent = ActiveAgent(
@@ -79,34 +75,7 @@ class Freezer(ABC):
started_at=metadata.started_at if metadata else "",
services=(),
)
bottle: Bottle = _NamedBottle(f"bot-bottle-{slug}")
self.commit(agent, bottle)
class _NamedBottle(Bottle):
"""Name-only Bottle stub for Freezer.commit_slug.
Only `name` is meaningful. All runtime operations raise
NotImplementedError — Freezer._freeze implementations must only
access bottle.name."""
def __init__(self, name: str) -> None:
self.name = name
def agent_argv(self, argv: list[str], *, tty: bool = True) -> list[str]:
raise NotImplementedError
def exec_agent(self, argv: list[str], *, tty: bool = True) -> int:
raise NotImplementedError
def exec(self, script: str, *, user: str = "node") -> ExecResult:
raise NotImplementedError
def cp_in(self, host_path: str, container_path: str) -> None:
raise NotImplementedError
def close(self) -> None:
pass
self.commit(agent)
def get_freezer(backend_name: str) -> Freezer:
@@ -8,7 +8,7 @@ from __future__ import annotations
import sys
from .. import ActiveAgent, Bottle
from .. import ActiveAgent
from ..freeze import CommitCancelled, Freezer
from .util import commit_container, container_is_running, stop_container
from ...log import info
@@ -19,9 +19,10 @@ class MacosContainerFreezer(Freezer):
backend_name = "macos-container"
def _freeze(self, agent: ActiveAgent, bottle: Bottle) -> str:
def _freeze(self, agent: ActiveAgent) -> str:
container = f"bot-bottle-{agent.slug}"
image_tag = f"bot-bottle-committed-{agent.slug}:latest"
if container_is_running(bottle.name):
if container_is_running(container):
sys.stderr.write(
f"bot-bottle: bottle {agent.slug!r} is running; "
"commit will stop it. Continue? [y/N] "
@@ -30,8 +31,8 @@ class MacosContainerFreezer(Freezer):
reply = _read_tty_line().strip().lower()
if reply not in ("y", "yes"):
raise CommitCancelled
stop_container(bottle.name)
commit_container(bottle.name, image_tag)
stop_container(container)
commit_container(container, image_tag)
return image_tag
def _export_hint(self, slug: str, image_ref: str) -> None:
+4 -3
View File
@@ -2,7 +2,7 @@
from __future__ import annotations
from .. import ActiveAgent, Bottle
from .. import ActiveAgent
from ..freeze import Freezer
from .smolvm import pack_create_from_vm
from ...bottle_state import bottle_state_dir
@@ -14,10 +14,11 @@ class SmolmachinesFreezer(Freezer):
backend_name = "smolmachines"
def _freeze(self, agent: ActiveAgent, bottle: Bottle) -> str:
def _freeze(self, agent: ActiveAgent) -> str:
machine = f"bot-bottle-{agent.slug}"
output = bottle_state_dir(agent.slug) / "committed-smolmachine"
output.parent.mkdir(parents=True, exist_ok=True)
pack_create_from_vm(bottle.name, output)
pack_create_from_vm(machine, output)
artifact = output.with_name(f"{output.name}.smolmachine")
return str(artifact)