From 2c85c9b831de24f04f96f4ac5fbc836b73b20249 Mon Sep 17 00:00:00 2001 From: Jordan Isaacs Date: Thu, 23 Apr 2026 00:09:50 +0000 Subject: [PATCH] Classify stacker-ops slots as OPS_OWNED Add Kind.OPS_OWNED to check.py: when a slot's .owner symlink points at paths.stacker_ops_marker, emit OPS_OWNED (ephemeral ownership by a stacker operation) instead of ORPHAN_OWNER. OPS_OWNED slots are intentional and not fixed by check --fix; pm pool gc-ops handles the garbage collection path for that ownership kind. pool ls reports such slots as "OPS" in the status column instead of ".stacker" (which the previous owner.parent.name logic would produce). project/ls gets the new label mapping for completeness, though project scope won't surface OPS_OWNED in practice. --- src/project_manager/check.py | 20 ++++++++++++++++++++ src/project_manager/pool/ls.py | 19 ++++++++++++++++--- src/project_manager/project/ls.py | 1 + 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/project_manager/check.py b/src/project_manager/check.py index fc7a53b..c814d93 100644 --- a/src/project_manager/check.py +++ b/src/project_manager/check.py @@ -17,6 +17,7 @@ class Kind(StrEnum): BROKEN = "broken" # forward points at a missing slot ORPHAN_FORWARD = "orphan-forward" # forward exists, no db row ORPHAN_OWNER = "orphan-owner" # slot .owner points at a forward not claimed by db + OPS_OWNED = "ops-owned" # slot .owner -> stacker_ops_marker (ephemeral ownership) @dataclass(frozen=True) @@ -111,6 +112,7 @@ def _orphan_owners( if not paths.worktrees.is_dir(): return scope_dir = paths.project(scope) if scope is not None else None + ops_marker = paths.stacker_ops_marker() for repo_dir in sorted(paths.worktrees.iterdir()): if not repo_dir.is_dir(): continue @@ -118,6 +120,17 @@ def _orphan_owners( owner = s.owner_target() if owner is None: continue + if _is_ops_marker(owner, ops_marker): + if scope_dir is not None: + continue + yield Finding( + kind=Kind.OPS_OWNED, + repo=repo_dir.name, + slot_path=s.path, + forward_path=owner, + detail="slot held by a stacker ops operation", + ) + continue if scope_dir is not None and owner.parent != scope_dir: continue if (s.path, owner) in active_pairs: @@ -131,6 +144,13 @@ def _orphan_owners( ) +def _is_ops_marker(owner: Path, ops_marker: Path) -> bool: + try: + return owner.resolve() == ops_marker.resolve() + except OSError: + return False + + def _project_findings( paths: Paths, project: str, ) -> tuple[list[Finding], set[tuple[Path, Path]]]: diff --git a/src/project_manager/pool/ls.py b/src/project_manager/pool/ls.py index 030654c..1249b28 100644 --- a/src/project_manager/pool/ls.py +++ b/src/project_manager/pool/ls.py @@ -8,7 +8,7 @@ from project_manager.pool import slot as slot_mod class PoolRow: repo: str uuid: str - status: str # "FREE" or project name + status: str # "FREE", a project name, or "OPS" for stacker-ops slots def ls(paths: Paths, repo: str | None) -> list[PoolRow]: @@ -22,11 +22,24 @@ def ls(paths: Paths, repo: str | None) -> list[PoolRow]: entry.name for entry in paths.worktrees.iterdir() if entry.is_dir() ) + ops_marker = paths.stacker_ops_marker() rows: list[PoolRow] = [] for r in repos: for s in slot_mod.list_slots(paths, r): owner = s.owner_target() - # owner points at //; parent.name is the project - status = "FREE" if owner is None else owner.parent.name + if owner is None: + status = "FREE" + elif _is_ops_marker(owner, ops_marker): + status = "OPS" + else: + # owner points at //; parent.name is the project + status = owner.parent.name rows.append(PoolRow(repo=r, uuid=s.uuid, status=status)) return rows + + +def _is_ops_marker(owner, ops_marker) -> bool: # noqa: ANN001 + try: + return owner.resolve() == ops_marker.resolve() + except OSError: + return False diff --git a/src/project_manager/project/ls.py b/src/project_manager/project/ls.py index 3259ed0..fc9a66c 100644 --- a/src/project_manager/project/ls.py +++ b/src/project_manager/project/ls.py @@ -10,6 +10,7 @@ _KIND_TO_LABEL: dict[check_mod.Kind, str] = { check_mod.Kind.DRIFT: "drift", check_mod.Kind.STALE: "stale", check_mod.Kind.BROKEN: "broken", + check_mod.Kind.OPS_OWNED: "ops-owned", } -- knotmirror 0.0.1