fix: tolerate backfill under-delivery, fix predict None-fill, drop dead session_id

This commit is contained in:
2026-07-14 17:07:55 -04:00
parent 1d222d9f18
commit f36eb66c18
4 changed files with 68 additions and 6 deletions
+18 -5
View File
@@ -756,9 +756,18 @@ async def run_adversarial_rounds(
if deficit <= 0 or round_no + 1 >= config.adversarial_max_rounds:
break
new_qs = await backfill(deficit, round_no, all_questions)
assert len(new_qs) == deficit, (
f"backfill 应产出 {deficit} 题,实得 {len(new_qs)}(缺额驱动契约)"
# 真实 backfill 经 run_pipeline_v2 只返回过门的题:部分题被 gate 拒 = 常态欠产。
# 容忍 len(new_qs) <= deficit——欠产先并入,deficit 下轮重算继续补,max_rounds 兜底
# 防死循环。多产(> deficit)才是契约被破坏的 bug,保留 sanity 断言。
assert len(new_qs) <= deficit, (
f"backfill 多产: 需 {deficit} 实得 {len(new_qs)}(超额 = 契约被破坏)"
)
if len(new_qs) < deficit:
logger.warning(
"backfill 欠产: 需 {} 实得 {},本轮先并入,后续轮次继续补",
deficit,
len(new_qs),
)
for q in new_qs:
all_questions[q.question_id] = q
pending = new_qs # 只对新补的题重新过滤(已判题走续跑)
@@ -843,7 +852,12 @@ class _RealAgentRunner:
rows = await RunLogImpl(self._db_path).get_predictions(
run_id, question_ids=[q.question_id for q in questions]
)
return {r["question_id"]: r["prediction"] for r in rows}
# 契约:每个入参 qid 都必须有键。先全填 None,再用回读行覆盖——回读缺行
# agent 未落库/异常)的 qid 保持 None,不静默丢键。
preds: dict[str, str | None] = {q.question_id: None for q in questions}
for r in rows:
preds[r["question_id"]] = r["prediction"]
return preds
# ---------------------------------------------------------------------------
@@ -873,7 +887,6 @@ def build_backfill(
store: QuestionGenStore,
pipeline_config: PipelineConfig,
filter_task_types: tuple[str, ...],
session_id: str,
) -> BackfillFn:
"""组装真实 backfill 回调 — 缺额驱动 run_pipeline_v2,返回新增 AR 题。
@@ -883,6 +896,7 @@ def build_backfill(
- initial_embed_pool = 已有题 embedding(跨 run 去重);
- seq_offset = 已有题最大 seq(新题续编,防撞 question_id)。
仅补 filter_task_types(当前锁定为 AR 单类),返回 PipelineResult.accepted。
session/run_id 由 run_pipeline_v2 内部自生成,故本层不接受 session_id。
参数:
trees: video_id → 三层树索引(生成素材来源)。
@@ -892,7 +906,6 @@ def build_backfill(
store: 出题持久化。
pipeline_config: ar30 原配置(除 per_type 外全部继承)。
filter_task_types: 补生成的题型(仅这些)。
session_id: 遥测会话 ID(透传给管线子调用)。
返回:
BackfillFn 闭包。