fix(issue-31): a claude purge removes every path the session owns, reports what is left, and waits for the process; the stop docs say a purge removes the row #59

Merged
Godopu merged 26 commits from fix/issue-31 into main 2026-10-17 16:25:21 +00:00
2 changed files with 15 additions and 7 deletions
Showing only changes of commit 60779ba1f8 - Show all commits

No files matched your search

@@ -78,12 +78,17 @@ def _session_file_live(data: dict, pid) -> bool:
except OSError:
pass
# startedAt is epoch ms: a finite positive number. A bool, a string, NaN
# (every comparison with it is false) or an infinity is no time at all.
# (every comparison with it is false), an infinity or an int too large
# for a float is no time at all.
started = data.get("startedAt")
if isinstance(started, bool) or not isinstance(started, (int, float)) \
or not math.isfinite(started) or started <= 0:
if isinstance(started, bool) or not isinstance(started, (int, float)):
return True
try:
started = float(started) / 1000.0
except OverflowError:
return True
if not math.isfinite(started) or started <= 0:
return True
started = started / 1000.0
# lstart in UTC: a local time is ambiguous in the hour a DST change repeats.
try:
out = subprocess.run(["ps", "-p", str(pid), "-o", "lstart="], capture_output=True, text=True,
+6 -3
View File
@@ -472,7 +472,8 @@ def test_liveness_reads_lstart_as_utc(tmp_path, monkeypatch, live):
@pytest.mark.parametrize("started", ["NaN", float("nan"), float("inf"), float("-inf"), "inf", "1760000000000",
"soon", True, False, None, [1], "<missing>"])
"soon", True, False, None, [1], pytest.param(10 ** 400, id="10**400"),
"<missing>"])
def test_an_unusable_started_at_means_live(live, started):
from lib_py.agents.adapters import claude as claude_mod
data = {} if started == "<missing>" else {"startedAt": started}
@@ -480,10 +481,12 @@ def test_an_unusable_started_at_means_live(live, started):
assert claude_mod._session_file_live(data, _dead_pid()) is False, "a dead pid holds nothing"
@pytest.mark.parametrize("raw", ["NaN", '"NaN"', "Infinity", "true"])
@pytest.mark.parametrize("raw", ["NaN", '"NaN"', "Infinity", "true",
pytest.param("1" + "0" * 400, id="10**400")])
def test_a_live_holder_with_an_unusable_started_at_blocks_the_purge(home, tmp_path, conv, live, raw):
"""json.load turns a bare NaN or Infinity into a float that every
comparison fails, which once made a live holder look stale."""
comparison fails, which once made a live holder look stale, and a huge
integer into an int no float can hold."""
ws = tmp_path / "ws"
ws.mkdir()
sfile, key = _session_file(home / ".claude", live.pid, conv)