Read the newest steps first: sort the node's keys by id (start order) before the cut, and say older steps were not read
mesh/delivery merged: source.main moved to novox/mesh-catalog@567736f7795a
mesh/check failed: integration: meshbuildnode/cmd/mesh-build-node.TestAFixtureBundleBuiltTwiceHasOneDigest: no toolchain of this lock is installed und…

The review found a cut read took an arbitrary 1000 keys, so the newest steps could be missing. A step id is
base-36 milliseconds plus random digits, so its string order is its start order; the newest max(limit*4, 100)
keys are read now, 1000 at most. The toolchains read logs when it drops keys past its cap.
This commit is contained in:
2026-10-26 00:43:53 +01:00
parent 8f9c78bcba
commit e901769cb2
6 changed files with 60 additions and 43 deletions
@@ -131,8 +131,9 @@ type StepLine struct {
}
// RecentSteps are this node's steps, the latest started first, at most limit (ten when limit is not above zero). Only
// the node's own keys (<node>.) are read, at most MaxStateReads of them; cut says more were stored than were read, so
// the newest may be missing. A step's id says nothing of when it started, so the values are what orders them.
// the node's own keys (<node>.) are listed and the newest max(limit*4, 100) of them read (at most MaxStateReads): a step's
// id is base-36 milliseconds and random digits, so its string order is its start order. cut says older steps were not
// read. The values still order the lines, since an ask step's id carries the ask time.
func (m *Module) RecentSteps(limit int) (lines []StepLine, cut bool, err error) {
if limit <= 0 {
limit = 10
@@ -153,8 +154,9 @@ func (m *Module) RecentSteps(limit int) (lines []StepLine, cut bool, err error)
}
}
}
if len(own) > MaxStateReads {
own, cut = own[:MaxStateReads], true
sort.Sort(sort.Reverse(sort.StringSlice(own)))
if n := min(max(limit*4, 100), MaxStateReads); len(own) > n {
own, cut = own[:n], true
}
raws, err := readValues(own, m.ReadSteps.Get)
log.Printf("steps read: %d of %d keys listed read in %v (cut %v)", len(own), len(keys), time.Since(start).Round(time.Millisecond), cut)
@@ -197,11 +199,12 @@ func (m *Module) ReadToolchains() (map[string]delivery.Toolchain, error) {
if err != nil {
return nil, err
}
if len(keys) > MaxStateReads {
cut := len(keys) > MaxStateReads
if cut {
keys = keys[:MaxStateReads] // a node has a key per language: far fewer in practice
}
raws, err := readValues(keys, m.ReadToolchainsState.Get)
log.Printf("toolchains read: %d keys read in %v", len(keys), time.Since(start).Round(time.Millisecond))
log.Printf("toolchains read: %d keys read in %v (cut %v: keys past %d were not read)", len(keys), time.Since(start).Round(time.Millisecond), cut, MaxStateReads)
if err != nil {
return nil, err
}
@@ -242,7 +245,7 @@ func (m *Module) ReadTools() []stdio.Tool {
ans := map[string]any{"node": m.Node, "steps": steps}
if cut {
ans["cut"] = true
ans["note"] = fmt.Sprintf("this node has more than %d steps stored; %d were read, so the newest may be missing", MaxStateReads, MaxStateReads)
ans["note"] = fmt.Sprintf("this node has more steps stored than one call reads; older steps were not read (ask for a larger limit, at most %d reads)", MaxStateReads)
}
return ans, err
}},