Commit f33c4a50 authored by 郭阔's avatar 郭阔

feat(harvest): merge delivered articles across retry attempts

When attempt1 delivers data but fails structured reporting, the final
attempt fast-exits all_seen with 0 articles — the record then showed
nothing delivered, leaving the operator to guess. After the attempt loop,
merge earlier attempts' delivered articles (URL-deduped, archive_path
required) into the final envelope, recompute counts, and record each
attempt's contribution in warnings. Single verdict, full visibility.
Unit-tested: 0+3+2(1 dup) → 4 articles, per-attempt notes.
parent ad7cc7d6
......@@ -190,6 +190,46 @@ for ATTEMPT in 1 2 3; do
done
set -e
# --- 合并各次 attempt 的交付成果 ---
# 数据可能由早期 attempt 产出(其结构化上报失败),末次仅作快速收尾(all_seen 0 篇);
# 不合并的话最终记录只显示末次 0 篇,无法判断实际交付。合并规则:按 URL 去重,
# 只并入"有 archive_path 的已交付文章",并在 warnings 注明每轮贡献。
python3 - "$JSON_OUT" "${JSON_OUT}.attempt1" "${JSON_OUT}.attempt2" <<'MERGE_EOF' || true
import json, sys, os
final_path = sys.argv[1]
final = json.load(open(final_path))
so = final.get('structured_output')
if not isinstance(so, dict):
sys.exit(0) # 末次也失败,走原有失败路径
arts = so.setdefault('articles', [])
have = {a.get('url') for a in arts}
notes = []
for i, p in enumerate(sys.argv[2:], 1):
if not (p and os.path.exists(p)):
continue
try:
env = json.load(open(p))
except Exception:
continue
prev = env.get('structured_output')
if not isinstance(prev, dict):
continue
add = [a for a in prev.get('articles', [])
if a.get('url') and a.get('archive_path') and a['url'] not in have]
for a in add:
have.add(a['url'])
arts.append(a)
if add:
notes.append(f"attempt{i} 交付 {len(add)} 篇")
if notes:
so['attempted_count'] = len(arts)
so['succeeded_count'] = sum(1 for a in arts if a.get('status') == 'SUCCESS')
so['failed_count'] = so['attempted_count'] - so['succeeded_count']
so.setdefault('warnings', []).append("多轮交付合并:" + ";".join(notes))
json.dump(final, open(final_path, 'w'), ensure_ascii=False, indent=2)
print(f"[merge] {'; '.join(notes)}")
MERGE_EOF
# 如果 claude 完全没输出(可能 PATH 未生效),写入诊断信息到 RAW_OUT
if [ ! -s "$JSON_OUT" ] && [ ! -s "$RAW_OUT" ]; then
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment