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
@@ -275,3 +275,27 @@ async def test_real_agent_runner_predict_roundtrips_predictions(tmp_path: Path)
"smoke_r0", question_ids=["smoke"]
)
assert rows and rows[0]["prediction"] == "B"
@pytest.mark.asyncio
async def test_real_agent_runner_predict_fills_none_for_missing(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""predict 对 predictions 表缺失的 qid 返回 None(契约:每个入参 qid 都有键)。"""
async def _noop_run_inference(*args: Any, **kwargs: Any) -> None:
"""空跑:不写 predictions 表,模拟回读缺行。"""
return None
monkeypatch.setattr("app.harness.inference.run_inference", _noop_run_inference)
runner = _RealAgentRunner(
llm=_MockLLM(answer="B"),
tool_dispatch_fn=lambda *a, **k: None,
prompt_builder=lambda q: ("s", "u"),
db_path=str(tmp_path / "harness.db"),
concurrency=1,
skill_mode="none",
model="mock",
)
preds = await runner.predict([_smoke_q("missing")], max_steps=1, run_id="r_none")
assert preds == {"missing": None} # 缺回读行 → 该 qid 键存在且为 None
+26
View File
@@ -163,3 +163,29 @@ async def test_rounds_backfill_then_stop_at_max(tmp_path):
ids = {d["question_id"] for d in json.loads(final_path.read_text(encoding="utf-8"))}
assert "q0" in ids and any(x.startswith("bf0_") for x in ids)
store.close()
@pytest.mark.asyncio
async def test_rounds_tolerate_backfill_under_delivery(tmp_path):
"""backfill 欠产(实得 < deficit,被 gate 拒常态)→ 不崩,并入实得题,达上限停。"""
store = QuestionGenStore(str(tmp_path / "q.db"))
agent = _FakeAgent(pred="B")
# 每轮只产出 deficit-1 道(模拟部分题被 gate 拒的真实欠产)
backfill = _CountingBackfill(lambda d, r: [_q(f"bf{r}_{i}") for i in range(max(d - 1, 0))])
final_path = tmp_path / "accepted_questions_final.json"
await run_adversarial_rounds(
[_q("q0")],
agent=agent,
vlm=object(),
store=store,
trees={},
config=AdversarialFilterConfig(adversarial_max_rounds=3),
final_path=final_path,
target=99, # 永远达不到 → 靠 max_rounds 终止,不因欠产崩溃或死循环
backfill=backfill,
session_id="s",
)
assert backfill.calls == 2 # round0/round1 各补一次;round2 达上限 break
ids = {d["question_id"] for d in json.loads(final_path.read_text(encoding="utf-8"))}
assert "q0" in ids and any(x.startswith("bf0_") for x in ids) # 实得欠产题已并入
store.close()