fix: exclude pause time from task run duration

Persist active_run_seconds + run_segment_started_at so task list and
orchestration list_tasks accumulate only actual execution time across
pause/resume/queue/terminal transitions.
This commit is contained in:
artex committed 2026-10-27 13:37:43 +08:00
1 parent e740334b90
commit 41c967f7ad
15 files changed
+320 -71

No files matched your search

+6
View File
@@ -937,6 +937,9 @@ func (e *Engine) plannerLoop(ctx context.Context, t *Task) {
return
}
defer e.decInflight(t.ID)
if err := e.m.StartTaskRunSegment(t.ID); err != nil {
log.Printf("[runtime] task %s start segment failed: %v", t.ID, err)
}
e.stampFirstRun(t) // 首次真正规划 → 盖 first_run_at + 算 deadline(仅带 timeout 的任务)
e.touch(t.ID)
emit := func(r db.Activity) { e.emitActivity(t, r) }
@@ -1086,6 +1089,9 @@ func (e *Engine) runIntent(ctx context.Context, t *Task, name string, worker *ag
}
return true
}
if err := e.m.StartTaskRunSegment(t.ID); err != nil {
log.Printf("[runtime] task %s start segment failed: %v", t.ID, err)
}
// per-work child context so the planner's kill_work can stop just this work.
workCtx, workCancel := context.WithCancelCause(ectx)
e.registerWork(intent.ID, workCancel)