#1665: sideLogins took loginsMu, which also makes and locks
logins.json.lock, for every list of an agent's accounts. That is a dozen
lists for each page's read (google twice, copilot, chatgpt-api, qoder
and the rest), and nearly every one writes nothing. After the
rememberLogins fix, a lock trace of a sandbox start (MAGPIE_LOCKTRACE)
still showed ~55 sideLogins locks in the first 20s. An interposed run
counted 1107 opens of logins.json.lock over the run, nearly all of them
from sideLogins.
sideLogins now reads logins.json without the lock. keepSideLogins looks
(look=true), which changes and writes nothing and only says whether it
would. Only then does sideLogins take loginsMu, read the file again and
make the change, the same code as before. The look says "would change"
for every branch that writes. logins.json is only ever replaced whole
(writePrivate through steady.WriteFile: temp file, flush, rename), so an
unlocked read sees one write's file.
TestSideLoginsNothingToChangeTakesNoLock holds loginsMu and lists an
agent's accounts 100 times when nothing changes. It expects them to
return within 5s with the agent's own account listed. Then a new own
account must still be written. Both halves were broken by hand:
lock always taken:
--- FAIL: TestSideLoginsNothingToChangeTakesNoLock (5.34s)
side_logins_unlocked_test.go:34: a list with nothing to change waited for logins.json's lock
write never taken:
--- FAIL: TestSideLoginsNothingToChangeTakesNoLock (0.07s)
side_logins_unlocked_test.go:38: the agent's own account isn't listed: []
What was run (worktree at 9fd80b212 plus this change and the commits
before it):
gofmt -l internal/: nothing
go vet ./internal/provider: exit 0
GOOS=linux go vet -tags nogui ./...: exit 0
GOOS=windows go vet -tags nogui ./...: exit 0
go test -timeout 45m -count=1 ./internal/provider: ok 696.341s