Garbage collector¶
xcore_agent.agent.gc — prune stale rollback snapshots and cached artifact
downloads, and optionally force plugin restarts.
xcore_agent.agent.gc
¶
Garbage collection for xcore-agent's on-disk state.
Two things grow unbounded if nothing prunes them:
<project_root>/.snapshots/— everyinstall_pluginstep withsnapshot: true(see install_driver.py) leaves a copy of the previous plugin version behind, forever, unless something removes old ones.<cache_root>/<version>/— every version ever deployed leaves its downloaded/extracted workdir under the agent's cache root, forever.
GarbageCollector prunes both, and force_restart (used after a purge) is
how the agent makes sure a running plugin process actually drops any
in-memory state it was holding, rather than serving stale cached data
indefinitely after its on-disk snapshot was reclaimed.
GCReport
dataclass
¶
Source code in xcore_agent/agent/gc.py
snapshots_removed: list[Path] = field(default_factory=list)
class-attribute
instance-attribute
¶
cache_dirs_removed: list[Path] = field(default_factory=list)
class-attribute
instance-attribute
¶
plugins_restarted: list[str] = field(default_factory=list)
class-attribute
instance-attribute
¶
bytes_freed: int = 0
class-attribute
instance-attribute
¶
__init__(snapshots_removed: list[Path] = list(), cache_dirs_removed: list[Path] = list(), plugins_restarted: list[str] = list(), bytes_freed: int = 0) -> None
¶
GarbageCollector
¶
Source code in xcore_agent/agent/gc.py
layout = layout
instance-attribute
¶
keep_snapshots = keep_snapshots
instance-attribute
¶
cache_root = cache_root
instance-attribute
¶
__init__(layout: Layout, *, keep_snapshots: int = 3, cache_root: Path | None = None, supervisor: Supervisor | None = None) -> None
¶
Source code in xcore_agent/agent/gc.py
collect_snapshots() -> list[Path]
¶
Keep only the keep_snapshots most recent snapshots per plugin.
Snapshot directories are named <step_id>-<plugin_id>-<epoch_ms>
(see InstallDriver.snapshot_before); grouping by the plugin_id
segment and sorting by mtime finds each plugin's oldest snapshots.
Source code in xcore_agent/agent/gc.py
collect_cache(*, keep_versions: frozenset[str]) -> list[Path]
¶
Remove cached download/extraction workdirs for any version not in
keep_versions (normally: just the currently installed version).
Source code in xcore_agent/agent/gc.py
force_restart(plugin_ids: list[str]) -> list[str]
¶
Restart each plugin so a running process drops any in-memory
cache it was holding — a purged-on-disk snapshot alone doesn't do
that for a process that's still up. Requires a supervisor to have
been passed in; without one this is a no-op (nothing to restart).