Compare commits
3 commits
main
...
fix/7246-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2735bc5a13 | ||
|
|
9f3f569553 | ||
|
|
d224d1c19a |
5 changed files with 179 additions and 14 deletions
|
|
@ -433,6 +433,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
role through (see *Added*). A missing id is a plain not-found after one
|
||||
`getIssue`, instead of a partial-id search refusal, and `bd update
|
||||
<absent> --claim` answers a not-found gc classifies.
|
||||
- **`bd mol wisp gc --age 0s` can miss a just-created wisp.** Dolt's
|
||||
`DATETIME(0)` column rounds fractional seconds half-up on write rather
|
||||
than truncating, so a wisp created in the second half of a wall-clock
|
||||
second can read back with `updated_at` up to 0.5s in the future. The GC's
|
||||
age check (`now.Sub(updatedAt) > ageThreshold`) then compares against a
|
||||
negative duration and fails, even though `--age 0s`'s own contract is
|
||||
that every wisp qualifies. `ageThreshold <= 0` now bypasses the clock
|
||||
comparison entirely (#7236).
|
||||
- **PRs based on `hotfix/**` branches now run full CI, not just
|
||||
cross-version historical smokes and triage labeling.** `pr.yml`,
|
||||
`pr-risk.yml`, `conformance.yml`, `cross-version-smoke.yml` and
|
||||
|
|
|
|||
|
|
@ -1266,6 +1266,7 @@ go_test(
|
|||
"where_cgo_test.go",
|
||||
"where_embedded_test.go",
|
||||
"where_test.go",
|
||||
"wisp_abandoned_test.go",
|
||||
"wisp_gc_active_embedded_test.go",
|
||||
"wisp_gc_purge_closed_embedded_test.go",
|
||||
"wisp_proxied_integration_test.go",
|
||||
|
|
|
|||
|
|
@ -822,6 +822,30 @@ func runWispGC(cmd *cobra.Command, args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// wispIsAbandoned reports whether a wisp counts as abandoned for GC
|
||||
// purposes: it has not been updated within ageThreshold of now.
|
||||
//
|
||||
// ageThreshold <= 0 (--age 0s and below) always reports true, bypassing
|
||||
// the clock comparison entirely — this matches the GC's own documented
|
||||
// contract ("hasn't been updated in --age duration"): nothing has been
|
||||
// updated in the last zero seconds. It also matters for a reason the
|
||||
// comparison alone does not handle: Dolt's DATETIME(0) column rounds
|
||||
// fractional seconds half-up on write rather than truncating (#7236), so
|
||||
// a wisp created in the second half of a wall-clock second can read back
|
||||
// with updatedAt up to 0.5s in the future. now.Sub(updatedAt) is then
|
||||
// negative, failing a strict > comparison for a wisp that is, by
|
||||
// definition, not yet one second old — exactly what --age 0s's "every
|
||||
// wisp qualifies" contract exists to avoid depending on in the first
|
||||
// place.
|
||||
func wispIsAbandoned(now, updatedAt time.Time, ageThreshold time.Duration) bool {
|
||||
return ageThreshold <= 0 || now.Sub(updatedAt) > ageThreshold
|
||||
}
|
||||
|
||||
// wispGCNow is the clock seam for findAbandonedWisps' age check, swappable in
|
||||
// tests. Both gc routes read it, so a test that swaps it must not call
|
||||
// t.Parallel().
|
||||
var wispGCNow = time.Now
|
||||
|
||||
func findAbandonedWisps(ctx context.Context, r molReader, cleanAll bool, ageThreshold time.Duration, excludeTypes []types.IssueType) ([]*types.Issue, error) {
|
||||
ephemeralFlag := true
|
||||
filter := types.IssueFilter{
|
||||
|
|
@ -848,7 +872,7 @@ func findAbandonedWisps(ctx context.Context, r molReader, cleanAll bool, ageThre
|
|||
return nil, err
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
now := wispGCNow()
|
||||
var abandoned []*types.Issue
|
||||
for _, issue := range issues {
|
||||
if r.IsInfraTypeCtx(ctx, issue.IssueType) {
|
||||
|
|
@ -860,7 +884,7 @@ func findAbandonedWisps(ctx context.Context, r molReader, cleanAll bool, ageThre
|
|||
if isProtectedWisp(issue, blockedSet, protectedStatuses) {
|
||||
continue
|
||||
}
|
||||
if now.Sub(issue.UpdatedAt) > ageThreshold {
|
||||
if wispIsAbandoned(now, issue.UpdatedAt, ageThreshold) {
|
||||
abandoned = append(abandoned, issue)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
138
cmd/bd/wisp_abandoned_test.go
Normal file
138
cmd/bd/wisp_abandoned_test.go
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// TestWispIsAbandoned pins the #7236 fix: --age 0s (ageThreshold <= 0) must
|
||||
// treat every wisp as abandoned regardless of its updatedAt, including a
|
||||
// wisp whose stored updatedAt reads back AFTER now — the shape Dolt's
|
||||
// DATETIME(0) half-up rounding on write produces for a wisp created in the
|
||||
// second half of a wall-clock second (#7236). Before this fix, that case
|
||||
// failed the strict now.Sub(updatedAt) > ageThreshold comparison because
|
||||
// the difference is negative.
|
||||
func TestWispIsAbandoned(t *testing.T) {
|
||||
now := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
updatedAt time.Time
|
||||
age time.Duration
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "age 0s: a wisp updated exactly now is abandoned",
|
||||
updatedAt: now,
|
||||
age: 0,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "age 0s: a wisp whose stored updatedAt rounded into the future is still abandoned",
|
||||
updatedAt: now.Add(500 * time.Millisecond),
|
||||
age: 0,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "a negative age behaves like zero",
|
||||
updatedAt: now.Add(500 * time.Millisecond),
|
||||
age: -time.Second,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "positive age: a fresh wisp is not abandoned",
|
||||
updatedAt: now,
|
||||
age: time.Hour,
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "positive age: a wisp past the threshold is abandoned",
|
||||
updatedAt: now.Add(-2 * time.Hour),
|
||||
age: time.Hour,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "positive age: exactly at the threshold is not abandoned (strict >, unchanged)",
|
||||
updatedAt: now.Add(-time.Hour),
|
||||
age: time.Hour,
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := wispIsAbandoned(now, tc.updatedAt, tc.age); got != tc.want {
|
||||
t.Errorf("wispIsAbandoned(%v, %v, %v) = %v, want %v", now, tc.updatedAt, tc.age, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// fixedWispsMolReader serves findAbandonedWisps a fixed set of wisps with
|
||||
// nothing blocked, no custom statuses and no dependents. It embeds the
|
||||
// molReader INTERFACE, so a read the age scan does not make today panics
|
||||
// rather than quietly answering zero.
|
||||
type fixedWispsMolReader struct {
|
||||
molReader
|
||||
wisps []*types.Issue
|
||||
}
|
||||
|
||||
func (r fixedWispsMolReader) SearchIssues(context.Context, string, types.IssueFilter) ([]*types.Issue, error) {
|
||||
return r.wisps, nil
|
||||
}
|
||||
func (fixedWispsMolReader) GetBlockedIssues(context.Context, types.WorkFilter) ([]*types.BlockedIssue, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (fixedWispsMolReader) GetCustomStatusesDetailed(context.Context) ([]types.CustomStatus, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (fixedWispsMolReader) IsInfraTypeCtx(context.Context, types.IssueType) bool { return false }
|
||||
func (fixedWispsMolReader) FindWispDependentsRecursive(context.Context, []string) (map[string]bool, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// TestFindAbandonedWispsAgesAtStoragePrecision pins the call site that
|
||||
// TestWispIsAbandoned cannot see: findAbandonedWisps must decide age through
|
||||
// wispIsAbandoned. A wisp written at 12:00:00.7 is stored as 12:00:01, and a
|
||||
// gc at 12:00:00.9 with --age 0s must still reclaim it; the raw
|
||||
// now.Sub(updated_at) > threshold that #7236 replaced reads -100ms and misses
|
||||
// it. A one-hour threshold must leave the same wisp alone at that instant and
|
||||
// reclaim it two hours later, so dropping the age check fails too. --age 1s
|
||||
// at 12:00:01.5 must leave it alone: only half a second has passed since the
|
||||
// stored second, so a positive threshold never credits idle time that has
|
||||
// not elapsed.
|
||||
func TestFindAbandonedWispsAgesAtStoragePrecision(t *testing.T) {
|
||||
base := time.Date(2026, 10, 10, 12, 0, 0, 0, time.UTC)
|
||||
wisp := &types.Issue{
|
||||
ID: "gc-idle",
|
||||
Status: types.StatusOpen,
|
||||
IssueType: types.TypeTask,
|
||||
Ephemeral: true,
|
||||
UpdatedAt: base.Add(700 * time.Millisecond).Round(time.Second), // 12:00:01
|
||||
}
|
||||
old := wispGCNow
|
||||
t.Cleanup(func() { wispGCNow = old })
|
||||
|
||||
for _, tc := range []struct {
|
||||
now time.Time
|
||||
threshold time.Duration
|
||||
want int
|
||||
}{
|
||||
{base.Add(900 * time.Millisecond), 0, 1},
|
||||
{base.Add(900 * time.Millisecond), time.Hour, 0},
|
||||
{base.Add(2 * time.Hour), time.Hour, 1},
|
||||
{base.Add(1500 * time.Millisecond), time.Second, 0},
|
||||
} {
|
||||
wispGCNow = func() time.Time { return tc.now }
|
||||
got, err := findAbandonedWisps(context.Background(), fixedWispsMolReader{wisps: []*types.Issue{wisp}}, false, tc.threshold, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("findAbandonedWisps(--age %s): %v", tc.threshold, err)
|
||||
}
|
||||
if len(got) != tc.want {
|
||||
t.Errorf("findAbandonedWisps(--age %s) at %s, updated_at 12:00:01: got %d wisps, want %d",
|
||||
tc.threshold, tc.now.Format("15:04:05.000"), len(got), tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,14 +28,6 @@ func TestWispGCProtectsActiveWisps(t *testing.T) {
|
|||
// category. "reviewing" is wip (protected); "triaging" is active, which
|
||||
// behaves like plain open and stays reclaimable — that pair also guards
|
||||
// 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.
|
||||
bdCommand(t, bd, dir, "config", "set", "status.custom", "reviewing:wip,triaging:active")
|
||||
|
||||
// Genuinely abandoned: an idle open ephemeral wisp. Must be reclaimed.
|
||||
|
|
@ -66,10 +58,12 @@ func TestWispGCProtectsActiveWisps(t *testing.T) {
|
|||
customWIP := bdCreate(t, bd, dir, "custom wip step", "--ephemeral").ID
|
||||
bdCommand(t, bd, dir, "update", customWIP, "--status", "reviewing")
|
||||
|
||||
// Every wisp above was created well over 1ms ago by the time gc runs, so a
|
||||
// 1ms threshold makes them all "stale" by updated_at. Only the genuinely
|
||||
// abandoned ones should be reclaimed.
|
||||
out := bdCommand(t, bd, dir, "mol", "wisp", "gc", "--age", "1ms", "--dry-run", "--json")
|
||||
// --age 0s makes every wisp above old enough to reclaim. Any positive --age
|
||||
// can leave the most recently touched one reading as too young, because
|
||||
// updated_at is stored at whole-second precision and Dolt rounds the write
|
||||
// up to half a second into the future (#7236). Protection is checked
|
||||
// before age, so only the genuinely abandoned ones should be reclaimed.
|
||||
out := bdCommand(t, bd, dir, "mol", "wisp", "gc", "--age", "0s", "--dry-run", "--json")
|
||||
|
||||
var res struct {
|
||||
CleanedIDs []string `json:"cleaned_ids"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue