fix(agents): compare a claude process's lstart in UTC (Issue #31, Mac review)
time.mktime read ps's local lstart, which is ambiguous in the hour a DST change repeats: the start could come out an hour off and a live holder be taken for a reused pid (or the reverse). ps now runs with TZ=UTC0, which BSD ps and procps both honour, and calendar.timegm reads it. No /proc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f943b0db30
commit
af8ed397f6
2 files changed
+28
-3
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import os, re, json, glob, math, stat, time, shutil, subprocess
|
||||
import os, re, json, glob, math, stat, time, shutil, calendar, subprocess
|
||||
from typing import Optional, Any
|
||||
from lib_py.agents.base import BaseAgentAdapter, DiscoveryContext, conversation_in_use, scan_names, _plausible_id
|
||||
from lib_py.verify_session import workspace_key
|
||||
@@ -84,10 +84,11 @@ def _session_file_live(data: dict, pid) -> bool:
|
||||
or 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,
|
||||
timeout=5, env=dict(os.environ, LC_ALL="C")).stdout
|
||||
lstart = time.mktime(time.strptime(" ".join(out.split()), "%a %b %d %H:%M:%S %Y"))
|
||||
timeout=5, env=dict(os.environ, LC_ALL="C", TZ="UTC0")).stdout
|
||||
lstart = calendar.timegm(time.strptime(" ".join(out.split()), "%a %b %d %H:%M:%S %Y"))
|
||||
except Exception:
|
||||
return True
|
||||
# startedAt is written 1.7-3.2 s after the process starts; 2 s covers
|
||||
|
||||
Reference in new issue
Block a user