From 1d8a502ac4d6240ab8b737237c2ff601b487563b Mon Sep 17 00:00:00 2001 From: Levi Date: Sun, 20 Sep 2026 09:21:36 +0800 Subject: [PATCH] fix(task): keep DoneAt once written instead of clearing it Done tasks never leave the done state (doStart, pause and markTaskError all guard against Done), so the else branch clearing DoneAt was unreachable dead code. DoneAt is now written once on completion and kept for the task lifetime. --- pkg/download/model.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/download/model.go b/pkg/download/model.go index 36dfa4ab..bf479a0b 100644 --- a/pkg/download/model.go +++ b/pkg/download/model.go @@ -32,8 +32,9 @@ type Task struct { Progress *Progress `json:"progress"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` - // DoneAt is the time when the task last completed; nil while the task has - // never finished or is being downloaded again. + // DoneAt is the time when the task completed; nil if it has never + // finished. A done task never leaves the done state, so the value is + // written once and kept. DoneAt *time.Time `json:"doneAt"` producer production.Source @@ -137,11 +138,11 @@ func (t *Task) MarshalJSON() ([]byte, error) { func (t *Task) updateStatus(status base.Status) { t.UpdatedAt = time.Now() t.Status = status + // A done task never leaves the done state, so there is no branch to clear + // DoneAt on other transitions. if status == base.DownloadStatusDone { doneAt := time.Now() t.DoneAt = &doneAt - } else { - t.DoneAt = nil } }