Skip to content

feat(task): persist task timestamps across restarts - #2914

Open
fryeggs wants to merge 1 commit into
OpenListTeam:mainfrom
fryeggs:codex/fryeggs-copy-persistence
Open

feat(task): persist task timestamps across restarts#2914
fryeggs wants to merge 1 commit into
OpenListTeam:mainfrom
fryeggs:codex/fryeggs-copy-persistence

Conversation

@fryeggs

@fryeggs fryeggs commented Aug 11, 2026

Copy link
Copy Markdown

Summary / 摘要

This PR makes task start/end timestamps part of the persisted task representation so copy tasks can recover their visible timing information after a normal restart or container recreation. It also adds a regression test covering native task unmarshalling and recovery fields.

本 PR 将任务开始/结束时间纳入持久化任务表示,使复制任务在正常重启或容器重建后能够恢复可见的时间信息,并增加原生任务反序列化与恢复字段的回归测试。

  • This PR has breaking changes.
  • This PR changes public API, config, storage format, or migration behavior. The persisted JSON gains additive start_time/end_time fields; older payloads remain readable.
  • This PR requires corresponding changes in related repositories.

Related repository PRs / 关联仓库 PR:

Testing / 测试

  • go test ./internal/fs -run '^TestMigratedCopyTaskRecoversNativeFields$' -count=1
  • go test ./... — the current upstream baseline still has unrelated failures in several drivers under the current Go toolchain, an environment-dependent internal/net transport assertion, and aria2 RPC tests when no local aria2 service is running.
  • The added regression test verifies task IDs, state, creator, timestamps, paths, task type, retry initialization, and task grouping.

Checklist / 检查清单

  • I have read CONTRIBUTING.
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
  • I have formatted the changed code with gofmt or go fmt.
  • I have requested review from relevant maintainers or code owners where applicable.

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.

Tools used / 使用工具:

  • Codex

Usage scope / 使用范围:

  • Code generation / 代码生成

  • Refactoring / 重构

  • Tests / 测试

  • Review assistance / 审查辅助

  • I have reviewed and validated all AI-assisted content included in this PR.

  • I have ensured that this AI-assisted commit includes Co-Authored-By attribution.

  • I can reproduce the checked behavior from the committed source and test commands without relying on hidden runtime state.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
PIKACHUIM

This comment was marked as outdated.

@pikachuren pikachuren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🙏 感谢 @fryeggs 提交!
🤖 AI 自动审核声明:本评审报告由 AI 自动生成,当前使用 Claude Opus 5 模型进行分析。
⚠️ AI 分析结果仅供参考,可能存在误判或遗漏。如您发现任何问题或有不同意见,欢迎随时提出讨论和纠正。
⚠️ 重要提醒:即使 AI 评审认为代码质量良好且建议合并,最终是否合并仍需由项目维护者进行人工判定。项目维护者会综合考虑代码质量、项目规划、技术方向、团队资源等多方面因素做出决策。

🎯 结论

✅ 建议 Approve(由维护者人工确认)— 改动小而准,且补了迁移兼容测试

📖 概要

feat(task): persist task timestamps across restarts · 让任务的开始/结束时间在重启后不丢失。
核心改动:TaskExtensionstartTime / endTime 由私有字段改为导出字段并加 JSON tag,配套新增反序列化兼容测试。

🧭 整体方案

根因很清晰:私有字段不会被 encoding/json 序列化,任务持久化后时间戳自然丢失。改为导出字段 + json:"start_time,omitempty" 是最直接的解法,且通过保留原有 getter/setter 方法签名,对调用方完全透明,方案干净。

📊 变更统计

2 个文件(+72 / -7 行) | 功能 ⭐⭐⭐⭐⭐ | 最小改动 ⭐⭐⭐⭐⭐ | 前向兼容 ⭐⭐⭐⭐ | 方案设计 ⭐⭐⭐⭐⭐

🚨 关键问题

P0(阻塞合并):无
P1(建议修复):无

P2(可选)

  • 💡 字段由私有改为导出后,外部包可绕过 setter 直接赋值,封装性略有削弱。这是 Go 里为 JSON 序列化常见的取舍,可接受;若想两者兼得也可实现 MarshalJSON/UnmarshalJSON 保持字段私有,但样板代码会多不少,个人倾向当前写法~
  • 💡 新增的 TestMigratedCopyTaskRecoversNativeFields 覆盖了旧数据反序列化、creator 恢复、retry 延迟初始化、groupID 重建等多方面,质量不错。是否顺带补一个「新写入 → 读回」的往返测试,确保序列化方向也正确呢?
  • 💡 存量任务数据中没有 start_time / end_time,反序列化后为 nil。得益于 omitempty 与指针类型不会 panic,前端展示为空即可,属于可接受行为,仅作记录~

📂 逐文件分析

internal/task/base.go

改动意图:让时间戳参与 JSON 序列化。
代码逻辑startTime/endTimeStartTime/EndTime 并加 tag;四个 getter/setter 同步更新内部引用。
问题分析:改动完整,方法签名未变、调用方无需改动,ClearEndTime 也已同步。无问题。

internal/fs/copy_queue_persistence_test.go

改动意图:验证旧格式任务数据能正确恢复。
问题分析:用真实历史 JSON 结构做反序列化断言,覆盖面好,是本 PR 的加分项。

✅ 待处理清单

  • 建议补充一个序列化往返(marshal → unmarshal)测试
  • 合并后确认存量任务重启后展示正常(时间为空但不报错)

🎯 结论:✅ 建议 Approve — 根因准确、改动最小、测试到位,无阻塞项。

@PIKACHUIM

Copy link
Copy Markdown
Member

需要确认P2的问题是否有影响

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.

3 participants