Skip to content

fix: resolve issue #96 - #97

Merged
helsome merged 4 commits into
helsome:mainfrom
Jackkp0t:fix/issue-96
Oct 22, 2026
Merged

helsome merged 4 commits into
helsome:mainfrom
Jackkp0t:fix/issue-96

Conversation

@Jackkp0t

@Jackkp0t Jackkp0t commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

改动说明

修复计划自动化规则在同一计划日期可能重复执行的问题。

  • 执行前持久化声明 ruleId + scheduled occurrence,应用重启后仍可识别已处理任务。
  • 在异步持久化前设置内存 guard,避免后续 scheduler tick 并发触发同一规则。
  • 自动化运行记录写入时保留已声明的计划 occurrence。
  • 失败的计划任务不会在同一天后续 tick 自动重试。
  • claimScheduledOccurrence 与 record 共用按文件串行的读改写队列,防止跨 repository/store 实例的旧快照覆盖持久 claim;失败写入不阻塞后续操作。
  • 新增重启恢复、并发 tick、失败不重试、持久化声明、两个读写顺序的并发覆盖、并发重复 claim 与写入失败恢复测试。

关联 Issue

Closes #96

测试报告(正式审核前必填)

环境

  • Bun:1.4.2
  • OS:Windows

实际执行命令与结果

bun test packages/shared/src/automation/rules-repository.test.ts
→ 新增回归测试在修复前:8 passed / 4 failed;并发测试复现 claim 丢失与重复成功占用。

bun test packages/shared/src/automation/rules-repository.test.ts apps/electron/src/main/kernelHost.test.ts --isolate
→ 修复后:35 passed / 0 failed(12 repository + 23 kernel host)。

bun test packages/shared apps/electron --isolate
→ 1397 passed / 0 failed,117 files。

bun run typecheck
→ @finagent/core / @finagent/i18n / @finagent/shared / @finagent/ui / @finagent/electron 全部 exit 0。

git diff --check
→ exit 0。

实际使用 C:\Users\jackpot\.bun\bin\bun.exe。工作区测试在沙箱外运行,以允许现有测试访问 C:\tmp\pi;设置仅作用于测试进程的 GIT_CONFIG_COUNT=1、GIT_CONFIG_KEY_0=safe.directory、GIT_CONFIG_VALUE_0=<当前 checkout 的绝对路径>,避免沙箱用户创建仓库导致测试中的 git rev-parse HEAD 触发 ownership 检查。未修改全局 Git 配置。

已知失败 / Baseline(如有)

无。

  • 已提供实际测试命令与 pass/fail 结果
  • 已说明测试环境
  • 如果存在已知 baseline / 环境失败,已提供 main 对照或说明
  • 核心改动已有对应 focused test / smoke / integration 验证

UI 截图(仅可见 UI 变化时必填)

  • 本 PR 无可见 UI 变化(无需截图)
  • 本 PR 有可见 UI 变化,已提供修改后的 UI 截图
  • 已提供 Before / After 对比截图(适用时)

Before(适用时)

不适用(无可见 UI 变化)。

After(适用时)

不适用(无可见 UI 变化)。

Scope / 后续

本 PR 仅处理计划自动化的同日去重、重启恢复与并发执行保护;不修改自动化规则配置、手动执行行为或 UI。

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复方向与 #96 的两个真实重复路径一致:执行前先占用 occurrence、内存 guard 阻止重叠 tick、持久 claim 让 host 重建后仍可去重;失败 occurrence 明确选择“当天不自动重试”,也避免了偶然的一分钟 retry storm。新增测试覆盖了重启恢复、执行跨 tick、失败不重试和跨 repository instance 的持久 claim,focused tests + typecheck 报告足够验证这个修复。

代码本身批准。当前分支基于较早的 4eca2d1,而 main 已前进到新的提交;这是持久化/调度路径,我不建议直接用旧基线合并。请只 rebase 最新 main,并重跑现有两组 focused tests + typecheck/basic CI 即可,不需要扩大 scope。action_required 是首次贡献者 Actions 授权,不作为质量失败。

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新增持久 claim 存在丢失更新风险。rules-repository.ts 的 claimScheduledOccurrence 与 record 分别对同一文件 read→write,未共享 RMW 串行保护。受控序列:record(A) 读取旧快照后暂停,claim(B) 先写入 B 并返回 true,record(A) 再以旧快照覆盖,B claim 消失;B 执行期间崩溃后重启便可重复执行。JsonFileStore 仅串行最终 rename 不能防止这个覆盖。请让 claim/record 共用 RMW 队列或锁,并补并发与仓库重建后的去重回归。依据源码及受控读写序列模拟,未声称运行了仓库集成测试。

@Jackkp0t
Jackkp0t requested a review from helsome October 22, 2026 07:14
@Jackkp0t

Copy link
Copy Markdown
Contributor Author

Hi @helsome , I've pushed two commits to address the review feedback:

  • 6e294e8: Serialize automation claims and runtime record read/write operations.
  • 1919a97: Sync with upstream main and preserve the automation deduplication and runtime-state tests.

Could you please take another look when you have a chance? Thanks for the review!

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.

[Automation] Scheduled rules can run more than once on the same day

2 participants