provider: FetchNew waits on no CLI for who is signed in; none feeds a list it fetches
cliIdentities() still held cursorStatus after Cursor's built-in was retired. Nothing FetchNew fetches waits on `cursor-agent about` any more: the Cursor plugin lists its own accounts (Listed), and cursorIdentity only names its carried-over account. But a page's FetchNewBehind still found the never-asked CLI unsettled and ran behind the page, so FetchingNew stayed up on a poll with nothing due, the same loop Devin's entry caused (TestFetchingNewOnceStarted and TestFetchingNewForgottenWhileListed red from the Cursor commit on). Removed: cliIdentities, awaitIdentities, asking, identitiesUnsettled and identitiesAnswered, and their branches in fetchNewGo and fetchNewHeld, which now list the accounts once. TestFetchingNewForgottenWhileListed (#2390) and the CLI half of TestFetchingNewOnceStarted (#1147, #1789) tested only that wait, and go with it. cursorStatus and devinStatus stay as cliIdentity, asked by the plugin's own-account name and the movers; left_alone_test names them itself. Run in magpie-wt-int (this commit on the retire stack): go test -tags nogui -count=1 -run 'FetchingNew|FetchNew|LeftAlone|Identit|Mover' ./internal/provider: ok go vet -tags nogui ./internal/provider; staticcheck -checks U1000 ./internal/provider: only sameAccount, unused on origin/main too The full suite at the stack's final head is recorded in the last commit's body.
This commit is contained in:
@@ -181,75 +181,6 @@ func (c *cliIdentity) refresh() chan struct{} {
|
||||
return done
|
||||
}
|
||||
|
||||
// cliIdentities are the CLIs a look at the accounts asks who is signed in.
|
||||
// Devin's (devinStatus) isn't: its built-in is retired, and only the move
|
||||
// onto its plugin asks it, waiting itself. Listed here, never asked by a
|
||||
// look, it stayed unsettled, and every page was told lists were on their
|
||||
// way.
|
||||
func cliIdentities() []*cliIdentity { return []*cliIdentity{cursorStatus} }
|
||||
|
||||
// awaitIdentities waits, at most timeout, for each CLI being asked who is
|
||||
// signed in for the first time: waited, if one was, and unknown, if one
|
||||
// still hasn't answered. FetchNew asks for the lists of the accounts known:
|
||||
// at the start of a magpie with nothing kept from before, `cursor-agent
|
||||
// about` (which asks Cursor's servers) answered after a look's 3s, and
|
||||
// Cursor's list wasn't asked for at all (#1789).
|
||||
func awaitIdentities(timeout time.Duration) (waited, unknown bool) {
|
||||
deadline := time.After(timeout)
|
||||
for _, c := range cliIdentities() {
|
||||
pending, done := c.asking()
|
||||
if !pending {
|
||||
continue
|
||||
}
|
||||
waited = true
|
||||
select {
|
||||
case <-done:
|
||||
case <-deadline:
|
||||
return true, true
|
||||
}
|
||||
}
|
||||
return waited, false
|
||||
}
|
||||
|
||||
// asking says whether the CLI is being asked who is signed in for the
|
||||
// first time, and the channel closed when it has answered.
|
||||
func (c *cliIdentity) asking() (pending bool, done chan struct{}) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
return c.at.IsZero() && c.refreshing, c.done
|
||||
}
|
||||
|
||||
// identitiesUnsettled says whether a CLI never answered who is signed in
|
||||
// is being asked, or would be asked and waited for by the next look:
|
||||
// listing the accounts then may wait on it, as FetchNew does, which a page
|
||||
// doesn't (#541). Not while discovery is off, as no look asks then.
|
||||
func identitiesUnsettled() bool {
|
||||
if settings.AccountDiscoveryOff() {
|
||||
return false
|
||||
}
|
||||
for _, c := range cliIdentities() {
|
||||
c.Lock()
|
||||
unsettled := c.at.IsZero() && (c.refreshing || !c.waited)
|
||||
c.Unlock()
|
||||
if unsettled {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// identitiesAnswered is how many CLIs have answered who is signed in.
|
||||
func identitiesAnswered() (n int) {
|
||||
for _, c := range cliIdentities() {
|
||||
c.Lock()
|
||||
if !c.at.IsZero() {
|
||||
n++
|
||||
}
|
||||
c.Unlock()
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// forget has the next look ask the CLI and wait for it: after a sign-in or
|
||||
// a sign-out, the last answer is the wrong one.
|
||||
func (c *cliIdentity) forget() {
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -20,9 +18,7 @@ import (
|
||||
// test's cleanup that waited on it let its fetch run into the next test
|
||||
// (TestProvidersAnswerWhileListsComeIn failed on CI). And a page's poll with
|
||||
// no account due starts nothing it then counts: counted, each poll found
|
||||
// the last one's still under way and the page asked for ever. A CLI still
|
||||
// asked who is signed in is waited for behind the page, counted meanwhile.
|
||||
// One P keeps a started goroutine from running before FetchingNew is read.
|
||||
// the last one's still under way and the page asked for ever. One P keeps a started goroutine from running before FetchingNew is read.
|
||||
func TestFetchingNewOnceStarted(t *testing.T) {
|
||||
isolate(t)
|
||||
home := t.TempDir()
|
||||
@@ -160,93 +156,6 @@ func TestFetchingNewOnceStarted(t *testing.T) {
|
||||
t.Fatal("FetchNewSoon started a fetch, and FetchingNew says none is on its way")
|
||||
}
|
||||
waitFetchingNew(t)
|
||||
|
||||
// a CLI never asked who is signed in, as after a sign-in forgot it, or
|
||||
// one still asked: which accounts are due can't be known without
|
||||
// waiting on it, which the page doesn't (#541); the fetch lists them
|
||||
// and waits behind the page, which is told lists are on their way until
|
||||
// it has (yetone on #1147, #1789)
|
||||
wasCursor, wasFirst := cursorStatus, firstAsk
|
||||
defer func() { cursorStatus, firstAsk = wasCursor, wasFirst }()
|
||||
firstAsk = 5 * time.Second // long, to tell a look's wait from none
|
||||
for _, asked := range []bool{false, true} {
|
||||
answer := make(chan struct{})
|
||||
cursorStatus = &cliIdentity{name: "cursor-test", exe: func() string { return "" }, read: true,
|
||||
ask: func() (string, string, bool, error) { <-answer; return "", "", false, nil }}
|
||||
if asked {
|
||||
cursorStatus.Lock()
|
||||
cursorStatus.waited = true // its look gave up already
|
||||
cursorStatus.refresh()
|
||||
cursorStatus.Unlock()
|
||||
}
|
||||
start = time.Now()
|
||||
FetchNewBehind(5 * time.Second)
|
||||
took = time.Since(start)
|
||||
busy = FetchingNew()
|
||||
if took > time.Second || !busy {
|
||||
close(answer)
|
||||
waitFetchingNew(t)
|
||||
t.Fatalf("with a CLI asked %v who is signed in: took %v, fetching %v", asked, took, busy)
|
||||
}
|
||||
close(answer)
|
||||
waitFetchingNew(t)
|
||||
}
|
||||
}
|
||||
|
||||
// A CLI forgotten while the Providers page's FetchNewBehind lists the
|
||||
// accounts (a sign-in finishing then) left its account out of that list:
|
||||
// the fetch is asked behind the page, which is told lists are on their
|
||||
// way, not that none is due. The forget is that listing's own, and the CLI
|
||||
// answers only once the page was told: a read another test left running
|
||||
// (a usage refresh reads Grok's account, then Cursor's) took the first
|
||||
// GrokExecutable call (the hook is Kiro's kiro-cli lookup now), forgot Cursor before the listing read it, and
|
||||
// Cursor answered nobody at once, so nothing was left to wait on and
|
||||
// nothing was due (#2390, red on ubuntu CI).
|
||||
func TestFetchingNewForgottenWhileListed(t *testing.T) {
|
||||
isolate(t)
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
||||
newFetches.Lock()
|
||||
newFetches.m = map[string]time.Time{}
|
||||
newFetches.Unlock()
|
||||
newSoonAt.Store(0)
|
||||
ForgetAccounts()
|
||||
answer := make(chan struct{})
|
||||
answered := sync.OnceFunc(func() { close(answer) })
|
||||
wasCursor, wasDB := cursorStatus, kiroCLIDB
|
||||
t.Cleanup(func() {
|
||||
answered()
|
||||
waitFetchingNew(t)
|
||||
cursorStatus, kiroCLIDB = wasCursor, wasDB
|
||||
ForgetAccounts()
|
||||
})
|
||||
nobody := func() (string, string, bool, error) { return "", "", false, nil }
|
||||
now := time.Now()
|
||||
// asked again once forgotten, Cursor answers after the page was told
|
||||
cursor := &cliIdentity{name: "cursor-test", exe: func() string { return "" }, read: true, at: now,
|
||||
ask: func() (string, string, bool, error) { <-answer; return nobody() }}
|
||||
cursorStatus = cursor
|
||||
// Kiro's account is read after Cursor's: the sign-in lands there, in
|
||||
// the page's own listing, not in anything else reading the accounts
|
||||
var once sync.Once
|
||||
kiroCLIDB = func() string {
|
||||
b := make([]byte, 64<<10)
|
||||
if strings.Contains(string(b[:runtime.Stack(b, false)]), "provider.FetchNewBehind(") {
|
||||
once.Do(cursor.forget)
|
||||
}
|
||||
return wasDB()
|
||||
}
|
||||
|
||||
FetchNewBehind(5 * time.Second)
|
||||
busy := FetchingNew()
|
||||
answered()
|
||||
waitFetchingNew(t)
|
||||
if !busy {
|
||||
t.Fatal("a CLI forgotten while the accounts were listed, and FetchingNew says none is on its way")
|
||||
}
|
||||
}
|
||||
|
||||
// waitFetchingNew waits for the fetches under way to end, the ones started
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestLeftAloneRunsNoCLI(t *testing.T) {
|
||||
claudeStatusAt = time.Now().Add(-time.Hour)
|
||||
}
|
||||
claudeStatusMu.Unlock()
|
||||
for _, c := range cliIdentities() {
|
||||
for _, c := range []*cliIdentity{cursorStatus, devinStatus} {
|
||||
c.Lock()
|
||||
if !c.at.IsZero() {
|
||||
c.at = time.Now().Add(-time.Hour)
|
||||
@@ -102,8 +102,11 @@ func TestLeftAloneRunsNoCLI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
// what was asked behind the look has answered before the test ends
|
||||
for _, c := range cliIdentities() {
|
||||
if pending, done := c.asking(); pending {
|
||||
for _, c := range []*cliIdentity{cursorStatus, devinStatus} {
|
||||
c.Lock()
|
||||
asking, done := c.refreshing, c.done
|
||||
c.Unlock()
|
||||
if asking {
|
||||
<-done
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,11 +445,9 @@ func FetchNewBehind(timeout time.Duration) {
|
||||
// fetchNewGo is FetchNew in the background, counted in newRunning before
|
||||
// it returns when there is work, so a page reading FetchingNew straight
|
||||
// after is told; with none nothing is started or counted. Which accounts
|
||||
// are due is known at once unless a CLI is still asked who is signed in:
|
||||
// then the fetch is counted and waits for it in its goroutine, as the page
|
||||
// doesn't wait on a CLI (#541), and isn't told nothing is coming before
|
||||
// that account's list does (#1789). The accounts are listed here only once
|
||||
// no CLI is left to wait on.
|
||||
// are due is known at once: no CLI is asked who is signed in for a list
|
||||
// FetchNew fetches, since every built-in that asked one is retired and its
|
||||
// plugin lists its own accounts.
|
||||
func fetchNewGo(timeout time.Duration) {
|
||||
run := func(fetch func()) {
|
||||
newRunning.Add(1)
|
||||
@@ -464,24 +462,7 @@ func fetchNewGo(timeout time.Duration) {
|
||||
run(func() { FetchNew(timeout) })
|
||||
return
|
||||
}
|
||||
behind := func() {
|
||||
run(func() {
|
||||
defer newFetches.Unlock()
|
||||
fetchNewHeld(timeout)
|
||||
})
|
||||
}
|
||||
if identitiesUnsettled() {
|
||||
behind()
|
||||
return
|
||||
}
|
||||
// no CLI left to ask, unless one was forgotten while they were listed
|
||||
// (a sign-in just finished): asked behind the page, as left out
|
||||
ps := All()
|
||||
if identitiesUnsettled() {
|
||||
behind()
|
||||
return
|
||||
}
|
||||
due, _ := newDue(ps)
|
||||
due, _ := newDue(All())
|
||||
if len(due) == 0 {
|
||||
newFetches.Unlock()
|
||||
fetchingNew.Store(false)
|
||||
@@ -523,18 +504,7 @@ func FetchNew(timeout time.Duration) (missing bool) {
|
||||
|
||||
// fetchNewHeld is FetchNew with newFetches held.
|
||||
func fetchNewHeld(timeout time.Duration) (missing bool) {
|
||||
// listing them asks a CLI who is signed in, if never asked: one that
|
||||
// hasn't answered yet is waited for, and they are listed again
|
||||
answered := identitiesAnswered()
|
||||
ps := All()
|
||||
// one answered since, while they were listed (its look gave up
|
||||
// waiting) or after: an account it says is signed in was left out
|
||||
if waited, unknown := awaitIdentities(timeout); unknown {
|
||||
missing = true
|
||||
} else if waited || answered != identitiesAnswered() {
|
||||
ps = All()
|
||||
}
|
||||
due, skipped := newDue(ps)
|
||||
due, skipped := newDue(All())
|
||||
if fetchDue(due, timeout) {
|
||||
missing = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user