Skip to content

fix(alerts): 用持久文章 ID 防止迟到新闻漏报 - #228

Closed
Bluuok wants to merge 1 commit into
helsome:mainfrom
Bluuok:fix/alert-news-dedup
Closed

Bluuok wants to merge 1 commit into
helsome:mainfrom
Bluuok:fix/alert-news-dedup

Conversation

@Bluuok

@Bluuok Bluuok commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

改动与原因

告警引擎把 lastCheckedAt 写成轮询时钟,新闻评估器却拿它当文章发布时间游标。Provider 延迟返回的新闻(发布时间早于上次检查)因此永久漏报;同秒文章也不能可靠地靠时间水位区分。

本 PR 将最近见过的文章 ID 存在每条规则独立的 alerts-snapshots.json 状态中,按 ID 判断新增,并限制状态为最近 1000 个 ID。已有规则在首次升级轮询时仍用旧 lastCheckedAt 过滤旧文章,再切到 ID 去重,避免升级后批量重放历史新闻。lastCheckedAt 继续记录检查时间。

Closes #227

可复现测试报告

环境:Windows 11 / Bun 1.4.0 / 上游 main ba5dcdf。分支基于干净 main,改动仅 shared 告警路径。

命令 修复前 修复后
bun test packages/shared/src/alerts/engine.test.ts 7 pass / 1 fail;新增迟到新闻回归用例期望 2 条事件、实际 1 条 —
bun test packages/shared/src/alerts --isolate — 59 pass / 0 fail / 156 expect
bun run --filter @finagent/shared typecheck — exit 0
git diff --check — exit 0

新增真实 AlertEngine.tick() → AlertRuleRepository → JsonFileStore 测试,覆盖 provider 迟到文章、同秒新文章、空轮询、重建 Engine/Repository 后的持久去重;旧规则首次升级不重放历史、之后接受迟到新 ID;单独断言持久状态上限。

本地全工作区检查的环境限制

独立 worktree 中 bun install --frozen-lockfile 2 次均在 Windows 包链接阶段对 happy-dom、micromark-util-decode-numeric-character-reference、@babel/helper-module-transforms 报 ENOENT(544 个包已安装,3 个失败)。因此 bun run typecheck 的 core/shared 通过,i18n/ui 因无法解析 happy-dom 退出 2;这不是本 PR 的代码错误结论,也不宣称本地全仓通过。请以本 PR 在干净 CI 环境的 Typecheck、Focused tests 和 Full unit tests 结果复核。

范围与限制

  • 无可见 UI 变化;告警内容沿用现有格式,无需截图。
  • 不改新闻来源、轮询频率或 cooldown。
  • 去重状态有 1000 个 ID 的上限;极长时间后旧 ID 被淘汰,若 provider 再返回它,可能再次触发。生产 research.news 每次默认取 20 条,状态上限覆盖常规连续轮询。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(alerts): 新闻规则以检查时间去重,迟到和同秒文章永久漏报

1 participant