Skip to content

Commit c2a336a

Browse files
Gregg CochranCopilot
andcommitted
Keep Pulse on explicit Stampede roots
When AGENT_PULSE_SCAN_ROOTS is set, restrict Stampede run discovery to those roots and sort run directories by run id timestamp before mtime so terminal Agent Conductor runs do not fall back to stale historical runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e06c755 commit c2a336a

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

agent_pulse.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,18 +1010,19 @@ def _iter_stampede_bases(self) -> List[Path]:
10101010
for p in os.environ.get("AGENT_PULSE_SCAN_ROOTS", "").split(os.pathsep)
10111011
if p
10121012
]
1013-
roots = [Path.cwd(), Path.home(), Path.home() / "dev", Path.home() / "tmp", *env_roots]
1013+
roots = env_roots if env_roots else [Path.cwd(), Path.home(), Path.home() / "dev", Path.home() / "tmp"]
10141014
bases: Dict[str, Path] = {}
10151015

10161016
def add_base(path: Path) -> None:
1017-
if path.exists() and path.is_dir():
1017+
if path.exists() and path.is_dir() and path.name == ".stampede":
10181018
bases[str(path)] = path
10191019

10201020
def scan_depth(root: Path, max_depth: int = 3) -> None:
10211021
stack: List[Tuple[Path, int]] = [(root, 0)]
10221022
while stack and len(bases) < 100:
10231023
current, depth = stack.pop()
10241024
try:
1025+
add_base(current)
10251026
add_base(current / ".stampede")
10261027
if depth >= max_depth:
10271028
continue
@@ -1065,13 +1066,20 @@ def _candidate_run_dirs(self) -> List[Path]:
10651066
except Exception:
10661067
continue
10671068

1068-
def mtime(path: Path) -> float:
1069+
def run_sort_key(path: Path) -> Tuple[int, float]:
1070+
match = re.match(r"run-(\d{8})-(\d{6})$", path.name)
1071+
run_ts = 0
1072+
if match:
1073+
try:
1074+
run_ts = int(datetime.strptime("".join(match.groups()), "%Y%m%d%H%M%S").timestamp())
1075+
except Exception:
1076+
run_ts = 0
10691077
try:
1070-
return path.stat().st_mtime
1078+
return (run_ts, path.stat().st_mtime)
10711079
except OSError:
1072-
return 0.0
1080+
return (run_ts, 0.0)
10731081

1074-
return sorted(runs.values(), key=mtime, reverse=True)[: self._RUN_DIR_LIMIT]
1082+
return sorted(runs.values(), key=run_sort_key, reverse=True)[: self._RUN_DIR_LIMIT]
10751083

10761084
def _poll_ledger_events(self, ledger: Path, run_id: str, commander_id: str) -> None:
10771085
key = f"stampede-ledger:{ledger}"

0 commit comments

Comments
 (0)