fix(b4): restore dynamic POSIX timestamp in herdr ls shim and reconcile.sh (100% PASS)
This commit is contained in:
@@ -329,24 +329,35 @@ claude_project_dir = os.environ.get('CLAUDE_PROJECT_DIR', f"{home}/.claude/proje
|
||||
|
||||
now_iso = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
|
||||
# Bound unconditionally. This used to be assigned only inside the "except
|
||||
# NameError" branch below, which the write path never enters because
|
||||
# atomic_dump_yaml predefines `d` -- so drift C's pin raised
|
||||
# NameError: name 'lib_sh' is not defined and aborted the whole sweep,
|
||||
# in write mode only.
|
||||
lib_sh = os.environ.get('LIB_SH')
|
||||
if not lib_sh:
|
||||
_ws_root = os.environ.get('WORKSPACE_ROOT')
|
||||
if not _ws_root:
|
||||
_ws_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..'))
|
||||
lib_sh = os.path.join(_ws_root, '.agents/skills/lib.sh')
|
||||
|
||||
try:
|
||||
d
|
||||
except NameError:
|
||||
import subprocess
|
||||
d = {}
|
||||
try:
|
||||
lib_sh = os.environ.get('LIB_SH')
|
||||
if not lib_sh:
|
||||
ws_root = os.environ.get('WORKSPACE_ROOT')
|
||||
if not ws_root:
|
||||
ws_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..'))
|
||||
lib_sh = os.path.join(ws_root, '.agents/skills/lib.sh')
|
||||
script = f"source '{lib_sh}' && load_state_json"
|
||||
out = subprocess.check_output(['bash', '-c', script], stderr=subprocess.DEVNULL)
|
||||
d = json.loads(out.decode('utf-8'))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Any herdr_session_epoch at or below this is not a real session time.
|
||||
# 1000000000 = 2001-09-09; it is below every plausible MAM session and far
|
||||
# above the 0 / 999999 sentinels this guard exists to reject.
|
||||
MAM_EPOCH_FLOOR = 1000000000
|
||||
|
||||
drifts = []
|
||||
actions = []
|
||||
|
||||
@@ -375,10 +386,24 @@ try:
|
||||
sys.stderr.write(f"LS CMD: {cmd} | RC: {r.returncode} | STDOUT: {r.stdout} | STDERR: {r.stderr}\n")
|
||||
if r.returncode == 0:
|
||||
for line in r.stdout.strip().split('\n'):
|
||||
if not line:
|
||||
if not line or '|' not in line:
|
||||
continue
|
||||
name, created = line.split('|', 1)
|
||||
herdr_sessions.append({'name': name, 'created': int(created), 'server': srv})
|
||||
# A malformed field must not abort the whole sweep: the old
|
||||
# bare int() raised out of the enclosing try and flipped
|
||||
# herdr_confirmed to False for every server, which reads as
|
||||
# "herdr is down" and suppresses drift detection entirely.
|
||||
try:
|
||||
created_i = int(created.strip())
|
||||
except ValueError:
|
||||
created_i = 0
|
||||
# Below the floor means "no real creation time" -- 0, or the
|
||||
# 999999 sentinel the shim used to emit (B-4). Both are far
|
||||
# below any live transcript's mtime, so they silently disable
|
||||
# the stale-transcript guard in verify_session_uuid.
|
||||
if created_i < MAM_EPOCH_FLOOR:
|
||||
created_i = 0
|
||||
herdr_sessions.append({'name': name, 'created': created_i, 'server': srv})
|
||||
else:
|
||||
err = (r.stderr or '').lower()
|
||||
is_empty = ('no server running' in err) or ('no sessions' in err) or ('failed to connect' in err)
|
||||
@@ -494,11 +519,18 @@ if herdr_confirmed:
|
||||
elif agent == 'cline':
|
||||
cmd_full = 'cline -i'
|
||||
server_opt = f"-L {srv} " if srv != 'default' else ""
|
||||
# The shim resolves this from the pane's root process. Fall back to now
|
||||
# only if that failed: 'now' can merely over-estimate creation time,
|
||||
# which tightens the stale-transcript guard, whereas 0 disables it and
|
||||
# stamps a 1970-01-01 herdr_session_created_at into the YAML.
|
||||
created_epoch = t.get('created') or 0
|
||||
if created_epoch < MAM_EPOCH_FLOOR:
|
||||
created_epoch = int(time.time())
|
||||
entry = {
|
||||
'name': name,
|
||||
'status': 'running',
|
||||
'herdr_session_created_at': datetime.fromtimestamp(t.get('created', 0), tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ'),
|
||||
'herdr_session_epoch': t.get('created', 0),
|
||||
'herdr_session_created_at': datetime.fromtimestamp(created_epoch, tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ'),
|
||||
'herdr_session_epoch': created_epoch,
|
||||
'herdr_session': srv,
|
||||
'pane': {'index': 0, 'pid': pm['pid'], 'cmd': agent, 'cmd_full': cmd_full, 'cwd': pm['cwd']},
|
||||
'start_command': f'HERDR_SESSION_NAME={srv} herdr new-session -d -s "{name}" -x 140 -y 40 -c "{pm["cwd"]}" "{cmd_full}"',
|
||||
|
||||
Reference in New Issue
Block a user