Spaces:
Running
Running
Fix: never emit Infinity in health JSON (strict JSON for browsers)
Browse files
aureon/core/aureon_operational_core.py
CHANGED
|
@@ -660,7 +660,7 @@ class StatePulse:
|
|
| 660 |
"""Check if state is stale (not updated recently)."""
|
| 661 |
last = self._last_write.get('state', 0)
|
| 662 |
if last == 0:
|
| 663 |
-
return True,
|
| 664 |
age = time.time() - last
|
| 665 |
return age > self._stale_threshold, age
|
| 666 |
|
|
@@ -669,7 +669,9 @@ class StatePulse:
|
|
| 669 |
last = self._last_write.get('state', 0)
|
| 670 |
return {
|
| 671 |
'last_write': datetime.fromtimestamp(last).isoformat() if last > 0 else 'NEVER',
|
| 672 |
-
|
|
|
|
|
|
|
| 673 |
'is_stale': (now - last > self._stale_threshold) if last > 0 else True,
|
| 674 |
'write_count': self._write_count,
|
| 675 |
}
|
|
@@ -911,7 +913,9 @@ class AureonOperationalCore:
|
|
| 911 |
|
| 912 |
if state_freshness['is_stale']:
|
| 913 |
health = 'degraded' if health == 'healthy' else health
|
| 914 |
-
|
|
|
|
|
|
|
| 915 |
|
| 916 |
return {
|
| 917 |
'status': health,
|
|
|
|
| 660 |
"""Check if state is stale (not updated recently)."""
|
| 661 |
last = self._last_write.get('state', 0)
|
| 662 |
if last == 0:
|
| 663 |
+
return True, -1.0 # never written; -1.0 = unknown (never Infinity — strict JSON)
|
| 664 |
age = time.time() - last
|
| 665 |
return age > self._stale_threshold, age
|
| 666 |
|
|
|
|
| 669 |
last = self._last_write.get('state', 0)
|
| 670 |
return {
|
| 671 |
'last_write': datetime.fromtimestamp(last).isoformat() if last > 0 else 'NEVER',
|
| 672 |
+
# None when never written: float('inf') would serialize as the literal
|
| 673 |
+
# `Infinity` token, which browsers cannot JSON.parse.
|
| 674 |
+
'age_seconds': now - last if last > 0 else None,
|
| 675 |
'is_stale': (now - last > self._stale_threshold) if last > 0 else True,
|
| 676 |
'write_count': self._write_count,
|
| 677 |
}
|
|
|
|
| 913 |
|
| 914 |
if state_freshness['is_stale']:
|
| 915 |
health = 'degraded' if health == 'healthy' else health
|
| 916 |
+
age = state_freshness.get('age_seconds')
|
| 917 |
+
stale_detail = 'never written' if age is None else f"{age:.0f}s old"
|
| 918 |
+
issues.append(f"State stale: {stale_detail}")
|
| 919 |
|
| 920 |
return {
|
| 921 |
'status': health,
|