fix: wake expired defers before external-aware claims (beads-n6m)
Expose the advisory backend wake to the external ready claimer so selection preserves the existing defer lifecycle. Cover wake ordering, external exclusions, and claims after an advisory no-op. Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Denis Redozubov
This commit is contained in:
parent
128f8b4ebb
commit
3468d62f81
5 changed files with 97 additions and 0 deletions
|
|
@ -26,6 +26,13 @@ func NewReadyClaimer(store *DoltStore) (issueops.ReadyClaimer, error) {
|
|||
|
||||
type readyClaimer struct{ store *DoltStore }
|
||||
|
||||
// WakeExpiredDefersAdvisory preserves the backend wake contract for decorators.
|
||||
func (s *DoltStore) WakeExpiredDefersAdvisory(ctx context.Context) {
|
||||
s.wakeExpiredDefers(ctx)
|
||||
}
|
||||
|
||||
var _ storage.ExpiredDeferWaker = (*DoltStore)(nil)
|
||||
|
||||
// ClaimNext runs selection, the compare-and-set and hydration in one
|
||||
// transaction, under the claim-family verify-after-write (bd-zccb9) that
|
||||
// ClaimReadyIssue runs: this reaches the same writes, so under a degraded
|
||||
|
|
|
|||
|
|
@ -9,10 +9,18 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/issueops"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// WakeExpiredDefersAdvisory preserves the backend wake contract for decorators.
|
||||
func (s *EmbeddedDoltStore) WakeExpiredDefersAdvisory(ctx context.Context) {
|
||||
s.wakeExpiredDefers(ctx)
|
||||
}
|
||||
|
||||
var _ storage.ExpiredDeferWaker = (*EmbeddedDoltStore)(nil)
|
||||
|
||||
// wakeExpiredDefers runs the lazy defer-wake sweep (issueops.WakeExpiredDefersInTx)
|
||||
// in its own write transaction before a ready-work read. Advisory by contract:
|
||||
// a ready listing must never fail because the sweep could not run — strict
|
||||
|
|
|
|||
67
internal/storage/externaldeps/ready_wake_test.go
Normal file
67
internal/storage/externaldeps/ready_wake_test.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package externaldeps
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
publicops "github.com/steveyegge/beads/issueops"
|
||||
)
|
||||
|
||||
type wakeStore struct {
|
||||
*fakeStore
|
||||
wake func()
|
||||
}
|
||||
|
||||
func (s *wakeStore) WakeExpiredDefersAdvisory(context.Context) { s.wake() }
|
||||
|
||||
func (s *wakeStore) SearchIssuesWithCounts(ctx context.Context, _ string, filter types.IssueFilter) ([]*types.IssueWithCounts, error) {
|
||||
rows := make([]*types.IssueWithCounts, 0, len(filter.IDs))
|
||||
for _, id := range filter.IDs {
|
||||
row, err := s.GetIssue(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows = append(rows, &types.IssueWithCounts{Issue: row})
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func TestReadyClaimerWakesBeforeExternalFilteredSelection(t *testing.T) {
|
||||
for _, sweepSucceeds := range []bool{true, false} {
|
||||
name := "wake succeeds"
|
||||
if !sweepSucceeds {
|
||||
name = "failed advisory wake still allows claim"
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
blocked, eligible := issue("be-blocked"), issue("be-eligible")
|
||||
raw := &fakeStore{deps: map[string][]*types.Dependency{
|
||||
blocked.ID: {externalDep(blocked.ID, "external:remote:payments", types.DepBlocks)},
|
||||
}}
|
||||
if !sweepSucceeds {
|
||||
raw.ready = []*types.Issue{blocked, eligible}
|
||||
}
|
||||
wakes := 0
|
||||
backend := &wakeStore{fakeStore: raw, wake: func() {
|
||||
wakes++
|
||||
if sweepSucceeds {
|
||||
raw.ready = []*types.Issue{blocked, eligible}
|
||||
}
|
||||
}}
|
||||
// An intervening decorator must not hide the wake capability.
|
||||
inner := storage.NewHookFiringStore(backend, nil)
|
||||
claimer, err := New(inner, nil, nil).ReadyClaimer()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := claimer.ClaimNext(t.Context(), publicops.ClaimNextRequest{Actor: "worker"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if wakes != 1 || got.Claimed == nil || got.Claimed.ID != eligible.ID {
|
||||
t.Fatalf("wakes=%d, claimed=%v; want one wake and %s", wakes, got.Claimed, eligible.ID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -60,6 +60,11 @@ func (c *readyClaimer) ClaimNext(ctx context.Context, req issueops.ClaimNextRequ
|
|||
if err != nil {
|
||||
return issueops.ClaimNextResult{}, err
|
||||
}
|
||||
// ClaimReadyIssue does not perform the lazy wake owned by backend ready
|
||||
// roles. Preserve it before selection, including through telemetry/hooks.
|
||||
if waker, ok := storage.UnwrapStore(c.policy.inner).(storage.ExpiredDeferWaker); ok {
|
||||
waker.WakeExpiredDefersAdvisory(ctx)
|
||||
}
|
||||
claimed, err := c.policy.ClaimReadyIssue(ctx, filter, req.Actor)
|
||||
if err != nil || claimed == nil {
|
||||
return issueops.ClaimNextResult{}, err
|
||||
|
|
|
|||
10
internal/storage/wake_defers.go
Normal file
10
internal/storage/wake_defers.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package storage
|
||||
|
||||
import "context"
|
||||
|
||||
// ExpiredDeferWaker lets ready-role decorators preserve the backend's lazy
|
||||
// wake before selecting work. The sweep uses its own transaction and is
|
||||
// advisory: implementations warn on failure rather than failing the claim.
|
||||
type ExpiredDeferWaker interface {
|
||||
WakeExpiredDefersAdvisory(context.Context)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue