fix: address pre-push review findings

This commit is contained in:
Hermes Agent
2026-07-26 23:37:15 +00:00
parent 2da5d20ccd
commit bf77737d88
8 changed files with 68 additions and 9 deletions
+5 -4
View File
@@ -19,7 +19,7 @@ except ImportError: # pragma: no cover - Windows fallback uses the process lock
_LOCKS: dict[str, threading.RLock] = {}
_LOCKS_GUARD = threading.Lock()
_METADATA_KEYS = {"observed_at", "source", "stale", "last_error"}
_METADATA_KEYS = {"observed_at", "source", "stale", "last_error", "error"}
def _thread_lock(path: Path) -> threading.RLock:
@@ -165,7 +165,7 @@ def append_daily_jsonl(path: str | os.PathLike[str], entry: dict[str, Any]) -> b
return True
def _has_observation(payload: Any) -> bool:
def has_observation(payload: Any) -> bool:
if not isinstance(payload, dict):
return payload is not None
return any(value is not None for key, value in payload.items() if key not in _METADATA_KEYS)
@@ -180,7 +180,7 @@ def merge_observation(
error: str | None = None,
) -> dict[str, Any]:
"""Annotate a fresh observation or retain the last-known-good value as stale."""
if _has_observation(observed):
if has_observation(observed):
merged = dict(observed) if isinstance(observed, dict) else {"value": observed}
merged.update(
observed_at=observed_at or datetime.now(timezone.utc).isoformat(),
@@ -191,10 +191,11 @@ def merge_observation(
return merged
merged = dict(previous) if isinstance(previous, dict) else {}
observed_error = observed.get("error") if isinstance(observed, dict) else None
merged.update(
source=merged.get("source") or source,
stale=True,
last_error=error or "metric was not observed",
last_error=observed_error or error or "metric was not observed",
)
merged.setdefault("observed_at", None)
return merged
+2 -1
View File
@@ -32,6 +32,7 @@ from scoring import engine
from dashboard.persistence import (
append_daily_jsonl,
atomic_write_json,
has_observation,
load_json,
load_jsonl_tail,
merge_observation,
@@ -293,7 +294,7 @@ def run_scrape(force_full=False):
existing_cache.get(key), onchain.get(key), source=source,
error="metric missing from scrape",
)
if successful_sources:
if successful_sources and any(has_observation(value) for value in onchain.values()):
metrics["_onchain_timestamp"] = datetime.now(timezone.utc).isoformat()
elif "_onchain_timestamp" in existing_cache:
metrics["_onchain_timestamp"] = existing_cache["_onchain_timestamp"]