Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(runtime): avoid localized ps start parsing

cyh79b0db03049b
diff --git a/tests/test_runtime_service_lock.py b/tests/test_runtime_service_lock.py
index e708331b4..0e19c4cae 100644
--- a/tests/test_runtime_service_lock.py
+++ b/tests/test_runtime_service_lock.py
@@ -3,6 +3,7 @@ import sys
import tempfile
import unittest
from pathlib import Path
+from types import SimpleNamespace
from unittest.mock import patch
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
@@ -10,6 +11,10 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from vibe import runtime
+def subprocess_result(stdout: str = "", returncode: int = 0):
+ return SimpleNamespace(stdout=stdout, returncode=returncode)
+
+
class RuntimeServiceLockTests(unittest.TestCase):
def test_start_service_reuses_existing_live_pid(self):
with tempfile.TemporaryDirectory() as tmpdir:
@@ -117,6 +122,25 @@ class RuntimeServiceLockTests(unittest.TestCase):
with patch("vibe.runtime.get_process_start_time", return_value=1000.0):
self.assertFalse(runtime.runtime_processes_stale_after_package_update())
+ def test_parse_ps_elapsed_seconds(self):
+ self.assertEqual(runtime._parse_ps_elapsed_seconds("00:07"), 7)
+ self.assertEqual(runtime._parse_ps_elapsed_seconds("01:02:03"), 3723)
+ self.assertEqual(runtime._parse_ps_elapsed_seconds("2-01:02:03"), 176523)
+ self.assertIsNone(runtime._parse_ps_elapsed_seconds("Wed May 13 12:00:00 2026"))
+
+ def test_ps_process_start_time_uses_locale_independent_elapsed_time(self):
+ completed = subprocess_result(stdout="01:02:03\n", returncode=0)
+ with patch("vibe.runtime.subprocess.run", return_value=completed) as run:
+ with patch("vibe.runtime.time.time", return_value=10_000.0):
+ self.assertEqual(runtime._ps_process_start_time(12345), 6277.0)
+ run.assert_called_once_with(
+ ["ps", "-p", "12345", "-o", "etime="],
+ capture_output=True,
+ text=True,
+ timeout=2,
+ check=False,
+ )
+
if __name__ == "__main__":
unittest.main()
diff --git a/vibe/runtime.py b/vibe/runtime.py
index 05b42ad71..540e76478 100644
--- a/vibe/runtime.py
+++ b/vibe/runtime.py
@@ -10,7 +10,6 @@ import threading
import time
import urllib.error
import urllib.request
-from datetime import datetime
from pathlib import Path
from config import paths
@@ -490,10 +489,43 @@ def _linux_process_start_time(pid: int) -> float | None:
return None
+def _parse_ps_elapsed_seconds(value: str) -> int | None:
+ text = value.strip()
+ if not text:
+ return None
+ days = 0
+ if "-" in text:
+ day_text, text = text.split("-", 1)
+ try:
+ days = int(day_text)
+ except ValueError:
+ return None
+ parts = text.split(":")
+ if len(parts) == 2:
+ hours = 0
+ minutes_text, seconds_text = parts
+ elif len(parts) == 3:
+ hours_text, minutes_text, seconds_text = parts
+ try:
+ hours = int(hours_text)
+ except ValueError:
+ return None
+ else:
+ return None
+ try:
+ minutes = int(minutes_text)
+ seconds = int(seconds_text)
+ except ValueError:
+ return None
+ if min(days, hours, minutes, seconds) < 0 or minutes >= 60 or seconds >= 60:
+ return None
+ return (((days * 24) + hours) * 60 + minutes) * 60 + seconds
+
+
def _ps_process_start_time(pid: int) -> float | None:
try:
result = subprocess.run(
- ["ps", "-p", str(pid), "-o", "lstart="],
+ ["ps", "-p", str(pid), "-o", "etime="],
capture_output=True,
text=True,
timeout=2,
@@ -504,14 +536,11 @@ def _ps_process_start_time(pid: int) -> float | None:
return None
if result.returncode != 0:
return None
- started_text = result.stdout.strip()
- if not started_text:
- return None
- try:
- return datetime.strptime(started_text, "%a %b %d %H:%M:%S %Y").timestamp()
- except ValueError:
- logger.debug("Failed to parse ps start time for pid=%s: %s", pid, started_text)
+ elapsed_seconds = _parse_ps_elapsed_seconds(result.stdout)
+ if elapsed_seconds is None:
+ logger.debug("Failed to parse ps elapsed time for pid=%s: %s", pid, result.stdout.strip())
return None
+ return time.time() - elapsed_seconds
def get_process_start_time(pid: int) -> float | None: