Compare commits
1 commit
main
...
ci/bazel-w
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
907595ffc6 |
3 changed files with 63 additions and 7 deletions
|
|
@ -822,6 +822,26 @@ func runWispGC(cmd *cobra.Command, args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// updatedAtPrecision is the precision issues.updated_at / wisps.updated_at are
|
||||
// stored at: a DATETIME with no fractional seconds.
|
||||
const updatedAtPrecision = time.Second
|
||||
|
||||
// wispIdleAtLeast reports whether a wisp last updated at updatedAt (as read
|
||||
// back from the store) has been idle for at least threshold at now.
|
||||
//
|
||||
// Age is measured at the precision updated_at is stored at, not at now's
|
||||
// nanosecond precision. Dolt ROUNDS a fractional write to the nearest second,
|
||||
// so a row written at hh:mm:00.7 reads back as hh:mm:01, up to 500ms in the
|
||||
// future of the write; raw now.Sub(updatedAt) is then negative for up to half
|
||||
// a second, and `--age 0s` (every wisp) missed the wisp it was asked to
|
||||
// reclaim (ga-vnycm2.44). Rounding now the same way keeps the comparison
|
||||
// monotone — round(write) <= round(now) for any write at or before now — so a
|
||||
// wisp's age is never negative and `--age 0s` always includes it. A threshold
|
||||
// below one second is therefore only as fine as the stored timestamp.
|
||||
func wispIdleAtLeast(now, updatedAt time.Time, threshold time.Duration) bool {
|
||||
return now.Round(updatedAtPrecision).Sub(updatedAt) >= threshold
|
||||
}
|
||||
|
||||
func findAbandonedWisps(ctx context.Context, r molReader, cleanAll bool, ageThreshold time.Duration, excludeTypes []types.IssueType) ([]*types.Issue, error) {
|
||||
ephemeralFlag := true
|
||||
filter := types.IssueFilter{
|
||||
|
|
@ -860,7 +880,7 @@ func findAbandonedWisps(ctx context.Context, r molReader, cleanAll bool, ageThre
|
|||
if isProtectedWisp(issue, blockedSet, protectedStatuses) {
|
||||
continue
|
||||
}
|
||||
if now.Sub(issue.UpdatedAt) > ageThreshold {
|
||||
if wispIdleAtLeast(now, issue.UpdatedAt, ageThreshold) {
|
||||
abandoned = append(abandoned, issue)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ func TestWispGCProtectsActiveWisps(t *testing.T) {
|
|||
// against the predicate degenerating into "protect everything".
|
||||
//
|
||||
// Ordering matters: every wisp expected to be RECLAIMED is created and
|
||||
// last-touched first, before the protected ones. The age predicate is
|
||||
// now.Sub(updated_at) > threshold against a timestamp written by the
|
||||
// database, so the most recently touched bead can briefly appear
|
||||
// not-yet-stale if the DB clock runs ahead of the test process. Protected
|
||||
// wisps are excluded regardless of age, so only the reclaimable
|
||||
// assertions are sensitive to this.
|
||||
// last-touched first, before the protected ones. updated_at is stored at
|
||||
// whole-second precision and the age predicate (wispIdleAtLeast) compares
|
||||
// at that precision, so with a sub-second --age the most recently touched
|
||||
// bead can read as zero seconds idle. Protected wisps are excluded
|
||||
// regardless of age, so only the reclaimable assertions are sensitive to
|
||||
// this.
|
||||
bdCommand(t, bd, dir, "config", "set", "status.custom", "reviewing:wip,triaging:active")
|
||||
|
||||
// Genuinely abandoned: an idle open ephemeral wisp. Must be reclaimed.
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
|
@ -169,3 +170,38 @@ func TestWispCreateDryRunFanoutMessage(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestWispIdleAtLeastAtStoragePrecision pins ga-vnycm2.44: updated_at is a
|
||||
// whole-second DATETIME, and Dolt ROUNDS a fractional write to the nearest
|
||||
// second, so a wisp written at hh:mm:00.7 reads back as hh:mm:01 — 300ms in
|
||||
// the future of the write. A `bd mol wisp gc --age 0s` at hh:mm:00.9 used to
|
||||
// compute a negative age (now.Sub(updated_at) = -100ms), fail `> 0`, and miss
|
||||
// the wisp it was asked to reclaim (TestCLI_WispGCExcludeType's flake). Age is
|
||||
// now measured at the precision updated_at is stored at.
|
||||
func TestWispIdleAtLeastAtStoragePrecision(t *testing.T) {
|
||||
base := time.Date(2026, 10, 10, 12, 0, 0, 0, time.UTC)
|
||||
written := base.Add(700 * time.Millisecond)
|
||||
stored := written.Round(time.Second) // what Dolt's DATETIME holds: 12:00:01
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
now time.Time
|
||||
threshold time.Duration
|
||||
want bool
|
||||
}{
|
||||
{"age 0 just after a rounded-up write", base.Add(900 * time.Millisecond), 0, true},
|
||||
{"age 0 in the same instant as the write", written, 0, true},
|
||||
{"1ms threshold just after a rounded-up write", base.Add(900 * time.Millisecond), time.Millisecond, false},
|
||||
{"1ms threshold a second later", base.Add(1900 * time.Millisecond), time.Millisecond, true},
|
||||
{"1h threshold, fresh", base.Add(30 * time.Minute), time.Hour, false},
|
||||
{"1h threshold, exactly an hour at storage precision", stored.Add(time.Hour), time.Hour, true},
|
||||
{"1h threshold, well past", base.Add(2 * time.Hour), time.Hour, true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := wispIdleAtLeast(tc.now, stored, tc.threshold); got != tc.want {
|
||||
t.Errorf("wispIdleAtLeast(now=%s, updated_at=%s, %s) = %v, want %v",
|
||||
tc.now.Format("15:04:05.000"), stored.Format("15:04:05"), tc.threshold, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue