Commit ad7cc7d6 authored by 郭阔's avatar 郭阔

fix(panel): heartbeat is authoritative for phase; disk signals only as fallback

digitimes updates registry/index incrementally while still fetching, so a
mid-fetch registry write was misread as 推送/收尾 and overrode the agent's
own correct 采集中 heartbeat. Disk inference has now been wrong in both
directions (stale when the agent forgets to flip,超前 on incremental
writers) — trust the agent's heartbeat whenever present; disk evidence
and neutral 运行中 remain fallbacks only.
parent bf0fe57c
...@@ -592,38 +592,34 @@ def _harvest_phase(source): ...@@ -592,38 +592,34 @@ def _harvest_phase(source):
except OSError: except OSError:
return None, None return None, None
# 1) 真实阶段文件(进程自己写的)——磁盘证据必须比心跳最后写入时间新才能覆盖它。 # 1) 心跳 = 采集会话亲述的阶段,绝对优先(实测磁盘信号两个方向都会说谎:
# 基准锚在心跳而非任务开始:自动重试的 attempt2 会重置心跳为"采集中"重新抓取, # 会话忘翻牌时过旧;digitimes 这类边抓边写 registry 的源又过超前,
# attempt1 的收尾文件(registry 等)虽比任务开始新,但比新心跳旧,不得污染新阶段。 # 抓取中途的 registry 更新会被误读成"推送/收尾")。
phase_file = LOG_DIR / f"{source}.phase" phase_file = LOG_DIR / f"{source}.phase"
hb_txt, hb_mtime = "", None
if phase_file.exists(): if phase_file.exists():
try: try:
hb_txt = phase_file.read_text(encoding="utf-8").strip() hb_txt = phase_file.read_text(encoding="utf-8").strip()
hb_mtime = mtime(phase_file)
except OSError: except OSError:
hb_txt, hb_mtime = "", None hb_txt = ""
baseline = hb_mtime or start if hb_txt:
return start, hb_txt
# 2) 无心跳时才用磁盘信号兜底(尽力而为)
def disk_phase_and_mtime(): def disk_phase_and_mtime():
if not (day_dir and day_dir.is_dir()): if not (day_dir and day_dir.is_dir()):
return None, None return None, None
reg = mtime(day_dir / "registry.json") reg = mtime(day_dir / "registry.json")
if reg and reg > baseline: if reg and reg > start:
return "推送/收尾", reg return "推送/收尾"
summ = mtime(day_dir / ".summaries.json") summ = mtime(day_dir / ".summaries.json")
if summ and summ > baseline: if summ and summ > start:
return "摘要生成", summ return "摘要生成"
mani = mtime(day_dir / ".manifest.json") mani = mtime(day_dir / ".manifest.json")
if mani and mani > baseline: if mani and mani > start:
return "摘要生成", mani return "摘要生成"
return None, None return None
dp, dp_mtime = disk_phase_and_mtime() dp = disk_phase_and_mtime()
if hb_txt and hb_mtime:
if not dp or hb_mtime >= dp_mtime:
return start, hb_txt
return start, dp # 磁盘证据比心跳新:信磁盘(会话忘翻牌的场景)
if dp: if dp:
return start, dp return start, dp
# 3) 无信号:中性显示,不猜 # 3) 无信号:中性显示,不猜
......
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