fix: correctly accumulate historical metrics from branch and clean Gemini failures from report

This commit is contained in:
Nubenetes Bot
2026-05-13 09:37:06 +02:00
parent f2b064e9a8
commit a788992459
2 changed files with 31 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import json
import base64
from github import Github
from datetime import datetime
@@ -12,6 +13,13 @@ class RepositoryController:
base_branch = self.repository.get_branch(self.default_branch_name)
self.repository.create_git_ref(ref=f"refs/heads/{branch_name}", sha=base_branch.commit.sha)
def get_file_from_branch(self, file_path: str, branch_name: str) -> str:
try:
file_meta = self.repository.get_contents(file_path, ref=branch_name)
return base64.b64decode(file_meta.content).decode("utf-8")
except:
return ""
def apply_historical_chunk(self, updates: dict, next_since: str) -> None:
branch_name = "bot/historical-accumulator"

View File

@@ -130,12 +130,29 @@ async def master_orchestrator():
# 5. Gestión de Métricas Acumulativas (Para reporte final)
metrics_file = "src/memory/historical_metrics.json"
accumulated_report = full_extraction_report
if is_historical and os.path.exists(metrics_file):
try:
with open(metrics_file, 'r') as f:
prev_metrics = json.load(f)
accumulated_report.extend(prev_metrics.get("full_report", []))
except: pass
# Intentar cargar métricas previas (Local o desde la rama accumulator)
prev_metrics = None
if is_historical:
if os.path.exists(metrics_file):
try:
with open(metrics_file, 'r') as f: prev_metrics = json.load(f)
except: pass
else:
# Intentar desde la rama
acc_content = git_controller.get_file_from_branch(metrics_file, "bot/historical-accumulator")
if acc_content:
try: prev_metrics = json.loads(acc_content)
except: pass
if prev_metrics:
# Filtrar fallos críticos de Gemini del histórico para no "ensuciar" el reporte final
# y permitir que se re-intenten si el tramo se solapa.
clean_prev_report = [
item for item in prev_metrics.get("full_report", [])
if "Fallo crítico Gemini" not in item.get("reason", "")
]
accumulated_report.extend(clean_prev_report)
metrics = {
"total_extracted": len(accumulated_report),