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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(ui): preserve all-log recency
cyh91bd20960152
diff --git a/tests/test_ui_server_logs.py b/tests/test_ui_server_logs.pyindex 88328ec7d..7ebe4342e 100644--- a/tests/test_ui_server_logs.py+++ b/tests/test_ui_server_logs.py@@ -1,9 +1,17 @@from __future__ import annotations+import os+from datetime import datetime+from config import pathsfrom vibe.ui_server import app+def _set_mtime(path, timestamp: str) -> None:+ value = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S").timestamp()+ os.utime(path, (value, value))++def test_logs_endpoint_returns_multiple_sources(monkeypatch, tmp_path):monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))paths.ensure_data_dirs()@@ -43,18 +51,23 @@ def test_logs_endpoint_returns_aggregated_all_view(monkeypatch, tmp_path):monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))paths.ensure_data_dirs()- (paths.get_logs_dir() / "vibe_remote.log").write_text(+ service_log = paths.get_logs_dir() / "vibe_remote.log"+ service_log.write_text("2026-03-25 15:51:17,428 - asyncio - ERROR - main service failed\n",encoding="utf-8",)- (paths.get_runtime_dir() / "service_stderr.log").write_text(+ service_stderr_log = paths.get_runtime_dir() / "service_stderr.log"+ service_stderr_log.write_text("service stderr line\n",encoding="utf-8",)- (paths.get_runtime_dir() / "ui_stderr.log").write_text(+ ui_stderr_log = paths.get_runtime_dir() / "ui_stderr.log"+ ui_stderr_log.write_text("UI boot failed\n",encoding="utf-8",)+ _set_mtime(service_stderr_log, "2026-03-25 15:51:18")+ _set_mtime(ui_stderr_log, "2026-03-25 15:51:19")client = app.test_client()response = client.post("/logs", json={"lines": 20, "source": "all"})@@ -64,9 +77,9 @@ def test_logs_endpoint_returns_aggregated_all_view(monkeypatch, tmp_path):assert payload["source"] == "all"assert payload["total"] == 3assert [entry["source"] for entry in payload["logs"]] == [+ "service","service_stderr","ui_stderr",- "service",]assert {entry["source"] for entry in payload["logs"]} == {"service", "service_stderr", "ui_stderr"}@@ -143,6 +156,38 @@ def test_logs_endpoint_keeps_traceback_exception_summary_with_error_entry(monkeyassert payload["logs"][0]["message"].endswith("ValueError: boom")+def test_logs_endpoint_preserves_recent_unstructured_logs_in_all_view(monkeypatch, tmp_path):+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))+ paths.ensure_data_dirs()++ service_log = paths.get_logs_dir() / "vibe_remote.log"+ service_log.write_text(+ "\n".join(+ [+ "2026-03-25 15:51:17,428 - service.main - INFO - service line 1",+ "2026-03-25 15:51:18,428 - service.main - INFO - service line 2",+ ]+ )+ + "\n",+ encoding="utf-8",+ )+ ui_stderr_log = paths.get_runtime_dir() / "ui_stderr.log"+ ui_stderr_log.write_text("latest ui crash line\n", encoding="utf-8")+ _set_mtime(ui_stderr_log, "2026-03-25 15:51:19")++ client = app.test_client()+ response = client.post("/logs", json={"lines": 2, "source": "all"})++ assert response.status_code == 200+ payload = response.get_json()+ assert payload["source"] == "all"+ assert payload["total"] == 3+ assert [entry["message"] for entry in payload["logs"]] == [+ "service line 2",+ "latest ui crash line",+ ]++def test_logs_endpoint_falls_back_to_service_for_unknown_source(monkeypatch, tmp_path):monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))paths.ensure_data_dirs()diff --git a/vibe/ui_server.py b/vibe/ui_server.pyindex e5294c05c..5d52d05c6 100644--- a/vibe/ui_server.py+++ b/vibe/ui_server.py@@ -4,6 +4,7 @@ import loggingimport mimetypesimport reimport threading+from datetime import datetimefrom pathlib import Pathfrom typing import Any@@ -94,26 +95,51 @@ def _fallback_log_entry(line: str, source_key: str) -> dict[str, str]:}-def _read_log_entries(log_path: Path, source_key: str, lines: int) -> tuple[list[dict[str, str]], int]:+def _timestamp_to_sort_ns(timestamp: str) -> int | None:+ try:+ return int(datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S,%f").timestamp() * 1_000_000_000)+ except ValueError:+ return None+++def _serialize_log_entries(entries: list[dict[str, Any]]) -> list[dict[str, str]]:+ return [+ {+ "timestamp": str(entry.get("timestamp", "")),+ "logger": str(entry.get("logger", "")),+ "level": str(entry.get("level", "INFO")),+ "message": str(entry.get("message", "")),+ "source": str(entry.get("source", "")),+ }+ for entry in entries+ ]+++def _read_log_entries(log_path: Path, source_key: str, lines: int) -> tuple[list[dict[str, Any]], int]:if not log_path.exists():return [], 0with log_path.open("r", encoding="utf-8", errors="replace") as f:all_lines = f.readlines()recent_lines = all_lines[-lines:] if len(all_lines) > lines else all_lines+ file_sort_ns = log_path.stat().st_mtime_ns+ first_recent_line_index = len(all_lines) - len(recent_lines)- logs_list: list[dict[str, str]] = []- for raw_line in recent_lines:+ logs_list: list[dict[str, Any]] = []+ for line_offset, raw_line in enumerate(recent_lines):line = raw_line.rstrip("\n")match = STRUCTURED_LOG_PATTERN.match(line)if match:+ parsed_timestamp = match.group(1)logs_list.append({- "timestamp": match.group(1),+ "timestamp": parsed_timestamp,"logger": match.group(2),"level": match.group(3),"message": match.group(4),"source": source_key,+ "_sort_ns": _timestamp_to_sort_ns(parsed_timestamp) or file_sort_ns,+ "_sort_index": first_recent_line_index + line_offset,})continue@@ -125,7 +151,10 @@ def _read_log_entries(log_path: Path, source_key: str, lines: int) -> tuple[listlogs_list[-1]["message"] += "\n" + linecontinue- logs_list.append(_fallback_log_entry(line, source_key))+ fallback_entry = _fallback_log_entry(line, source_key)+ fallback_entry["_sort_ns"] = file_sort_ns+ fallback_entry["_sort_index"] = first_recent_line_index + line_offset+ logs_list.append(fallback_entry)return logs_list, len(all_lines)@@ -539,7 +568,7 @@ def logs():active_source = source_map.get(selected_source) or source_map["all"]try:- aggregated_logs: list[dict[str, str]] = []+ aggregated_logs: list[dict[str, Any]] = []aggregated_total = 0for source in sources:if source["key"] == "all":@@ -559,7 +588,12 @@ def logs():if active_source["key"] == "all":active_logs = sorted(aggregated_logs,- key=lambda entry: (entry.get("timestamp") or "", entry.get("source") or "", entry.get("logger") or ""),+ key=lambda entry: (+ int(entry.get("_sort_ns", 0)),+ int(entry.get("_sort_index", 0)),+ entry.get("source") or "",+ entry.get("logger") or "",+ ),)if len(active_logs) > lines:active_logs = active_logs[-lines:]@@ -567,7 +601,7 @@ def logs():return jsonify({"source": active_source["key"],- "logs": active_logs,+ "logs": _serialize_log_entries(active_logs),"total": active_total,"sources": sources,}