The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): board identity requires board.json; archive leaves a tombstone
Austin Pickett63e565640960
diff --git a/hermes_cli/kanban_boards.py b/hermes_cli/kanban_boards.pyindex 0c6db1801fe..ab5a1426ee0 100644--- a/hermes_cli/kanban_boards.py+++ b/hermes_cli/kanban_boards.py@@ -102,7 +102,8 @@ def _cmd_boards_rm(args: argparse.Namespace) -> int:return _err(f"kanban boards rm: {exc}")if res["action"] == "archived":print(f"Board {res['slug']!r} archived → {res['new_path']}\n"- "Recover by moving the directory back to <root>/kanban/boards/<slug>/.")+ "Recover by moving the directory back to <root>/kanban/boards/<slug>/ "+ "and deleting the archived tombstone board.json left in its place.")else:print(f"Board {res['slug']!r} deleted.")return 0@@ -117,6 +118,10 @@ def _cmd_boards_switch(args: argparse.Namespace) -> int:f"kanban boards switch: board {normed!r} does not exist. "f"Create it with `hermes kanban boards create {normed}`.")+ # An archived board has a tombstone board.json; switching to it would pin+ # `current` at a dead slug (#43243).+ if kb.read_board_metadata(normed).get("archived"):+ return _err(f"kanban boards switch: board {normed!r} is archived.")kb.set_current_board(normed)print(f"Active board is now {normed!r}.")return 0diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.pyindex 8992fc39807..623e25e2341 100644--- a/hermes_cli/kanban_db.py+++ b/hermes_cli/kanban_db.py@@ -458,7 +458,14 @@ def get_current_board() -> str:normed = _normalize_board_slug(candidate)except ValueError:return None- return normed if normed and board_exists(normed) else None+ if not (normed and board_exists(normed)):+ return None+ # An archived board leaves a tombstone board.json; a stale `current`+ # file or HERMES_KANBAN_BOARD pointing at one falls through to+ # default rather than resurrecting it (#43243).+ if read_board_metadata(normed).get("archived"):+ return None+ return normedfor candidate in ((_CURRENT_BOARD_OVERRIDE.get() or "").strip(),@@ -511,7 +518,7 @@ def board_dir(board: Optional[str] = None) -> Path:def board_exists(board: Optional[str] = None) -> bool:- """Board has ``board.json`` or ``kanban.db`` on disk; ``default`` always exists."""+ """Board has a ``board.json`` on disk; ``default`` always exists."""slug = _slug_or_default(board)if slug == DEFAULT_BOARD:return True@@ -519,7 +526,12 @@ def board_exists(board: Optional[str] = None) -> bool:def _dir_holds_board(d: Path) -> bool:- return (d / "board.json").exists() or (d / "kanban.db").exists()+ # ``board.json`` is the identity marker: archive/hard-delete both leave the+ # directory without it, and a stale ``connect(board=slug)`` used to leave a+ # ``kanban.db``-only stub that resurfaced in the board list as an empty+ # active board (#43243). Discovery must therefore require the metadata+ # file; a DB-only directory is a stub to ignore, never a board.+ return (d / "board.json").exists()def _explicit_board_slug(board: Optional[str]) -> Optional[str]:@@ -693,9 +705,12 @@ def create_board() -> dict:"""Create board dir + DB + metadata (``mkdir -p`` semantics: existing board returns its metadata)."""normed = _require_slug(slug)+ # Explicit creation clears any archived tombstone at this slug (left by+ # remove_board(archive=True)) — otherwise init_db() below would rightly+ # refuse to recreate the archived board's DB (#43243).meta = write_board_metadata(normed, name=name, description=description, icon=icon, color=color,- default_workdir=default_workdir, project_id=project_id,+ default_workdir=default_workdir, project_id=project_id, archived=False,)# Touch the DB so list_boards() sees it immediately.init_db(board=normed)@@ -746,6 +761,9 @@ def remove_board(slug: str, *, archive: bool = True) -> dict:_INITIALIZED_PATHS.discard(str((d / "kanban.db").resolve()))if archive:+ # Capture display metadata before the move so the tombstone below keeps+ # the user's board name instead of falling back to a title-cased slug.+ prior_meta = read_board_metadata(normed)archive_root = boards_root() / "_archived"archive_root.mkdir(parents=True, exist_ok=True)ts = int(time.time())@@ -755,6 +773,20 @@ def remove_board(slug: str, *, archive: bool = True) -> dict:target = archive_root / f"{normed}-{ts}-{suffix}"suffix += 1d.rename(target)+ # Leave an ``archived`` tombstone at the original slug. Stale dashboard+ # tabs / gateway pollers can keep calling connect(board=slug) after the+ # archive; without a marker the resurrect-guard cannot tell an archived+ # slug from a brand-new one and an empty board would reappear (#43243).+ write_board_metadata(+ normed,+ name=prior_meta.get("name"),+ description=prior_meta.get("description"),+ icon=prior_meta.get("icon"),+ color=prior_meta.get("color"),+ default_workdir=prior_meta.get("default_workdir"),+ project_id=prior_meta.get("project_id"),+ archived=True,+ )return {"slug": normed, "action": "archived", "new_path": str(target)}import shutilshutil.rmtree(d)diff --git a/tests/hermes_cli/test_kanban_boards.py b/tests/hermes_cli/test_kanban_boards.pyindex d2888fa45e0..613d4f6a2c6 100644--- a/tests/hermes_cli/test_kanban_boards.py+++ b/tests/hermes_cli/test_kanban_boards.py@@ -185,11 +185,12 @@ class TestBoardCRUD:@pytest.mark.parametrize("archive", [True, False])def test_remove_clears_init_cache_for_recreated_db(self, fresh_home, archive):- # Regression for #23833: poll loops that call connect(board=slug) right- # after remove_board() recreate an empty kanban.db at the same path- # (connect() does mkdir(exist_ok=True)). If _INITIALIZED_PATHS still- # contains the resolved path, the CREATE TABLE pass is skipped and- # downstream readers hit `no such table: task_events`.+ # Regression for #23833: a poll loop that re-creates a just-removed+ # board must get a fresh schema-init pass — if _INITIALIZED_PATHS+ # still contained the resolved path, the CREATE TABLE pass would be+ # skipped and downstream readers hit `no such table: task_events`.+ # (Since #43243 connect() itself refuses to recreate a removed board,+ # so the re-creation goes through create_board, as it should.)kb.create_board("recycle")# First connect populates _INITIALIZED_PATHS for this DB. Use# connect_closing: `with connect() as conn` does NOT close the fd, and@@ -205,8 +206,9 @@ class TestBoardCRUD:# connect() gets a fresh schema-init pass.assert str(db_path.resolve()) not in kb._INITIALIZED_PATHS- # Simulate the event-stream poll: re-open the same slug. connect()- # recreates the directory + empty .db; the schema must be re-applied.+ # Simulate the board being re-created at the same slug: the schema+ # must be re-applied on the fresh DB file.+ kb.create_board("recycle")with kbc.connect_closing(board="recycle") as conn:tables = {row[0]@@ -372,3 +374,58 @@ class TestCLI:+++# ---------------------------------------------------------------------------+# Archived / deleted board resurrection (#43243)+# ---------------------------------------------------------------------------++class TestBoardResurrection:+ """Read/watch paths must not resurrect archived or deleted boards.++ Stale dashboard tabs, gateway notifiers and event-stream pollers can hand+ ``connect(board=<slug>)`` a slug whose board was archived (moved to+ ``_archived/`` with an ``archived`` tombstone) or hard-deleted+ (``rmtree``). ``connect`` must refuse to recreate the directory/DB, and+ ``list_boards`` must not surface a DB-only stub as an active board.+ """++ def test_connect_does_not_recreate_archived_board(self, fresh_home):+ kb.create_board("gone")+ kb.remove_board("gone", archive=True)+ tombstone = kb.board_metadata_path("gone")+ assert tombstone.exists() and kb.read_board_metadata("gone")["archived"] is True+ with pytest.raises(ValueError, match="archived"):+ kbc.connect(board="gone")+ assert not (kb.board_dir("gone") / "kanban.db").exists()++ def test_connect_does_not_recreate_deleted_board(self, fresh_home):+ kb.create_board("nuked")+ kb.remove_board("nuked", archive=False)+ assert not kb.board_dir("nuked").exists()+ with pytest.raises(ValueError, match="does not exist"):+ kbc.connect(board="nuked")+ assert not kb.board_dir("nuked").exists()++ def test_connect_still_opens_live_board(self, fresh_home):+ kb.create_board("live")+ with kbc.connect_closing(board="live") as conn:+ conn.execute("SELECT 1").fetchone()+ assert kb.board_exists("live")++ def test_list_boards_ignores_db_only_stub(self, fresh_home):+ # Simulate the historical stub shape: kanban.db with no board.json.+ stub = kb.board_dir("ghost")+ stub.mkdir(parents=True)+ (stub / "kanban.db").touch()+ assert "ghost" not in [b["slug"] for b in kb.list_boards()]+ assert "ghost" not in [b["slug"] for b in kb.list_boards(include_archived=True)]++ def test_archive_tombstone_keeps_name(self, fresh_home):+ kb.create_board("keepname", name="My Board")+ kb.remove_board("keepname", archive=True)+ meta = kb.read_board_metadata("keepname")+ assert meta["archived"] is True+ assert meta["name"] == "My Board"+ assert "keepname" in [b["slug"] for b in kb.list_boards(include_archived=True)]+ assert "keepname" not in [b["slug"] for b in kb.list_boards(include_archived=False)]diff --git a/tests/hermes_cli/test_kanban_core_functionality.py b/tests/hermes_cli/test_kanban_core_functionality.pyindex c82d6ff4531..4fd7c0db0c5 100644--- a/tests/hermes_cli/test_kanban_core_functionality.py+++ b/tests/hermes_cli/test_kanban_core_functionality.py@@ -1374,6 +1374,7 @@ def test_dead_worker_reap_reads_the_log_of_the_dispatching_board(kanban_home):from hermes_cli import kanban_db_dispatch as kbdassert kb.get_current_board() == "default"board = "other-board"+ kb.create_board(board) # explicit creation; connect() must not create boards (#43243)conn = kbc.connect(board=board)try:tid = kb.create_task(conn, title="handoff", assignee="worker")diff --git a/tests/plugins/test_kanban_board_lifecycle_api.py b/tests/plugins/test_kanban_board_lifecycle_api.pyindex 172e4849fb1..f1072f08ca8 100644--- a/tests/plugins/test_kanban_board_lifecycle_api.py+++ b/tests/plugins/test_kanban_board_lifecycle_api.py@@ -67,7 +67,10 @@ def test_delete_board_archives_and_reverts_current(client):archived = Path(body["result"]["new_path"])assert archived.is_dir()assert (archived / "kanban.db").exists()- assert not kb.board_dir("widget").exists()+ # The original slug keeps only an archived tombstone (no DB) — a stale+ # dashboard tab must not resurrect an empty board there (#43243).+ assert not (kb.board_dir("widget") / "kanban.db").exists()+ assert kb.read_board_metadata("widget")["archived"] is Trueassert all(b["slug"] != "widget" for b in client.get("/api/plugins/kanban/boards").json()["boards"])