fix: harden task runtime across restart and terminal mirror

Clear open run segments on process start without imputing downtime.
Mirror terminal/pause runtime fields into memory before hydration, make
SetPaused finalize segments, and add DB lifecycle tests.
This commit is contained in:
artex committed 2026-10-27 14:14:56 +08:00
1 parent 41c967f7ad
commit d8bda59d7d
4 files changed
+274 -24

No files matched your search

+1 -1
View File
@@ -191,7 +191,7 @@ function fmtDuration(sec: number): string {
// taskDuration counts only active execution segments. A live segment ticks locally;
// paused, queued, and terminal tasks stay fixed at their persisted active total.
function taskDuration(task: Task, nowSec: number): number {
const active = Math.max(0, Math.floor(task.active_run_seconds ?? task.run_seconds ?? 0));
const active = Math.max(0, Math.floor(task.active_run_seconds ?? 0));
const segmentStart = task.run_segment_started_unix ?? 0;
if (task.status === "running" && !task.paused && !task.queued && segmentStart > 0) {
return active + Math.max(0, Math.floor(nowSec - segmentStart));