feat(eval): memoir A/B chapter judging and eval-web parity with dialogue
- Judge baseline excerpt and library chapter separately; build_memoir_compare_summary for gate, nine-dim and leaf deltas. - Memoir SSE chapter payload: baseline_judge, compare_summary, baseline_judge_error. - MemoirJudgeOutput: loose score coercion and post-validate clamp; memoir judge prompt caps from settings. - app-eval-web: two-column MemoirScoreCard layout, MemoirCompareSummary, chapter blocks and CSS. - Add memoir_compare_summary, log_events, celery_log_context, memoir_pipeline_progress; tests and migration 0014. - Misc: memory/evidence and enrichment paths, task/orchestrator updates, internal-eval docs, env examples.
This commit is contained in:
@@ -28,6 +28,7 @@ logger = get_logger(__name__)
|
||||
@shared_task
|
||||
def memory_compaction_sweep() -> dict[str, Any]:
|
||||
"""Beat:为近期有记忆写入的用户调度 compaction(debounce 仍由 schedule 合并)。"""
|
||||
t0 = time.perf_counter()
|
||||
if not settings.memory_compaction_enabled:
|
||||
return {"skipped": True, "reason": "disabled"}
|
||||
hours = int(settings.memory_compaction_sweep_recent_hours)
|
||||
@@ -36,8 +37,13 @@ def memory_compaction_sweep() -> dict[str, Any]:
|
||||
ctx_base: dict[str, Any] = {"trigger_source": "beat", "sweep_hours": hours}
|
||||
for uid in user_ids:
|
||||
schedule_memory_compaction_run(uid, dict(ctx_base))
|
||||
ms = (time.perf_counter() - t0) * 1000
|
||||
logger.info(
|
||||
"memory_compaction_sweep hours={} scheduled_users={}", hours, len(user_ids)
|
||||
"event=memory_compaction_sweep_done hours={} scheduled_users={} duration_ms={:.1f} "
|
||||
"msg=记忆压缩定时扫描已调度",
|
||||
hours,
|
||||
len(user_ids),
|
||||
ms,
|
||||
)
|
||||
return {"scheduled": len(user_ids), "user_ids": user_ids}
|
||||
|
||||
@@ -46,6 +52,7 @@ def memory_compaction_sweep() -> dict[str, Any]:
|
||||
def memory_compaction_run(
|
||||
self, user_id: str, context: dict[str, Any] | None = None
|
||||
) -> dict[str, Any]:
|
||||
run_t0 = time.perf_counter()
|
||||
if not settings.memory_compaction_enabled:
|
||||
return {"skipped": True, "reason": "disabled"}
|
||||
|
||||
@@ -61,9 +68,12 @@ def memory_compaction_run(
|
||||
ttl_seconds=settings.memory_compaction_lock_ttl_seconds,
|
||||
)
|
||||
if lock is None:
|
||||
ms = (time.perf_counter() - run_t0) * 1000
|
||||
logger.info(
|
||||
"memory_compaction_skipped user_id={} skipped_reason=lock_not_acquired",
|
||||
"event=memory_compaction_skipped user_id={} reason=lock_not_acquired "
|
||||
"duration_ms={:.1f} msg=记忆压缩跳过(未拿到锁)",
|
||||
user_id,
|
||||
ms,
|
||||
)
|
||||
out = {"skipped": True, "reason": "lock_not_acquired"}
|
||||
finalize_memory_compaction_run(
|
||||
@@ -89,10 +99,23 @@ def memory_compaction_run(
|
||||
observed_deadline_ts=deadline,
|
||||
context=ctx,
|
||||
)
|
||||
ms = (time.perf_counter() - run_t0) * 1000
|
||||
logger.info(
|
||||
"event=memory_compaction_done user_id={} duration_ms={:.1f} msg=记忆压缩运行完成",
|
||||
user_id,
|
||||
ms,
|
||||
)
|
||||
return out
|
||||
except Exception as exc:
|
||||
logger.warning("memory_compaction_run failed user_id={} err={}", user_id, exc)
|
||||
ms = (time.perf_counter() - run_t0) * 1000
|
||||
logger.warning(
|
||||
"event=memory_compaction_failed user_id={} duration_ms={:.1f} err={} "
|
||||
"msg=记忆压缩运行失败",
|
||||
user_id,
|
||||
ms,
|
||||
exc,
|
||||
)
|
||||
release_scheduler_gate(user_id)
|
||||
raise self.retry(exc=exc)
|
||||
raise self.retry(exc=exc) from exc
|
||||
finally:
|
||||
release_redis_lock(lock)
|
||||
|
||||
Reference in New Issue
Block a user