fix: hands-on bugs found during pre-submission audit

API + data integrity
- /api/settings GET no longer leaks the active Anthropic API key — returns a
  masked preview (sk-ant-XX…YYYY) plus a boolean `anthropic_api_key_set` flag
- /api/settings POST won't overwrite a real key with the masked placeholder
  the client receives back on GET (length<30 / "…" / "..." / "***" markers
  trigger a preserve-existing path)
- /api/best_result, /api/status, _make_run_dict, _result_to_dict, all AI-loop
  emits, validation_run_complete, optimization_complete, ai_iteration_complete,
  ai_targets_met, run_complete: max_drawdown and win_rate are now consistently
  emitted as PERCENTAGES (0–100), matching the dashboard's existing display
  formatters. They were previously emitted as fractions (0.13 = 13%) so the UI
  rendered "0.13%" instead of "13%"
- ResultRanker.make_result() now sets `passing` and `raw_score` on every result
  it produces. Previously these were only set during a full ranker.rank() pass,
  so individual Phase 2 / Phase 3 runs hit _make_run_dict with passing=False
  even when they cleared all gates (history showed "0 passing" when 22/22
  actually passed)
This commit is contained in:
LEGSTECH Optimizer
2026-04-25 11:55:22 +00:00
parent 6caafdb794
commit 746ab8fb11
4 changed files with 72 additions and 28 deletions
+8 -8
View File
@@ -142,7 +142,7 @@ class AIGuidedLoop:
self._emit("ai_targets_met", {
"iteration": iteration - 1,
"profit_factor": round(self.best_result.profit_factor, 3),
"max_drawdown": round(self.best_result.max_drawdown, 2),
"max_drawdown": round(self.best_result.max_drawdown * 100, 2),
"calmar": round(self.best_result.calmar, 3),
})
self.pipeline._emit_early_termination(
@@ -151,7 +151,7 @@ class AIGuidedLoop:
details={
"iteration": iteration - 1,
"profit_factor": round(self.best_result.profit_factor, 3),
"max_drawdown": round(self.best_result.max_drawdown, 2),
"max_drawdown": round(self.best_result.max_drawdown * 100, 2),
"calmar": round(self.best_result.calmar, 3),
},
)
@@ -298,7 +298,7 @@ class AIGuidedLoop:
kind="warning", iteration=iteration,
)
# Emit iteration complete
# Emit iteration complete (max_drawdown emitted as %)
self._emit("ai_iteration_complete", {
"iteration": iteration,
"max_iterations": max_iterations,
@@ -306,10 +306,10 @@ class AIGuidedLoop:
"score": round(result.score, 4),
"profit_factor": round(result.profit_factor, 3),
"calmar": round(result.calmar, 3),
"max_drawdown": round(result.max_drawdown, 2),
"max_drawdown": round(result.max_drawdown * 100, 2),
"net_profit": round(result.net_profit, 2),
"total_trades": result.total_trades,
"passing": result.passing,
"passing": bool(result.passing),
"best_score": round(self.best_result.score, 4) if self.best_result else 0,
"best_pf": round(self.best_result.profit_factor, 3) if self.best_result else 0,
"best_calmar": round(self.best_result.calmar, 3) if self.best_result else 0,
@@ -327,10 +327,10 @@ class AIGuidedLoop:
"net_profit": round(result.net_profit, 2),
"calmar": round(result.calmar, 3),
"profit_factor": round(result.profit_factor, 3),
"win_rate": round(result.win_rate, 1),
"max_drawdown": round(result.max_drawdown, 2),
"win_rate": round(result.win_rate * 100, 1),
"max_drawdown": round(result.max_drawdown * 100, 2),
"total_trades": result.total_trades,
"passing": result.passing,
"passing": bool(result.passing),
"score": round(result.score, 4),
"progress_pct": round(self.pipeline._run_count / max(self.pipeline._total_runs, 1) * 100),
})