From eedcebcc1280017451e2be6c1237a9a14e7de676 Mon Sep 17 00:00:00 2001 From: Godopu Date: Sun, 4 Oct 2026 10:34:27 +0000 Subject: [PATCH] fix(issue-45): restore stays off when python3 has no tomllib The shim runs a bare python3. Before 3.11 the module failed to import and the server started with restore on; now it gets the key alone, with a warning. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/lib_py/herdr_config.py | 9 ++++++++- tests/test_issue45_herdr_config.py | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.agents/skills/lib_py/herdr_config.py b/.agents/skills/lib_py/herdr_config.py index 69f1500..1d20f55 100644 --- a/.agents/skills/lib_py/herdr_config.py +++ b/.agents/skills/lib_py/herdr_config.py @@ -32,7 +32,6 @@ import os import re import sys import tempfile -import tomllib from typing import List, Mapping, Optional, Tuple MARKER = "# generated by multi-agent-mux (Issue #45) - do not edit" @@ -42,6 +41,11 @@ FALLBACK_NAME = "herdr-server-config.toml" KEY = "resume_agents_on_restore" MINIMAL = f"[session]\n{KEY} = false\n" +try: + import tomllib +except ImportError: # Python < 3.11: no parser to check a merge with + tomllib = None + _SESSION_HEADER = re.compile(r"^\s*\[\s*session\s*\]\s*(#.*)?$") _ANY_HEADER = re.compile(r"^\s*\[") _KEY_LINE = re.compile(rf"^\s*{KEY}\s*=") @@ -107,6 +111,9 @@ def server_config_text(user_text: Optional[str]) -> Tuple[str, List[str]]: always has session.resume_agents_on_restore = false.""" if not user_text or not user_text.strip(): return MINIMAL, [] + if tomllib is None: + return MINIMAL, [f"this Python has no tomllib (3.11+); the MAM server uses only {KEY} = false, " + "without the rest of your settings"] try: user = tomllib.loads(user_text) except tomllib.TOMLDecodeError as e: diff --git a/tests/test_issue45_herdr_config.py b/tests/test_issue45_herdr_config.py index add63e4..3ee1429 100644 --- a/tests/test_issue45_herdr_config.py +++ b/tests/test_issue45_herdr_config.py @@ -71,6 +71,14 @@ def test_a_bad_value_type_falls_back_to_minimal(): assert warnings == [] +def test_without_tomllib_restore_is_still_off(monkeypatch): + # The shim runs a bare `python3`; on one older than 3.11 an import error + # would leave the server with restore on. Off wins over the user's settings. + monkeypatch.setattr(hc, "tomllib", None) + text, warnings = hc.server_config_text("[ui]\nconfirm_close = false\n") + assert text == hc.MINIMAL and "no tomllib" in warnings[0] + + def _env(tmp_path, **kw): env = {"HOME": str(tmp_path / "home")} env.update(kw)