yf176 commited on
Commit
d647d80
·
1 Parent(s): 7334e35

Complete V7.1 replay and evidence guardrails

Browse files
src/polyhedra/app.py CHANGED
@@ -54,6 +54,7 @@ except ImportError: # pragma: no cover
54
  _WEB_STATIC_DIR = Path(__file__).resolve().parent / "web" / "static"
55
  _RUNS: dict[str, dict[str, Any]] = {}
56
  _RUN_TASKS: set[asyncio.Task[Any]] = set()
 
57
 
58
 
59
  def _extract_ui_tickers(text: str) -> list[str]:
@@ -272,6 +273,7 @@ def _session_payload(session_id: str) -> dict[str, Any] | None:
272
 
273
  return {
274
  "session_id": session.session_id,
 
275
  "goal": session.goal,
276
  "created_at": session.created_at.isoformat(),
277
  "platform": session.platform,
@@ -572,7 +574,11 @@ def _options_issue_detail(text: str, *, fallback: str) -> str:
572
  for line in text.splitlines():
573
  stripped = line.strip(" -")
574
  upper = stripped.upper()
575
- if "DATA_GAP" in upper or "ERROR" in upper or "UNAVAILABLE" in upper:
 
 
 
 
576
  return stripped
577
  for line in text.splitlines():
578
  stripped = line.strip(" -")
@@ -689,8 +695,10 @@ async def _start_yolo_run_for_session(
689
 
690
  run_state: dict[str, Any] = {
691
  "session_id": session.session_id,
 
692
  "status": "pending",
693
  "started_at": datetime.now(tz=UTC).isoformat(),
 
694
  "messages": [],
695
  "status_message": "",
696
  "error": "",
@@ -749,6 +757,9 @@ async def _start_yolo_run_for_session(
749
  logger.exception("UI YOLO run failed: %s", exc)
750
  run_state["status"] = "failed"
751
  run_state["error"] = str(exc)
 
 
 
752
 
753
  task = asyncio.create_task(run_pipeline())
754
  _RUN_TASKS.add(task)
@@ -770,6 +781,7 @@ async def _wait_for_yolo_terminal(session_id: str, timeout_seconds: int = 600) -
770
  return
771
  if payload["status"] in {"completed", "blocked", "failed"}:
772
  run["status"] = payload["status"]
 
773
  return
774
  count = len(payload.get("messages", []))
775
  if count == last_count:
@@ -780,10 +792,91 @@ async def _wait_for_yolo_terminal(session_id: str, timeout_seconds: int = 600) -
780
  if idle_ticks >= 180:
781
  run["status"] = "blocked"
782
  run["error"] = "No agent progress for three minutes; inspect the session or Slack logs."
 
 
 
783
  return
784
  await asyncio.sleep(1)
785
  run["status"] = "blocked"
786
  run["error"] = "Timed out waiting for Finley to post the final YOLO output."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787
 
788
 
789
  def create_app():
@@ -936,6 +1029,22 @@ def create_app():
936
  "error": payload["error"],
937
  })
938
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
939
  @app.get("/api/sessions/{session_id}/export", tags=["web"])
940
  async def api_session_export(session_id: str):
941
  from polyhedra.core.session import SessionManager
 
54
  _WEB_STATIC_DIR = Path(__file__).resolve().parent / "web" / "static"
55
  _RUNS: dict[str, dict[str, Any]] = {}
56
  _RUN_TASKS: set[asyncio.Task[Any]] = set()
57
+ _YOLO_RUNS_DIR = "yolo_runs"
58
 
59
 
60
  def _extract_ui_tickers(text: str) -> list[str]:
 
273
 
274
  return {
275
  "session_id": session.session_id,
276
+ "run_id": run.get("run_id", ""),
277
  "goal": session.goal,
278
  "created_at": session.created_at.isoformat(),
279
  "platform": session.platform,
 
574
  for line in text.splitlines():
575
  stripped = line.strip(" -")
576
  upper = stripped.upper()
577
+ if "DATA_GAP" in upper or "ERROR" in upper:
578
+ return stripped
579
+ for line in text.splitlines():
580
+ stripped = line.strip(" -")
581
+ if "UNAVAILABLE" in stripped.upper():
582
  return stripped
583
  for line in text.splitlines():
584
  stripped = line.strip(" -")
 
695
 
696
  run_state: dict[str, Any] = {
697
  "session_id": session.session_id,
698
+ "run_id": datetime.now(tz=UTC).strftime("%Y%m%d_%H%M%S"),
699
  "status": "pending",
700
  "started_at": datetime.now(tz=UTC).isoformat(),
701
+ "tickers": tickers,
702
  "messages": [],
703
  "status_message": "",
704
  "error": "",
 
757
  logger.exception("UI YOLO run failed: %s", exc)
758
  run_state["status"] = "failed"
759
  run_state["error"] = str(exc)
760
+ payload = _session_payload(session.session_id)
761
+ if payload is not None:
762
+ _persist_yolo_run_record(session.session_id, payload)
763
 
764
  task = asyncio.create_task(run_pipeline())
765
  _RUN_TASKS.add(task)
 
781
  return
782
  if payload["status"] in {"completed", "blocked", "failed"}:
783
  run["status"] = payload["status"]
784
+ _persist_yolo_run_record(session_id, payload)
785
  return
786
  count = len(payload.get("messages", []))
787
  if count == last_count:
 
792
  if idle_ticks >= 180:
793
  run["status"] = "blocked"
794
  run["error"] = "No agent progress for three minutes; inspect the session or Slack logs."
795
+ payload = _session_payload(session_id)
796
+ if payload is not None:
797
+ _persist_yolo_run_record(session_id, payload)
798
  return
799
  await asyncio.sleep(1)
800
  run["status"] = "blocked"
801
  run["error"] = "Timed out waiting for Finley to post the final YOLO output."
802
+ payload = _session_payload(session_id)
803
+ if payload is not None:
804
+ _persist_yolo_run_record(session_id, payload)
805
+
806
+
807
+ def _persist_yolo_run_record(session_id: str, payload: dict[str, Any]) -> None:
808
+ from polyhedra.core.session import SessionManager
809
+ from polyhedra.services.evidence_ledger import write_evidence_ledger
810
+
811
+ session = SessionManager().resume(session_id)
812
+ if session is None:
813
+ return
814
+ run = _RUNS.get(session_id, {})
815
+ run_id = str(payload.get("run_id") or run.get("run_id") or datetime.now(tz=UTC).strftime("%Y%m%d_%H%M%S"))
816
+ payload["run_id"] = run_id
817
+ payload["replay_label"] = "Prior YOLO run replay - UI-only, not deterministic/frozen replay."
818
+ payload["recorded_at"] = datetime.now(tz=UTC).isoformat()
819
+ ticker_scope = _extract_ui_tickers(session.goal)
820
+ if run.get("tickers"):
821
+ ticker_scope = [str(t).upper() for t in run.get("tickers") or []]
822
+ ledger_paths = write_evidence_ledger(
823
+ session.session_dir,
824
+ run_id=run_id,
825
+ session_id=session_id,
826
+ ticker_scope=ticker_scope,
827
+ diagnostics=payload.get("diagnostics") or {},
828
+ proposal_state=payload.get("proposal_state") or {},
829
+ )
830
+ payload["evidence_ledger"] = ledger_paths
831
+ record_dir = session.session_dir / _YOLO_RUNS_DIR
832
+ record_dir.mkdir(parents=True, exist_ok=True)
833
+ (record_dir / f"{run_id}.json").write_text(
834
+ json.dumps(payload, indent=2),
835
+ encoding="utf-8",
836
+ )
837
+
838
+
839
+ def _list_yolo_run_records(session_id: str) -> list[dict[str, Any]]:
840
+ from polyhedra.core.session import SessionManager
841
+
842
+ session = SessionManager().resume(session_id)
843
+ if session is None:
844
+ raise FileNotFoundError(session_id)
845
+ record_dir = session.session_dir / _YOLO_RUNS_DIR
846
+ if not record_dir.exists():
847
+ return []
848
+ records: list[dict[str, Any]] = []
849
+ for path in sorted(record_dir.glob("*.json"), reverse=True):
850
+ try:
851
+ data = json.loads(path.read_text(encoding="utf-8"))
852
+ except json.JSONDecodeError:
853
+ continue
854
+ records.append({
855
+ "run_id": data.get("run_id") or path.stem,
856
+ "status": data.get("status", ""),
857
+ "run_mode": data.get("run_mode", ""),
858
+ "run_mode_label": data.get("run_mode_label", ""),
859
+ "goal": data.get("goal", ""),
860
+ "recorded_at": data.get("recorded_at", ""),
861
+ "proposal_state": data.get("proposal_state", {}),
862
+ "replay_label": data.get("replay_label", ""),
863
+ })
864
+ return records
865
+
866
+
867
+ def _yolo_run_record(session_id: str, run_id: str) -> dict[str, Any]:
868
+ from polyhedra.core.session import SessionManager
869
+
870
+ session = SessionManager().resume(session_id)
871
+ if session is None:
872
+ raise FileNotFoundError(session_id)
873
+ path = session.session_dir / _YOLO_RUNS_DIR / f"{run_id}.json"
874
+ if not path.exists():
875
+ raise FileNotFoundError(run_id)
876
+ data = json.loads(path.read_text(encoding="utf-8"))
877
+ data["replay"] = True
878
+ data["replay_label"] = data.get("replay_label") or "Prior YOLO run replay - UI-only, not deterministic/frozen replay."
879
+ return data
880
 
881
 
882
  def create_app():
 
1029
  "error": payload["error"],
1030
  })
1031
 
1032
+ @app.get("/api/sessions/{session_id}/runs", tags=["web"])
1033
+ async def api_session_runs(session_id: str) -> JSONResponse:
1034
+ try:
1035
+ runs = _list_yolo_run_records(session_id)
1036
+ except FileNotFoundError:
1037
+ return JSONResponse({"error": "Session not found."}, status_code=404)
1038
+ return JSONResponse({"session_id": session_id, "runs": runs})
1039
+
1040
+ @app.get("/api/sessions/{session_id}/runs/{run_id}", tags=["web"])
1041
+ async def api_session_run_detail(session_id: str, run_id: str) -> JSONResponse:
1042
+ try:
1043
+ payload = _yolo_run_record(session_id, run_id)
1044
+ except FileNotFoundError:
1045
+ return JSONResponse({"error": "Run not found."}, status_code=404)
1046
+ return JSONResponse(payload)
1047
+
1048
  @app.get("/api/sessions/{session_id}/export", tags=["web"])
1049
  async def api_session_export(session_id: str):
1050
  from polyhedra.core.session import SessionManager
src/polyhedra/services/evidence_ledger.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """V7.1 evidence ledger writer for YOLO run packages."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from datetime import UTC, datetime
7
+ from pathlib import Path
8
+ from typing import Any
9
+
10
+
11
+ def write_evidence_ledger(
12
+ session_dir: Path,
13
+ *,
14
+ run_id: str,
15
+ session_id: str,
16
+ ticker_scope: list[str],
17
+ diagnostics: dict[str, Any],
18
+ proposal_state: dict[str, Any],
19
+ ) -> dict[str, str]:
20
+ """Write JSON and Markdown evidence ledger artifacts for a YOLO run."""
21
+ entries = _collect_entries(
22
+ session_dir,
23
+ run_id=run_id,
24
+ session_id=session_id,
25
+ ticker_scope=ticker_scope,
26
+ diagnostics=diagnostics,
27
+ proposal_state=proposal_state,
28
+ )
29
+ if not entries:
30
+ return {}
31
+
32
+ quant_dir = session_dir / "quant"
33
+ quant_dir.mkdir(parents=True, exist_ok=True)
34
+ stem = f"evidence_ledger_{run_id}"
35
+ json_path = quant_dir / f"{stem}.json"
36
+ md_path = quant_dir / f"{stem}.md"
37
+ payload = {
38
+ "run_id": run_id,
39
+ "session_id": session_id,
40
+ "created_at": datetime.now(tz=UTC).isoformat(),
41
+ "ticker_scope": ticker_scope,
42
+ "entries": entries,
43
+ }
44
+ json_path.write_text(json.dumps(payload, indent=2), encoding="utf-8")
45
+ md_path.write_text(_render_markdown(payload), encoding="utf-8")
46
+ return {
47
+ "json": f"quant/{stem}.json",
48
+ "markdown": f"quant/{stem}.md",
49
+ }
50
+
51
+
52
+ def _collect_entries(
53
+ session_dir: Path,
54
+ *,
55
+ run_id: str,
56
+ session_id: str,
57
+ ticker_scope: list[str],
58
+ diagnostics: dict[str, Any],
59
+ proposal_state: dict[str, Any],
60
+ ) -> list[dict[str, Any]]:
61
+ entries: list[dict[str, Any]] = []
62
+ created_at = datetime.now(tz=UTC).isoformat()
63
+ quant_dir = session_dir / "quant"
64
+ if quant_dir.exists():
65
+ for path in sorted(quant_dir.rglob("*")):
66
+ if not path.is_file():
67
+ continue
68
+ rel = path.relative_to(session_dir).as_posix()
69
+ if rel.startswith("quant/evidence_ledger_"):
70
+ continue
71
+ usage_state = "used"
72
+ data_gap_reason = ""
73
+ if "_data_quality" in path.name or "options_flow_" in path.name:
74
+ text = path.read_text(encoding="utf-8", errors="replace")
75
+ if "DATA_GAP" in text or "provider_partial_data" in text:
76
+ usage_state = "data_gap"
77
+ data_gap_reason = _first_gap_line(text)
78
+ entries.append({
79
+ "ledger_id": f"{run_id}:{len(entries)+1}",
80
+ "run_id": run_id,
81
+ "session_id": session_id,
82
+ "created_at": created_at,
83
+ "ticker_scope": ticker_scope,
84
+ "agent_role": _agent_role_for_artifact(rel),
85
+ "artifact_path": rel,
86
+ "evidence_type": _evidence_type_for_artifact(rel),
87
+ "source": "session_artifact",
88
+ "source_timestamp": _mtime_iso(path),
89
+ "freshness_state": "unknown",
90
+ "usage_state": usage_state,
91
+ "summary": path.name,
92
+ "linked_decision": proposal_state.get("status", ""),
93
+ "data_gap_reason": data_gap_reason,
94
+ })
95
+
96
+ for issue in diagnostics.get("issues") or []:
97
+ entries.append({
98
+ "ledger_id": f"{run_id}:{len(entries)+1}",
99
+ "run_id": run_id,
100
+ "session_id": session_id,
101
+ "created_at": created_at,
102
+ "ticker_scope": ticker_scope,
103
+ "agent_role": issue.get("agent", ""),
104
+ "artifact_path": "",
105
+ "evidence_type": "diagnostic",
106
+ "source": "yolo_diagnostics",
107
+ "source_timestamp": created_at,
108
+ "freshness_state": "unavailable" if issue.get("status") in {"data_gap", "llm_unavailable"} else "unknown",
109
+ "usage_state": "data_gap" if issue.get("status") == "data_gap" else "excluded",
110
+ "summary": issue.get("detail", ""),
111
+ "linked_decision": proposal_state.get("status", ""),
112
+ "data_gap_reason": issue.get("detail", "") if issue.get("status") == "data_gap" else "",
113
+ })
114
+ return entries
115
+
116
+
117
+ def _render_markdown(payload: dict[str, Any]) -> str:
118
+ lines = [
119
+ f"# Evidence Ledger - {payload['run_id']}",
120
+ "",
121
+ "Paper trading simulation only. Not financial advice.",
122
+ "",
123
+ f"Session: {payload['session_id']}",
124
+ f"Ticker scope: {', '.join(payload.get('ticker_scope') or [])}",
125
+ "",
126
+ "| Agent | Usage | Evidence | Artifact | Summary |",
127
+ "|---|---|---|---|---|",
128
+ ]
129
+ for entry in payload.get("entries") or []:
130
+ lines.append(
131
+ "| "
132
+ f"{entry.get('agent_role', '')} | "
133
+ f"{entry.get('usage_state', '')} | "
134
+ f"{entry.get('evidence_type', '')} | "
135
+ f"{entry.get('artifact_path', '')} | "
136
+ f"{str(entry.get('summary', '')).replace('|', '/')} |"
137
+ )
138
+ return "\n".join(lines) + "\n"
139
+
140
+
141
+ def _agent_role_for_artifact(path: str) -> str:
142
+ mapping = {
143
+ "raw/": "datafetcher",
144
+ "trend_analysis_": "trendanalyst",
145
+ "sentiment_analysis_": "sentimentanalyst",
146
+ "market_events_": "marketeventwatcher",
147
+ "options_flow_": "optionsflowwatcher",
148
+ "macro_context_": "macrocontextwatcher",
149
+ "unusual_events_": "unusualeventdetector",
150
+ "event_route_": "eventrouter",
151
+ "asset_analysis_": "assetanalyst",
152
+ "signals_": "quantresearcher",
153
+ "backtest_results_": "backtester",
154
+ "risk_assessment_": "riskanalyst",
155
+ "trade_proposals_": "quantstrategist",
156
+ "post_": "publisher",
157
+ "strategist_performance.json": "quantstrategist",
158
+ }
159
+ for marker, role in mapping.items():
160
+ if marker in path:
161
+ return role
162
+ return "unknown"
163
+
164
+
165
+ def _evidence_type_for_artifact(path: str) -> str:
166
+ if "/raw/" in path:
167
+ return "market_data"
168
+ if "options_flow_" in path:
169
+ return "options_flow"
170
+ if "macro_context_" in path:
171
+ return "macro_context"
172
+ if "trade_proposals_" in path:
173
+ return "proposal_state"
174
+ if "post_" in path:
175
+ return "finley_output"
176
+ return "agent_artifact"
177
+
178
+
179
+ def _first_gap_line(text: str) -> str:
180
+ for line in text.splitlines():
181
+ stripped = line.strip(" -")
182
+ if "DATA_GAP" in stripped or "provider_partial_data" in stripped:
183
+ return stripped
184
+ return "Evidence was unavailable or treated as a data gap."
185
+
186
+
187
+ def _mtime_iso(path: Path) -> str:
188
+ return datetime.fromtimestamp(path.stat().st_mtime, tz=UTC).isoformat()
src/polyhedra/services/strategist_performance.py CHANGED
@@ -84,11 +84,15 @@ class StrategistPerformanceTracker:
84
  """Aggregate votes by current weight and confidence."""
85
  confidence_multiplier = {"low": 0.6, "medium": 1.0, "high": 1.35}
86
  tally: dict[str, float] = {}
 
87
  for vote in votes:
88
  vote_value = str(vote.get("vote", "")).lower()
89
  confidence = str(vote.get("confidence", "medium")).lower()
90
  member_id = str(vote.get("member_id", ""))
91
- weight = float(vote.get("current_weight") or self.weights.get(member_id, 1.0))
 
 
 
92
  score = weight * confidence_multiplier.get(confidence, 1.0)
93
  tally[vote_value] = round(tally.get(vote_value, 0.0) + score, 3)
94
  leading_vote = ""
@@ -97,7 +101,8 @@ class StrategistPerformanceTracker:
97
  return {
98
  "tally": tally,
99
  "leading_vote": leading_vote,
100
- "method": "member current_weight multiplied by confidence multiplier",
 
101
  }
102
 
103
  def score_vote(
@@ -142,11 +147,14 @@ class StrategistPerformanceTracker:
142
  outcome: str,
143
  ) -> dict[str, Any]:
144
  member_id = str(vote.get("member_id", "")).strip() or "unknown_member"
 
145
  return {
146
  "member_id": member_id,
147
  "vote": str(vote.get("vote", "")).lower(),
148
  "confidence": str(vote.get("confidence", "medium")).lower(),
149
- "current_weight": float(vote.get("current_weight") or self.weights.get(member_id, 1.0)),
 
 
150
  "evidence_used": list(vote.get("evidence_used") or []),
151
  "rationale": str(vote.get("rationale", "")),
152
  "proposal_impact": str(vote.get("proposal_impact", "")),
 
84
  """Aggregate votes by current weight and confidence."""
85
  confidence_multiplier = {"low": 0.6, "medium": 1.0, "high": 1.35}
86
  tally: dict[str, float] = {}
87
+ ignored_members: list[str] = []
88
  for vote in votes:
89
  vote_value = str(vote.get("vote", "")).lower()
90
  confidence = str(vote.get("confidence", "medium")).lower()
91
  member_id = str(vote.get("member_id", ""))
92
+ if member_id not in self.weights:
93
+ ignored_members.append(member_id)
94
+ continue
95
+ weight = float(self.weights[member_id])
96
  score = weight * confidence_multiplier.get(confidence, 1.0)
97
  tally[vote_value] = round(tally.get(vote_value, 0.0) + score, 3)
98
  leading_vote = ""
 
101
  return {
102
  "tally": tally,
103
  "leading_vote": leading_vote,
104
+ "ignored_unknown_members": ignored_members,
105
+ "method": "session-owned member weight multiplied by confidence multiplier",
106
  }
107
 
108
  def score_vote(
 
147
  outcome: str,
148
  ) -> dict[str, Any]:
149
  member_id = str(vote.get("member_id", "")).strip() or "unknown_member"
150
+ known_member = member_id in self.weights
151
  return {
152
  "member_id": member_id,
153
  "vote": str(vote.get("vote", "")).lower(),
154
  "confidence": str(vote.get("confidence", "medium")).lower(),
155
+ "current_weight": float(self.weights.get(member_id, 0.0)),
156
+ "llm_reported_weight": vote.get("current_weight"),
157
+ "aggregation_status": "included" if known_member else "ignored_unknown_member",
158
  "evidence_used": list(vote.get("evidence_used") or []),
159
  "rationale": str(vote.get("rationale", "")),
160
  "proposal_impact": str(vote.get("proposal_impact", "")),
src/polyhedra/web/static/index.html CHANGED
@@ -239,6 +239,19 @@
239
  .session-row strong { display: block; font-size: 13px; }
240
  .session-row span { color: var(--muted); font-size: 12px; }
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  .status-pill {
243
  display: inline-flex;
244
  align-items: center;
@@ -256,6 +269,19 @@
256
  .status-pill.blocked { color: var(--warn); border-color: rgba(152, 104, 0, 0.35); }
257
  .status-pill.failed { color: var(--bad); border-color: rgba(180, 35, 24, 0.35); }
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  .actions {
260
  display: flex;
261
  gap: 10px;
@@ -320,6 +346,7 @@
320
  <div id="proposalState" class="proposal-state" style="display:none"></div>
321
  <div id="blockedDetail" class="blocked-detail"></div>
322
  <div id="statusPill" class="status-pill">idle</div>
 
323
  <div id="diagnostics" class="diagnostics"></div>
324
  <div id="progress" class="progress"></div>
325
  <div class="actions">
@@ -329,6 +356,12 @@
329
  </div>
330
  </div>
331
 
 
 
 
 
 
 
332
  <div class="panel section">
333
  <h2>Finley Output</h2>
334
  <pre id="finleyOutput">Finley has not posted a final output yet.</pre>
@@ -363,6 +396,7 @@
363
  const currentAgent = document.getElementById("currentAgent");
364
  const proposalStateEl = document.getElementById("proposalState");
365
  const blockedDetail = document.getElementById("blockedDetail");
 
366
  const diagnosticsEl = document.getElementById("diagnostics");
367
  const progress = document.getElementById("progress");
368
  const finleyOutput = document.getElementById("finleyOutput");
@@ -370,6 +404,8 @@
370
  const committeeMeta = document.getElementById("committeeMeta");
371
  const committeeVotes = document.getElementById("committeeVotes");
372
  const sessionsEl = document.getElementById("sessions");
 
 
373
  const downloadLink = document.getElementById("downloadLink");
374
  const systemStatus = document.getElementById("systemStatus");
375
 
@@ -390,6 +426,13 @@
390
  ? `Current agent: ${payload.current_agent.label}`
391
  : "Current agent: idle";
392
  renderProposalState(payload.proposal_state || {});
 
 
 
 
 
 
 
393
  blockedDetail.textContent = payload.blocked?.reason
394
  ? `Blocked at ${payload.blocked.label || payload.blocked.agent}: ${payload.blocked.reason}`
395
  : "";
@@ -501,6 +544,7 @@
501
  renderStatus(payload);
502
  startPolling(payload.session_id);
503
  await loadSessions();
 
504
  }
505
 
506
  async function startSessionRun() {
@@ -523,17 +567,27 @@
523
  renderStatus(payload);
524
  startPolling(payload.session_id);
525
  await loadSessions();
 
526
  }
527
 
528
- async function loadSession(sessionId) {
529
  const response = await fetch(`/api/sessions/${sessionId}`);
530
  if (!response.ok) return;
531
  renderStatus(await response.json());
 
 
 
 
 
 
 
 
 
532
  }
533
 
534
  function startPolling(sessionId) {
535
  window.clearInterval(pollTimer);
536
- pollTimer = window.setInterval(() => loadSession(sessionId), 2000);
537
  }
538
 
539
  async function refreshActive() {
@@ -543,6 +597,34 @@
543
  await loadSessions();
544
  }
545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
  async function loadSessions() {
547
  const response = await fetch("/api/sessions");
548
  if (!response.ok) return;
 
239
  .session-row strong { display: block; font-size: 13px; }
240
  .session-row span { color: var(--muted); font-size: 12px; }
241
 
242
+ .run-row {
243
+ border: 1px solid var(--line);
244
+ border-radius: 7px;
245
+ padding: 10px;
246
+ background: #fbfcfd;
247
+ cursor: pointer;
248
+ font-size: 13px;
249
+ }
250
+
251
+ .run-row:hover { border-color: var(--accent); }
252
+ .run-row strong { display: block; }
253
+ .run-row span { color: var(--muted); display: block; margin-top: 4px; font-size: 12px; }
254
+
255
  .status-pill {
256
  display: inline-flex;
257
  align-items: center;
 
269
  .status-pill.blocked { color: var(--warn); border-color: rgba(152, 104, 0, 0.35); }
270
  .status-pill.failed { color: var(--bad); border-color: rgba(180, 35, 24, 0.35); }
271
 
272
+ .replay-banner {
273
+ display: none;
274
+ margin-top: 10px;
275
+ border: 1px solid rgba(15, 123, 108, 0.25);
276
+ border-left: 4px solid var(--accent);
277
+ border-radius: 7px;
278
+ padding: 10px;
279
+ color: var(--accent);
280
+ background: #f5fffc;
281
+ font-size: 13px;
282
+ font-weight: 700;
283
+ }
284
+
285
  .actions {
286
  display: flex;
287
  gap: 10px;
 
346
  <div id="proposalState" class="proposal-state" style="display:none"></div>
347
  <div id="blockedDetail" class="blocked-detail"></div>
348
  <div id="statusPill" class="status-pill">idle</div>
349
+ <div id="replayBanner" class="replay-banner"></div>
350
  <div id="diagnostics" class="diagnostics"></div>
351
  <div id="progress" class="progress"></div>
352
  <div class="actions">
 
356
  </div>
357
  </div>
358
 
359
+ <div class="panel section">
360
+ <h2>Prior Runs</h2>
361
+ <p id="runReplayMeta" class="meta">Select a session to replay recorded YOLO runs.</p>
362
+ <div id="runReplayList" class="sessions"></div>
363
+ </div>
364
+
365
  <div class="panel section">
366
  <h2>Finley Output</h2>
367
  <pre id="finleyOutput">Finley has not posted a final output yet.</pre>
 
396
  const currentAgent = document.getElementById("currentAgent");
397
  const proposalStateEl = document.getElementById("proposalState");
398
  const blockedDetail = document.getElementById("blockedDetail");
399
+ const replayBanner = document.getElementById("replayBanner");
400
  const diagnosticsEl = document.getElementById("diagnostics");
401
  const progress = document.getElementById("progress");
402
  const finleyOutput = document.getElementById("finleyOutput");
 
404
  const committeeMeta = document.getElementById("committeeMeta");
405
  const committeeVotes = document.getElementById("committeeVotes");
406
  const sessionsEl = document.getElementById("sessions");
407
+ const runReplayMeta = document.getElementById("runReplayMeta");
408
+ const runReplayList = document.getElementById("runReplayList");
409
  const downloadLink = document.getElementById("downloadLink");
410
  const systemStatus = document.getElementById("systemStatus");
411
 
 
426
  ? `Current agent: ${payload.current_agent.label}`
427
  : "Current agent: idle";
428
  renderProposalState(payload.proposal_state || {});
429
+ if (payload.replay) {
430
+ replayBanner.textContent = payload.replay_label || "Prior YOLO run replay - UI-only.";
431
+ replayBanner.style.display = "block";
432
+ } else {
433
+ replayBanner.textContent = "";
434
+ replayBanner.style.display = "none";
435
+ }
436
  blockedDetail.textContent = payload.blocked?.reason
437
  ? `Blocked at ${payload.blocked.label || payload.blocked.agent}: ${payload.blocked.reason}`
438
  : "";
 
544
  renderStatus(payload);
545
  startPolling(payload.session_id);
546
  await loadSessions();
547
+ await loadRuns(payload.session_id);
548
  }
549
 
550
  async function startSessionRun() {
 
567
  renderStatus(payload);
568
  startPolling(payload.session_id);
569
  await loadSessions();
570
+ await loadRuns(payload.session_id);
571
  }
572
 
573
+ async function loadSession(sessionId, includeRuns = true) {
574
  const response = await fetch(`/api/sessions/${sessionId}`);
575
  if (!response.ok) return;
576
  renderStatus(await response.json());
577
+ if (includeRuns) await loadRuns(sessionId);
578
+ }
579
+
580
+ async function loadRun(sessionId, runId) {
581
+ const response = await fetch(`/api/sessions/${sessionId}/runs/${runId}`);
582
+ if (!response.ok) return;
583
+ window.clearInterval(pollTimer);
584
+ pollTimer = 0;
585
+ renderStatus(await response.json());
586
  }
587
 
588
  function startPolling(sessionId) {
589
  window.clearInterval(pollTimer);
590
+ pollTimer = window.setInterval(() => loadSession(sessionId, false), 2000);
591
  }
592
 
593
  async function refreshActive() {
 
597
  await loadSessions();
598
  }
599
 
600
+ async function loadRuns(sessionId) {
601
+ const response = await fetch(`/api/sessions/${sessionId}/runs`);
602
+ if (!response.ok) {
603
+ runReplayMeta.textContent = "Recorded YOLO runs are unavailable for this session.";
604
+ runReplayList.innerHTML = "";
605
+ return;
606
+ }
607
+ const payload = await response.json();
608
+ const runs = payload.runs || [];
609
+ runReplayMeta.textContent = runs.length
610
+ ? "Replay shows recorded prior-run output only; it does not rerun agents or claim frozen replay."
611
+ : "No recorded YOLO runs for this session yet.";
612
+ runReplayList.innerHTML = runs.slice(0, 12).map((run) => {
613
+ const runId = escapeHtml(run.run_id || "");
614
+ const mode = escapeHtml(run.run_mode_label || run.run_mode || "YOLO");
615
+ const status = escapeHtml(run.status || "");
616
+ const recorded = escapeHtml(run.recorded_at || "");
617
+ const proposal = escapeHtml(run.proposal_state?.label || "");
618
+ return `<div class="run-row" data-run="${runId}">
619
+ <strong>${mode} - ${status}</strong>
620
+ <span>${runId} | ${recorded} | ${proposal}</span>
621
+ </div>`;
622
+ }).join("") || `<p class="meta">No prior YOLO run snapshots found.</p>`;
623
+ runReplayList.querySelectorAll(".run-row").forEach((row) => {
624
+ row.addEventListener("click", () => loadRun(sessionId, row.dataset.run));
625
+ });
626
+ }
627
+
628
  async function loadSessions() {
629
  const response = await fetch("/api/sessions");
630
  if (!response.ok) return;
tests/test_v611_web_ui.py CHANGED
@@ -1,6 +1,7 @@
1
  from __future__ import annotations
2
 
3
  import io
 
4
  import sys
5
  import types
6
  import zipfile
@@ -17,6 +18,7 @@ from polyhedra.core import session as session_module # noqa: E402
17
  from polyhedra.core.research_state import QuantState, ResearchStateManager # noqa: E402
18
  from polyhedra.core.session import SessionManager # noqa: E402
19
  from polyhedra.core.yolo_context import prepare_yolo_run_context # noqa: E402
 
20
 
21
 
22
  def _client(tmp_path: Path, monkeypatch) -> TestClient:
@@ -445,6 +447,9 @@ def test_v7_ui_contains_current_agent_and_committee_panels(
445
  assert 'id="proposalState"' in html
446
  assert 'id="blockedDetail"' in html
447
  assert 'id="diagnostics"' in html
 
 
 
448
  assert 'id="committeeVotes"' in html
449
  assert "QuantStrategists" in html
450
  assert "Paper trading simulation only." in html
@@ -467,6 +472,86 @@ def test_v7_export_includes_committee_artifact(tmp_path: Path, monkeypatch) -> N
467
  assert "quant/strategist_performance.json" in archive.namelist()
468
 
469
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
470
  def test_v7_delta_mode_preserves_v6_workflow_nodes(tmp_path: Path, monkeypatch) -> None:
471
  client = _client(tmp_path, monkeypatch)
472
  session = SessionManager().create(goal="YOLO & SPY Analysis Session", platform="web")
 
1
  from __future__ import annotations
2
 
3
  import io
4
+ import json
5
  import sys
6
  import types
7
  import zipfile
 
18
  from polyhedra.core.research_state import QuantState, ResearchStateManager # noqa: E402
19
  from polyhedra.core.session import SessionManager # noqa: E402
20
  from polyhedra.core.yolo_context import prepare_yolo_run_context # noqa: E402
21
+ from polyhedra.services.evidence_ledger import write_evidence_ledger # noqa: E402
22
 
23
 
24
  def _client(tmp_path: Path, monkeypatch) -> TestClient:
 
447
  assert 'id="proposalState"' in html
448
  assert 'id="blockedDetail"' in html
449
  assert 'id="diagnostics"' in html
450
+ assert 'id="runReplayList"' in html
451
+ assert "Prior Runs" in html
452
+ assert "does not rerun agents" in html
453
  assert 'id="committeeVotes"' in html
454
  assert "QuantStrategists" in html
455
  assert "Paper trading simulation only." in html
 
472
  assert "quant/strategist_performance.json" in archive.namelist()
473
 
474
 
475
+ def test_v71_session_run_replay_api_reads_recorded_snapshot_only(
476
+ tmp_path: Path,
477
+ monkeypatch,
478
+ ) -> None:
479
+ client = _client(tmp_path, monkeypatch)
480
+ session = SessionManager().create(goal="YOLO & SPY Analysis Session", platform="web")
481
+ run_dir = session.session_dir / "yolo_runs"
482
+ run_dir.mkdir()
483
+ run_payload = {
484
+ "session_id": session.session_id,
485
+ "run_id": "20260904_010203",
486
+ "goal": session.goal,
487
+ "status": "completed",
488
+ "workflow": "V6 specialized quant path",
489
+ "run_mode": "baseline",
490
+ "run_mode_label": "Baseline YOLO",
491
+ "path": [{"role": "publisher", "label": "Finley", "status": "completed"}],
492
+ "finley": {"from_role": "publisher", "content": "Recorded Finley output."},
493
+ "proposal_state": {"status": "true_no_trade_or_watch", "label": "True No-Trade / Watch"},
494
+ "recorded_at": "2026-09-04T01:02:03+00:00",
495
+ "replay_label": "Prior YOLO run replay - UI-only, not deterministic/frozen replay.",
496
+ }
497
+ (run_dir / "20260904_010203.json").write_text(json.dumps(run_payload), encoding="utf-8")
498
+
499
+ list_response = client.get(f"/api/sessions/{session.session_id}/runs")
500
+ detail_response = client.get(f"/api/sessions/{session.session_id}/runs/20260904_010203")
501
+
502
+ listed = list_response.json()["runs"][0]
503
+ detail = detail_response.json()
504
+ assert list_response.status_code == 200
505
+ assert detail_response.status_code == 200
506
+ assert listed["run_mode_label"] == "Baseline YOLO"
507
+ assert detail["replay"] is True
508
+ assert detail["finley"]["content"] == "Recorded Finley output."
509
+ assert "not deterministic/frozen replay" in detail["replay_label"]
510
+
511
+
512
+ def test_v71_evidence_ledger_writer_records_data_gap_and_export(
513
+ tmp_path: Path,
514
+ monkeypatch,
515
+ ) -> None:
516
+ client = _client(tmp_path, monkeypatch)
517
+ session = SessionManager().create(goal="YOLO & SPY Analysis Session", platform="web")
518
+ quant_dir = session.session_dir / "quant"
519
+ quant_dir.mkdir()
520
+ (quant_dir / "options_flow_2026-09-04.md").write_text(
521
+ "DATA_GAP. Options evidence is excluded from signal weighting.",
522
+ encoding="utf-8",
523
+ )
524
+
525
+ paths = write_evidence_ledger(
526
+ session.session_dir,
527
+ run_id="20260904_010203",
528
+ session_id=session.session_id,
529
+ ticker_scope=["SPY"],
530
+ diagnostics={
531
+ "issues": [
532
+ {
533
+ "agent": "optionsflowwatcher",
534
+ "status": "data_gap",
535
+ "detail": "DATA_GAP. Options evidence is excluded from signal weighting.",
536
+ }
537
+ ]
538
+ },
539
+ proposal_state={"status": "data_loss"},
540
+ )
541
+ export_response = client.get(f"/api/sessions/{session.session_id}/export")
542
+
543
+ assert paths == {
544
+ "json": "quant/evidence_ledger_20260904_010203.json",
545
+ "markdown": "quant/evidence_ledger_20260904_010203.md",
546
+ }
547
+ ledger = json.loads((session.session_dir / paths["json"]).read_text(encoding="utf-8"))
548
+ assert any(entry["usage_state"] == "data_gap" for entry in ledger["entries"])
549
+ assert all(entry["summary"] for entry in ledger["entries"])
550
+ with zipfile.ZipFile(io.BytesIO(export_response.content)) as archive:
551
+ assert paths["json"] in archive.namelist()
552
+ assert paths["markdown"] in archive.namelist()
553
+
554
+
555
  def test_v7_delta_mode_preserves_v6_workflow_nodes(tmp_path: Path, monkeypatch) -> None:
556
  client = _client(tmp_path, monkeypatch)
557
  session = SessionManager().create(goal="YOLO & SPY Analysis Session", platform="web")
tests/test_yolo_context.py CHANGED
@@ -411,7 +411,7 @@ def test_strategist_performance_tracker_aggregates_by_weight_and_confidence(
411
  "member_id": "risk_skeptic",
412
  "vote": "watch",
413
  "confidence": "high",
414
- "current_weight": 1.2,
415
  "evidence_used": ["risk"],
416
  "rationale": "Wait for confirmation.",
417
  "proposal_impact": "Watch.",
@@ -432,6 +432,47 @@ def test_strategist_performance_tracker_aggregates_by_weight_and_confidence(
432
 
433
  assert committee["aggregation"]["leading_vote"] == "watch"
434
  assert committee["aggregation"]["tally"]["watch"] > committee["aggregation"]["tally"]["bullish"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
 
436
 
437
  def test_strategist_performance_tracker_updates_member_weight(tmp_path: Path) -> None:
 
411
  "member_id": "risk_skeptic",
412
  "vote": "watch",
413
  "confidence": "high",
414
+ "current_weight": 1.8,
415
  "evidence_used": ["risk"],
416
  "rationale": "Wait for confirmation.",
417
  "proposal_impact": "Watch.",
 
432
 
433
  assert committee["aggregation"]["leading_vote"] == "watch"
434
  assert committee["aggregation"]["tally"]["watch"] > committee["aggregation"]["tally"]["bullish"]
435
+ assert committee["votes"][0]["current_weight"] == 1.0
436
+ assert committee["votes"][0]["llm_reported_weight"] == 1.8
437
+
438
+
439
+ def test_strategist_performance_tracker_ignores_unknown_members_in_aggregation(
440
+ tmp_path: Path,
441
+ ) -> None:
442
+ files = FileWriter(tmp_path)
443
+ tracker = StrategistPerformanceTracker.load(files)
444
+
445
+ committee = tracker.record_votes(
446
+ files,
447
+ [
448
+ {
449
+ "member_id": "unknown_macro_star",
450
+ "vote": "bullish",
451
+ "confidence": "high",
452
+ "current_weight": 99.0,
453
+ "evidence_used": ["unsupported"],
454
+ "rationale": "LLM invented this member.",
455
+ "proposal_impact": "Should not affect tally.",
456
+ },
457
+ {
458
+ "member_id": "risk_skeptic",
459
+ "vote": "watch",
460
+ "confidence": "medium",
461
+ "current_weight": 1.0,
462
+ "evidence_used": ["risk"],
463
+ "rationale": "Wait for confirmation.",
464
+ "proposal_impact": "Watch.",
465
+ },
466
+ ],
467
+ run_mode="session_delta",
468
+ outcome="WATCH_FOR_CONFIRMATION",
469
+ )
470
+
471
+ assert committee["aggregation"]["leading_vote"] == "watch"
472
+ assert "bullish" not in committee["aggregation"]["tally"]
473
+ assert committee["aggregation"]["ignored_unknown_members"] == ["unknown_macro_star"]
474
+ assert committee["votes"][0]["aggregation_status"] == "ignored_unknown_member"
475
+ assert committee["votes"][0]["current_weight"] == 0.0
476
 
477
 
478
  def test_strategist_performance_tracker_updates_member_weight(tmp_path: Path) -> None: