Wenchao An 1b76ab9060
feat: add opt-in task notes and compacted history recall (#5382)
* feat: add opt-in task notes and compacted history recall

* fix: validate task continuity state and preserve user answers

Honor explicit opt-out, preserve clarification replies and capture failure statuses, validate notebook writes, and clear branch archive references. Update the config version and audit optional LLM credentials, with regression and integration evidence.

* fix: align Helm config version with task continuity schema

* fix: preserve mixed task history and declare continuity policies

* fix: recover malformed history and evict archives atomically
2026-09-12 21:01:46 +08:00

50 lines
2.4 KiB
Python

from __future__ import annotations
import argparse
import asyncio
import json
from common import PROTOCOL, ROOT, LiveClient, digest, tokens, write_json
from prepare import render_history
from public_eval import READER_SYSTEM, grade
async def run(args):
entries = json.loads((ROOT/"public-manifest.json").read_text())["test"]
diagnostic = json.loads((ROOT/"diagnostic-protocol.json").read_text())
client = LiveClient(args.endpoints, concurrency=2)
sem = asyncio.Semaphore(2)
async def one(entry):
async with sem:
cid=entry["id"]
try:
case=json.loads((ROOT/"cases/public"/f"{cid}.json").read_text())
gold=json.loads((ROOT/"gold/public"/f"{cid}.json").read_text())
sessions=set(map(str,gold["evidence_sessions"]))
history=render_history([r for r in case["records"] if r["session_id"] in sessions])
messages=[{"role":"system","content":READER_SYSTEM},
{"role":"user","content":f"<historical_context>\n{history}\n</historical_context>\n\nQuestion date: {case['question_date']}\nCurrent question: {case['question']}"}]
answer=await client.chat(messages,max_tokens=PROTOCOL["answer_max_output_tokens"],tag=f"{cid}:oracle_reader")
prediction=answer["message"].get("content") or ""
judgement=await grade(case,gold,prediction,client)
row={"id":cid,"abstention":gold["abstention"],"prediction":prediction,"grade":judgement,
"reader_metrics":answer["metrics"],"context_tokens_proxy":tokens(history),
"diagnostic_protocol_hash":digest(diagnostic),"reader_request":answer["request_hash"]}
write_json(ROOT/"results/oracle"/f"{cid}.json",row)
print(f"oracle_done {cid} {int(judgement['correct'])}",flush=True)
return row
except Exception as exc:
result={"id":cid,"error_type":type(exc).__name__,"message":str(exc)}
write_json(ROOT/"results/oracle_failures"/f"{cid}.json",result)
return result
try:
rows=await asyncio.gather(*(one(e) for e in entries))
write_json(ROOT/"results/oracle-run.json",{"rows":rows,"calls":client.calls})
finally:
await client.close()
if __name__=="__main__":
p=argparse.ArgumentParser();p.add_argument("--endpoints",required=True)
asyncio.run(run(p.parse_args()))