| 1 | package goal |
| 2 | |
| 3 | import "math" |
| 4 | |
| 5 | // AddWorkDuration records completed active work without changing tool authority. |
| 6 | // The host serializes and persists this candidate before publishing it. |
| 7 | func (m *Machine) AddWorkDuration(ref Ref, durationMs int64) (View, error) { |
| 8 | m.mu.Lock() |
| 9 | defer m.mu.Unlock() |
| 10 | current, err := m.exactLocked(ref) |
| 11 | if err != nil { |
| 12 | return View{}, err |
| 13 | } |
| 14 | if durationMs > 0 { |
| 15 | current.WorkDurationMs += min(durationMs, math.MaxInt64-current.WorkDurationMs) |
| 16 | } |
| 17 | return *m.viewLocked(), nil |
| 18 | } |
| 19 |