switch: Claude Code near out or refused for its limit is moved on within a minute (#4443)

In switch-only mode, Claude Code asks Anthropic directly, so magpie learns
the active account is out only from a `claude -p /usage` read. That read was
due 5 to 15 minutes (claudeUsageWait) after the last one, and
KeepOnAnAccountWithRoom looked at Claude's sign-in only every 5 minutes.
Codex already had a 1-minute near-out cadence; Claude had none. mydosu's
account read 4% left at 12:16:15, which is under Smart's 98% threshold, so
it was rightly not moved then. It burnt through within the 5-minute gap,
and Claude Code refused for about 1.5 minutes until a hand switch, while
the other account had 100% left.

Changed:
- While Claude has an account to move to, the loop looks at its sign-in
  every claudeLookEvery (1 min) between the full looks (claudeLookDue).
- Near out (an all-model window at 90% or more, codexNearShare), the
  active account's /usage is due a minute after the last read instead of
  at its 5-15 minute wait (claudeWaitOf).
- When Claude Code writes its own rate_limit refusal ("You've hit your …
  limit": error "rate_limit", isApiErrorMessage) into a session in
  ~/.claude/projects/*/*.jsonl, the next look reads /usage at once and
  marks the reading stale (StaleAllowance). Only the bytes appended since
  the last scan are read (at most 1MB per session per scan). The first
  scan only marks where the sessions end. The refusal is a cue for the
  read, not a switch by itself: the transcript doesn't say which account
  was refused.
- Cost per minute: Logins("claude") plus leftAlone. With a spare, also a
  stat of each session file and a read of the appended bytes. /usage runs
  every minute only while the account is near out and in use, or after a
  refusal (30s floor still applies).

Run:
- New tests: TestClaudeNearOutIsReadEveryMinute,
  TestClaudeRefusalInSessionReadsAtOnce, TestScanClaudeLimits,
  TestKeepOnAnAccountWithRoomLooksAtClaudeNearOut. Pass under -race
  -count=3 on mote, with TestClaudeSwitchOnly* and TestClaudeUsage*.
- Broken by hand, each red: no near-out wait ->
  TestClaudeNearOutIsReadEveryMinute ("switched to \"\""); no refusal due
  -> TestClaudeRefusalInSessionReadsAtOnce; no in-between look in the loop
  -> TestKeepOnAnAccountWithRoomLooksAtClaudeNearOut (still on pro@x.com
  at its 1-minute deadline).
- Windows (xiaomi-gpu, win-run): the new and Claude tests pass. The whole
  internal/provider package has 13 reds there, and all 13 fail the same way
  run alone at origin/main d99e213f5: #2808 (keychain, SavedButSignedOut),
  #4115 (CodexDaemonEnv, CodexListTag), and #4446, filed now
  (TestCodexSignInKnown, TestGitOnDisk*).
- mote at eaa2eeb29 (this commit on fa427216a): gofmt -l clean; go vet
  (nogui, GOOS=linux nogui, GOOS=windows); go build for darwin, linux and
  windows; go test -tags nogui -count=1 -timeout 45m ./... exit 0, every
  package ok (gateway 672s, agent 268s, provider 173s).
- Rebased on 4 commits (gateway, plugin, provider/codex_models; none
  touch these files), at the pushed tree on mote: go vet (nogui, linux,
  windows), darwin and windows builds, internal/provider ok (213s) and
  internal/gateway ok (716s).

Not tried: a real Claude account running out, and a real Claude Code
session on Windows writing its refusal. The refusal line's format was
checked read-only against real local transcripts. No UI added.
This commit is contained in:
yetone
2026-10-30 22:05:12 +08:00
parent 2ec3453647
commit 2ff75161dc
5 changed files with 534 additions and 14 deletions
File diff suppressed because one or more lines are too long
+229
View File
@@ -0,0 +1,229 @@
package provider
// Claude Code on its own login asks Anthropic itself, so magpie learns the
// account it is on is out only from a /usage run, which unasked comes
// claudeUsageWait (5 to 15 minutes) after the last, and the switch looked
// only every loginSwitchEvery. An account burnt from 4% left to its limit
// in two minutes, and Claude Code said "You've hit your 5-hour limit" for
// over a minute while the other account had all of it left (#4443,
// mydosu). So while Claude has an account to move to, its sign-in is
// looked at every claudeLookEvery, and two things make that look read
// /usage at once rather than at its wait:
//
// - the account near out (claudeNearOut): read every claudeNearOutWait;
// - Claude Code having written a rate_limit refusal into one of its
// sessions since the last read (scanClaudeLimits), which is what it
// shows as "You've hit your … limit". Which account it was refused on
// the transcript doesn't say, so it is only the cue for the read; the
// read decides.
import (
"bufio"
"bytes"
"encoding/json"
"io"
"os"
"path/filepath"
"strings"
"sync"
"sync/atomic"
"time"
)
// claudeLookEvery is how often Claude's sign-in is looked at between
// KeepOnAnAccountWithRoom's full looks, while it has an account to move to.
// A var so tests can say.
var claudeLookEvery = time.Minute
// claudeNearOutWait is how long after a /usage run the next unasked one is
// due while the account Claude Code is on is near out, in place of
// claudeUsageWait.
const claudeNearOutWait = time.Minute
// claudeNearOut says the windows ws, of the account Claude Code is on, are
// near out: one that stops the account for every model is at
// codexNearShare or past.
func claudeNearOut(ws []QuotaWindow, now time.Time) bool {
return usedPast(SubscriptionQuota{Windows: ws}, codexNearShare, now)
}
// claudeWaitOf is how long after e's last /usage run the next unasked one
// of the account Claude Code is on is due.
func claudeWaitOf(e claudeUsageEntry, now time.Time) time.Duration {
if e.ws != nil && claudeNearOut(e.windows(now), now) {
return min(e.wait, claudeNearOutWait)
}
return e.wait
}
// claudeLimitHit is when Claude Code last wrote a rate_limit refusal into
// one of its sessions, as unix nanoseconds (zero: none seen).
var claudeLimitHit atomic.Int64
// claudeLimitHitAfter says Claude Code was refused for its limit after t.
func claudeLimitHitAfter(t time.Time) bool {
n := claudeLimitHit.Load()
return n != 0 && time.Unix(0, n).After(t)
}
// claudeTranscripts is where scanClaudeLimits got to: the sessions written
// to are read on from where the last scan stopped, so each line is read
// once.
var claudeTranscripts struct {
sync.Mutex
started bool
off map[string]int64
}
// claudeScanTail is the most of one session read by one scan: a refusal is
// the last line Claude Code writes, and a session that grew more than this
// since is read from its end.
const claudeScanTail = 1 << 20
// scanClaudeLimits reads what Claude Code wrote to its sessions (each
// project's *.jsonl) since the last scan and keeps the time of the latest
// rate_limit refusal in claudeLimitHit. The first scan only marks where the
// sessions end: what was refused before magpie looked is the startup
// read's to tell. Its cost is a stat of each session and a read of what
// was added to the ones written to.
func scanClaudeLimits() {
c := &claudeTranscripts
c.Lock()
defer c.Unlock()
projects := filepath.Join(filepath.Dir(claudeCredentialsPath()), "projects")
dirs, _ := os.ReadDir(projects)
off := make(map[string]int64, len(c.off))
for _, d := range dirs {
root := filepath.Join(projects, d.Name())
if !d.IsDir() {
if fi, err := os.Stat(root); err != nil || !fi.IsDir() {
continue
}
}
files, _ := os.ReadDir(root)
for _, f := range files {
if f.IsDir() || !strings.HasSuffix(f.Name(), ".jsonl") {
continue
}
fi, err := f.Info()
if err != nil {
continue
}
path := filepath.Join(root, f.Name())
was, known := c.off[path]
switch {
case !c.started:
off[path] = fi.Size()
case known && was == fi.Size():
off[path] = was
default:
if !known {
was = 0 // a session begun since the last scan
}
off[path] = scanClaudeSession(path, was, fi.Size())
}
}
}
c.off, c.started = off, true
}
// scanClaudeSession reads path from from to size for rate_limit refusals,
// and answers where it got to: the end of its last whole line, so a line
// still being written is read whole next time.
func scanClaudeSession(path string, from, size int64) int64 {
if size < from {
from = 0 // written over
}
start := max(from, size-claudeScanTail)
f, err := os.Open(path)
if err != nil {
return from
}
defer f.Close()
if _, err := f.Seek(start, io.SeekStart); err != nil {
return from
}
r := bufio.NewReader(io.LimitReader(f, size-start))
pos := start
if start > from {
// started mid-line: what is before the first newline is cut
skipped, err := r.ReadBytes('\n')
pos += int64(len(skipped))
if err != nil {
return size // all one line not ended, longer than any refusal
}
}
for {
line, err := r.ReadBytes('\n')
if err != nil {
return pos // the rest is a line not yet ended
}
pos += int64(len(line))
noteClaudeRefusal(line)
}
}
// claudeRefusal is what marks a line Claude Code writes for a refusal for
// the account's limit ("You've hit your session limit"), cheaply found
// before it is parsed.
var claudeRefusal = []byte(`"rate_limit"`)
// noteClaudeRefusal keeps the time of line in claudeLimitHit when it is
// Claude Code's own message for a rate_limit refusal.
func noteClaudeRefusal(line []byte) {
if !bytes.Contains(line, claudeRefusal) {
return
}
var m struct {
Error string `json:"error"`
APIError bool `json:"isApiErrorMessage"`
Timestamp string `json:"timestamp"`
}
if json.Unmarshal(line, &m) != nil || m.Error != "rate_limit" || !m.APIError {
return
}
at, err := time.Parse(time.RFC3339Nano, m.Timestamp)
if err != nil {
at = time.Now()
}
for {
was := claudeLimitHit.Load()
if at.UnixNano() <= was || claudeLimitHit.CompareAndSwap(was, at.UnixNano()) {
return
}
}
}
// claudeLookDue says Claude's sign-in is to be looked at before the next
// full look: it has an account to move to, and the account Claude Code is
// on is near out, or Claude Code was refused for its limit since that
// account's last /usage run. A refusal makes the account's reading stale
// (StaleAllowance), so the look reads it even with allowances read only
// when asked.
func claudeLookDue() bool {
if leftAlone("claude") {
return false
}
var active string
spare := false
for _, l := range Logins("claude") {
switch {
case l.Active:
active = l.User
case l.On && l.Lapsed == "" && l.home == "" && !l.Token:
spare = true
}
}
if active == "" || !spare {
return false
}
scanClaudeLimits()
claudeUsage.Lock()
e := claudeUsage.m[strings.ToLower(active)]
claudeUsage.Unlock()
if claudeLimitHitAfter(e.tried) {
StaleAllowance("claude", active)
return true
}
return e.ws != nil && claudeNearOut(e.windows(time.Now()), time.Now())
}
+256
View File
@@ -0,0 +1,256 @@
package provider
import (
"context"
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
)
// claudeOutSoon sets up #4443's case: Claude kept to Claude Code
// (switch-only), Claude Code on pro@x.com, max@x.com on with all of its
// allowance left, and /usage answering, for the account Claude Code is on,
// the share set last (set). The account Claude Code is on is read once, at
// first, and doesn't move on. It answers the spare, set, and a func that
// ages every reading by d, as the minutes between two looks do.
func claudeOutSoon(t *testing.T, first string) (spare string, set func(string), age func(d time.Duration)) {
t.Helper()
claudeThree(t) // pro@x.com signed in; team and max saved
var out atomic.Value
out.Store("")
fakeClaudeUsage(t, &out, nil)
claudeUsageWait = func() time.Duration { return 10 * time.Minute } // fakeClaudeUsage puts it back
forget := func() {
lastQuotas.Lock()
lastQuotas.m, lastQuotas.loaded = nil, false
lastQuotas.Unlock()
loginUsageCache.Lock()
loginUsageCache.m = nil
loginUsageCache.Unlock()
claudeLimitHit.Store(0)
claudeTranscripts.Lock()
claudeTranscripts.started, claudeTranscripts.off = false, nil
claudeTranscripts.Unlock()
}
forget()
t.Cleanup(forget)
if err := SetSwitchOnly("claude", true); err != nil {
t.Fatal(err)
}
for _, l := range Logins("claude") {
if strings.HasPrefix(l.User, "max@x.com") {
spare = l.User
if err := SetLoginOn("claude", l.User, true); err != nil {
t.Fatal(err)
}
}
}
if spare == "" {
t.Fatal("no max@x.com")
}
var mu sync.Mutex
active := first
set = func(s string) {
mu.Lock()
active = s
mu.Unlock()
}
UsageClaudeVia(func(_ context.Context, dir string) (string, error) {
mu.Lock()
defer mu.Unlock()
used := "0" // the spare
if dir == "" {
used = active
}
return "Current session: " + used + "% used · resets " + sessionReset(), nil
})
age = func(d time.Duration) {
loginUsageCache.Lock()
loginUsageCache.m = nil // the minute's cache gone
loginUsageCache.Unlock()
claudeUsage.Lock()
for k, e := range claudeUsage.m {
e.tried, e.at = e.tried.Add(-d), e.at.Add(-d)
claudeUsage.m[k] = e
}
claudeUsage.Unlock()
}
if to, err := SwitchWhenSpent(context.Background(), "claude"); err != nil || to != "" {
t.Fatalf("at %s%%: switched to %q: %v", first, to, err)
}
return spare, set, age
}
// The account Claude Code is on read near out (#4443: 4% left at
// 12:16:15) is read again a minute later, not at its 5 to 15 minutes'
// wait, and the look a minute later that finds it spent moves Claude Code
// on.
func TestClaudeNearOutIsReadEveryMinute(t *testing.T) {
spare, set, age := claudeOutSoon(t, "96")
if !claudeLookDue() {
t.Fatal("near out, but no look due before the next full one")
}
set("100")
age(claudeLookEvery)
if to, err := SwitchWhenSpent(context.Background(), "claude"); err != nil || to != spare {
t.Fatalf("a minute on, spent: switched to %q: %v, want %q", to, err, spare)
}
}
// Claude Code refused for its limit ("You've hit your 5-hour limit",
// written to its session) while the reading magpie has says room: the
// next look reads /usage at once, whatever its wait, and moves on.
func TestClaudeRefusalInSessionReadsAtOnce(t *testing.T) {
spare, set, age := claudeOutSoon(t, "50")
session := filepath.Join(filepath.Dir(claudeCredentialsPath()), "projects", "-work", "s1.jsonl")
writeSession(t, session, `{"type":"user","message":{"role":"user","content":"go"},"timestamp":"`+time.Now().UTC().Format(time.RFC3339Nano)+`"}`)
if claudeLookDue() {
t.Fatal("a look due at 50% with no refusal")
}
set("100")
age(2 * time.Minute)
if claudeLookDue() {
t.Fatal("a look due with no refusal written")
}
writeSession(t, session, claudeRefusalLine(time.Now()))
if !claudeLookDue() {
t.Fatal("Claude Code was refused, and no look is due")
}
if to, err := SwitchWhenSpent(context.Background(), "claude"); err != nil || to != spare {
t.Fatalf("after the refusal: switched to %q: %v, want %q", to, err, spare)
}
}
// What the scan of Claude Code's sessions counts: its own rate_limit
// message, written since the scan before, whole; not one from before
// magpie looked, a half-written line, nor the words in a tool's output.
func TestScanClaudeLimits(t *testing.T) {
claudeHome(t)
reset := func() {
claudeLimitHit.Store(0)
claudeTranscripts.Lock()
claudeTranscripts.started, claudeTranscripts.off = false, nil
claudeTranscripts.Unlock()
}
reset()
t.Cleanup(reset)
projects := filepath.Join(filepath.Dir(claudeCredentialsPath()), "projects")
old := filepath.Join(projects, "-a", "old.jsonl")
at := time.Now().Add(-time.Hour)
writeSession(t, old, claudeRefusalLine(at))
scanClaudeLimits()
if claudeLimitHitAfter(time.Time{}) {
t.Fatal("a refusal from before the first scan counted")
}
// a tool's output naming it, and a refusal half written
writeSession(t, old, `{"type":"user","message":{"content":[{"type":"tool_result","content":"\"error\":\"rate_limit\""}]},"timestamp":"`+time.Now().UTC().Format(time.RFC3339Nano)+`"}`)
now := time.Now().Add(-time.Second)
line := claudeRefusalLine(now)
appendRaw(t, old, line[:40])
scanClaudeLimits()
if claudeLimitHitAfter(time.Time{}) {
t.Fatal("a tool's output or a half-written line counted")
}
appendRaw(t, old, line[40:]+"\n")
scanClaudeLimits()
if !claudeLimitHitAfter(now.Add(-time.Millisecond)) || claudeLimitHitAfter(now) {
t.Fatalf("the refusal finished since: hit at %v, want %v", time.Unix(0, claudeLimitHit.Load()), now)
}
// a session begun since the last scan is read from its start
claudeLimitHit.Store(0)
writeSession(t, filepath.Join(projects, "-b", "new.jsonl"), claudeRefusalLine(time.Now()))
scanClaudeLimits()
if !claudeLimitHitAfter(now) {
t.Fatal("a refusal in a new session not counted")
}
}
// claudeRefusalLine is what Claude Code writes to its session when
// Anthropic refuses the account for its limit, as a real session has it.
func claudeRefusalLine(at time.Time) string {
return fmt.Sprintf(`{"parentUuid":"p","isSidechain":false,"type":"assistant","uuid":"u","timestamp":%q,"message":{"id":"m","container":null,"model":"<synthetic>","role":"assistant","stop_reason":"stop_sequence","stop_sequence":"","type":"message","usage":{"input_tokens":0,"output_tokens":0},"content":[{"type":"text","text":"You've hit your 5-hour limit · resets 5pm (UTC)"}]},"error":"rate_limit","isApiErrorMessage":true,"apiErrorStatus":429}`,
at.UTC().Format(time.RFC3339Nano))
}
// writeSession appends line, ended, to the session at path.
func writeSession(t *testing.T, path, line string) {
t.Helper()
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
appendRaw(t, path, line+"\n")
}
func appendRaw(t *testing.T, path, s string) {
t.Helper()
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
t.Fatal(err)
}
defer f.Close()
if _, err := f.WriteString(s); err != nil {
t.Fatal(err)
}
}
// The gateway's loop looks at Claude's sign-in between its five-minute
// looks while the account Claude Code is on is near out, and moves it on
// once a reading says it is spent: the account read at 96% at the first
// look, spent a minute on, is moved off before the next full look.
func TestKeepOnAnAccountWithRoomLooksAtClaudeNearOut(t *testing.T) {
spare, set, age := claudeOutSoon(t, "96")
oldFirst, oldEvery, oldLooked := firstSignInLook, claudeLookEvery, signInsLooked
firstSignInLook, claudeLookEvery = time.Millisecond, 10*time.Millisecond
fulls := make(chan struct{}, 1)
signInsLooked = func(full bool) {
if full {
select {
case fulls <- struct{}{}:
default:
}
}
}
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})
go func() {
defer close(done)
KeepOnAnAccountWithRoom(ctx)
}()
t.Cleanup(func() {
cancel()
<-done
firstSignInLook, claudeLookEvery, signInsLooked = oldFirst, oldEvery, oldLooked
})
// the full look done at 96%, the next is five minutes off
select {
case <-fulls:
case <-time.After(time.Minute):
t.Fatal("no full look")
}
if on := Logins("claude"); slices.ContainsFunc(on, func(l Login) bool { return l.Active && l.User == spare }) {
t.Fatal("moved on at 96%")
}
set("100")
age(claudeNearOutWait)
on := func() string {
for _, l := range Logins("claude") {
if l.Active {
return l.User
}
}
return ""
}
deadline := time.Now().Add(time.Minute)
for on() != spare {
if time.Now().After(deadline) {
t.Fatalf("Claude Code still on %q, want %q", on(), spare)
}
time.Sleep(10 * time.Millisecond)
}
}
+39 -10
View File
@@ -433,11 +433,14 @@ func noteCodexUsedUp(now bool) {
}
// KeepOnAnAccountWithRoom runs SwitchWhenSpent for Codex and Claude Code a
// minute after it starts and every loginSwitchEvery after that, until ctx
// ends, and keeps Claude Code's proxy that of its account
// (SyncClaudeProxyEnv).
// minute after it starts and every loginSwitchEvery after that (Codex's
// codexLookEvery), until ctx ends, and keeps Claude Code's proxy that of
// its account (SyncClaudeProxyEnv). Between those looks Claude's sign-in is
// looked at every claudeLookEvery when claudeLookDue: Claude Code asks
// Anthropic itself, and an account burnt fast was out minutes before the
// next look (#4443).
func KeepOnAnAccountWithRoom(ctx context.Context) {
t := time.NewTimer(time.Minute)
t := time.NewTimer(firstSignInLook)
defer t.Stop()
live := false
defer func() {
@@ -445,6 +448,7 @@ func KeepOnAnAccountWithRoom(ctx context.Context) {
codexLiveChecks.Add(-1)
}
}()
var full time.Time // when the next full look is due; zero: now
for {
select {
case <-ctx.Done():
@@ -458,12 +462,17 @@ func KeepOnAnAccountWithRoom(ctx context.Context) {
live = true
codexLiveChecks.Add(1)
}
for _, agent := range switchedAgents {
c, cancel := context.WithTimeout(ctx, time.Minute)
if _, err := SwitchWhenSpent(c, agent); err != nil {
log.Printf("%s: switching to an account with room: %v", agent, err)
claudeDue := claudeLookDue()
if time.Now().Before(full) {
if claudeDue {
lookAtSignIn(ctx, "claude")
}
cancel()
signInsLooked(false)
t.Reset(min(time.Until(full), claudeLookEvery))
continue
}
for _, agent := range switchedAgents {
lookAtSignIn(ctx, agent)
}
// a sign-in made in Claude Code itself, or a proxy picked since,
// takes its account's proxy too (#1807)
@@ -473,6 +482,26 @@ func KeepOnAnAccountWithRoom(ctx context.Context) {
cancel()
// Codex's own sign-in refused for good, or signed in again since
noteCodexGoneNow()
t.Reset(codexLookEvery(knownLoginUsage("codex")))
every := codexLookEvery(knownLoginUsage("codex"))
full = time.Now().Add(every)
signInsLooked(true)
t.Reset(min(every, claudeLookEvery))
}
}
// firstSignInLook is when KeepOnAnAccountWithRoom first looks. A var so
// tests can say.
var firstSignInLook = time.Minute
// signInsLooked is told after each of KeepOnAnAccountWithRoom's looks,
// whether it was a full one. A var so tests can wait on it.
var signInsLooked = func(full bool) {}
// lookAtSignIn is one look of KeepOnAnAccountWithRoom at agent's sign-in.
func lookAtSignIn(ctx context.Context, agent string) {
c, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
if _, err := SwitchWhenSpent(c, agent); err != nil {
log.Printf("%s: switching to an account with room: %v", agent, err)
}
}
+9 -3
View File
@@ -779,8 +779,10 @@ func AskUsage() {
// claudeWindows is the allowance of the Claude account user, read by
// Claude Code's own /usage. The account Claude Code is signed in to
// (active) is read when the user asked since it last was, or when the last
// reading's claudeUsageWait is up and Claude Code was used since. A saved
// (active) is read when the user asked since it last was, when the last
// reading's claudeUsageWait (claudeNearOutWait near out) is up and Claude
// Code was used since, or when Claude Code was refused for its limit
// since. A saved
// account is read only when its card is refreshed (savedRefresh), or when
// the switch off a spent account has no reading of it (spareRead), by
// Claude Code run in the account's own config directory
@@ -795,8 +797,12 @@ func claudeWindows(ctx context.Context, user string, active bool) ([]QuotaWindow
c.Lock()
e, ok := c.m[key]
c.Unlock()
// the account Claude Code is on is read sooner near out
// (claudeWaitOf), and at once once Claude Code was refused for its
// limit since (claudeLimitHitAfter, #4443)
due := e.tried.IsZero() || claudeAsked.Load() != 0 && asked > e.asked ||
active && now.Sub(e.tried) >= e.wait && (e.heard.After(e.tried) || claudeUsedSince(e.tried))
active && now.Sub(e.tried) >= claudeWaitOf(e, now) && (e.heard.After(e.tried) || claudeUsedSince(e.tried)) ||
active && claudeLimitHitAfter(e.tried)
// a saved account the switch off a spent one has no reading of
// (spareRead): read once, and again only after a wait while its read
// keeps failing, never every look