fix: repair DASH-001 live session state and readiness panel

This commit is contained in:
2026-08-17 10:47:53 -04:00
parent 8ca000a166
commit e7b6ae5878
7 changed files with 251 additions and 15 deletions

View File

@@ -71,6 +71,7 @@ class DashboardRuntime:
self.provenance: Optional[Dict[str, Any]] = None
self.settings: Dict[str, str] = {}
self.raw_tail: List[str] = []
self.readiness: Dict[str, Any] = {}
self.current_session_file: Optional[str] = None
self.polling = config.get("polling", {}) if isinstance(config.get("polling", {}), dict) else {}
self.session_poll_seconds = float(self.polling.get("session_log_seconds", 2))
@@ -92,7 +93,9 @@ class DashboardRuntime:
return {
"log_dir": str(self.log_dir),
"session_file": self.current_session_file,
"current_session": self.state.current_session,
"live_state": self.live_state,
"readiness": dict(self.readiness),
"events": list(self.latest_events[-100:]),
"trades": list(self.trades),
"provenance": self.provenance,
@@ -122,6 +125,14 @@ class DashboardRuntime:
path = parsers.newest_session_file(self.log_dir)
if path is None:
return
raw_tail = parsers.tail_lines(path)
session_key = parsers.session_key(path, raw_tail)
self.state.rollover_session(session_key)
with self.lock:
self.raw_tail = raw_tail
self.current_session_file = str(path)
self.readiness = parsers.parse_readiness(raw_tail)
self._refresh_live_state_from_tail(path, raw_tail)
offset = self.state.get_offset(path)
if offset is None:
try:
@@ -134,14 +145,18 @@ class DashboardRuntime:
lines, next_offset, next_partial = parsers.read_new_complete_lines(path, offset, partial)
self.state.set_offset(path, next_offset)
self.state.set_partial(path, next_partial)
self.raw_tail = parsers.tail_lines(path)
self.current_session_file = str(path)
for line in lines:
event = parsers.parse_session_event(path, line)
if event is not None:
self._handle_event(event)
self.state.save()
def _refresh_live_state_from_tail(self, path: Path, lines: List[str]) -> None:
for line in lines:
event = parsers.parse_session_event(path, line)
if event is not None:
self._apply_event(event)
def _poll_trades(self) -> None:
path = parsers.today_trades_file(self.log_dir)
trades = parsers.read_trades(path)
@@ -158,16 +173,32 @@ class DashboardRuntime:
self.settings = settings
def _handle_event(self, event: Dict[str, Any]) -> None:
self._apply_event(event)
if str(event.get("type") or "") == "PNL_UPDATE":
self._handle_pnl_milestones(event)
with self.lock:
self.latest_events.append(event)
self.latest_events = self.latest_events[-500:]
self._notify_event(event)
def _apply_event(self, event: Dict[str, Any]) -> None:
event_type = str(event.get("type") or "")
if event_type == "SESSION START":
session_key = str(event.get("session_start") or event.get("source") or "unknown")
self.state.rollover_session(session_key)
self.live_state["session_start"] = event.get("session_start")
elif event_type == "ACCOUNT":
self.live_state["account"] = event.get("account")
elif event_type == "SYMBOL":
self.live_state["symbol"] = event.get("symbol")
elif event_type == "MODE":
self.live_state["mode"] = event.get("mode")
elif event_type == "PNL_UPDATE":
self.live_state["daily_pnl"] = event.get("daily_pnl")
self.live_state["position"] = event.get("position")
self.live_state["quantity"] = event.get("quantity")
self._handle_pnl_milestones(event)
elif event_type.startswith("CONNECTION"):
self.live_state["connection"] = event.get("status")
elif event_type == "FILL":
@@ -177,12 +208,6 @@ class DashboardRuntime:
elif event_type == "BREAKEVEN":
self.live_state["last_breakeven"] = event
with self.lock:
self.latest_events.append(event)
self.latest_events = self.latest_events[-500:]
self._notify_event(event)
def _handle_pnl_milestones(self, event: Dict[str, Any]) -> None:
if not notifications_enabled(self.config, "daily_pnl_milestones"):
return