H-A-311 (3) review: the health reads records keeping revisions; a required step waiting is open

runner_health, show, list and stands refused every pipeline record
carrying the runner's own kept-revisions ("unknown field
kept-revisions" on main.131 and main.137): the field is now dropped
before the seat's strict decode. A required step waiting (an approval,
a pin-held step) now counts as open, as the end's judgement holds it.

Builds: design 47 H H-A-311 (3), H-A-313, H-A-285, H-A-309, H-A-322
This commit is contained in:
2026-11-21 20:53:04 +01:00
parent f22945c26a
commit 05d9f90bdb
5 changed files with 50 additions and 5 deletions
@@ -21,11 +21,13 @@ const StateConsumers = process.ConsumersState
const BehindAfter = 5 * time.Minute
// StalledAfter is how long a running pipeline may have nothing open and nothing newly placed before the runner's health
// names it stalled (H-A-311 (3)).
// names it stalled (H-A-311 (3)): the mesh's own rule for nothing moving (nothing-moved-in-five-minutes), not a setting
// (H-A-322).
const StalledAfter = 5 * time.Minute
// Stalled is the key of each running pipeline, as show reads it, that has had nothing open (no step asked and not ended)
// and nothing newly placed, started or ended for StalledAfter at now (H-A-311 (3)), each with how long, in key order.
// Stalled is the key of each running pipeline, as show reads it, that has had nothing open (no step asked and not ended,
// no required step waiting) and nothing newly placed, started or ended for StalledAfter at now (H-A-311 (3)), each with
// how long, in key order.
func Stalled(pipelines Kept, now time.Time) ([]string, error) {
all, err := Reads{Pipelines: pipelines}.pipelines()
if err != nil {
@@ -38,7 +40,9 @@ func Stalled(pipelines Kept, now time.Time) ([]string, error) {
}
last, busy := startedOf(p), false
for _, st := range p.Steps {
if open(st) {
// A required step waiting (an approval on the operator, a pin-held step, a composition on its validate) is open,
// as the end's judgement holds it; an optional one waiting holds nothing (A-104).
if open(st) || (st.Outcome == seat.StepResultOutcomeWaiting && st.Status == seat.StepResultStatusRequired) {
busy = true
break
}
@@ -56,6 +56,11 @@ func TestHealth(t *testing.T) {
"main.137 (nothing open and nothing placed for 6m0s)"},
{"a pipeline quiet four minutes is not", piped(now, "main.137", -4*time.Minute, seat.StepResultOutcomePassed), age("n_runner", 0), true, ""},
{"a pipeline with a step open is not", piped(now, "main.137", -20*time.Minute, seat.StepResultOutcomeRunning), age("n_runner", 0), true, ""},
// H-A-285, H-A-309: a record carrying the runner's kept-revisions is read, not refused.
{"a quiet pipeline keeping revisions is named", kept(piped(now, "main.131", -6*time.Minute, seat.StepResultOutcomePassed), "main.131"), age("n_runner", 0), false,
"main.131 (nothing open and nothing placed for 6m0s)"},
// A required step waiting (an approval on the operator) is open, as the end's judgement holds it.
{"a pipeline whose approval waits is not", piped(now, "main.137", -20*time.Minute, seat.StepResultOutcomeWaiting), age("n_runner", 0), true, ""},
}
for _, r := range rows {
a := Health(r.pipelines, r.consumers, now)
@@ -70,10 +75,22 @@ func TestHealth(t *testing.T) {
func piped(now time.Time, key string, moved time.Duration, outcome string) mapKept {
at, started := now.Add(moved), now.Add(-time.Hour)
st := seat.StepResult{Module: "app", Step: seat.StepResultStepBuild, Outcome: outcome, Status: seat.StepResultStatusRequired, Started: &at}
if outcome != seat.StepResultOutcomeRunning {
if outcome == seat.StepResultOutcomeWaiting {
st.Step, st.On = seat.StepResultStepApproval, seat.WaitOnPerson
} else if outcome != seat.StepResultOutcomeRunning {
st.Ended = &at
}
raw, _ := json.Marshal(seat.Pipeline{Pipeline: key, Branch: "main", Outcome: seat.PipelineOutcomeRunning, Started: &started,
Movers: []seat.Mover{{Module: "app"}}, Steps: []seat.StepResult{st}})
return mapKept{key: raw}
}
// kept is m with key's record carrying the runner's kept-revisions (H-A-285).
func kept(m mapKept, key string) mapKept {
raw, err := withKept(m[key], map[string]int64{"app": 130})
if err != nil {
panic(err)
}
m[key] = raw
return m
}
@@ -332,6 +332,20 @@ func keptOf(raw []byte) (map[string]int64, error) {
return kept, nil
}
// withoutKept is record without its kept-revisions, the runner's own property and never part of the seat's Go form, so the
// seat's strict decode of the record the runner's reads make refuses no record carrying it (H-A-285, H-A-309).
func withoutKept(record []byte) ([]byte, error) {
var fields map[string]json.RawMessage
if err := json.Unmarshal(record, &fields); err != nil {
return nil, fmt.Errorf("the record is no object: %w", err)
}
if _, ok := fields[keptRevisionsField]; !ok {
return record, nil
}
delete(fields, keptRevisionsField)
return json.Marshal(fields)
}
// withKept is record with kept as its kept-revisions.
func withKept(record []byte, kept map[string]int64) ([]byte, error) {
var fields map[string]json.RawMessage
@@ -206,6 +206,10 @@ func (r Reads) pipelineOf(key string, all []string) (seat.Pipeline, bool, error)
if raw == nil {
return seat.Pipeline{}, false, nil
}
raw, err = withoutKept(raw)
if err != nil {
return seat.Pipeline{}, false, fmt.Errorf("%s %s: %w", seat.StatePipelines, key, err)
}
p, err := seat.DecodePipelinesByBranchRevisionValue(raw)
if err != nil {
return seat.Pipeline{}, false, fmt.Errorf("%s %s: %w", seat.StatePipelines, key, err)
@@ -53,6 +53,12 @@ func TestReads(t *testing.T) {
// A pipeline kept as H-A-187 keeps it: its record's steps empty, each mover's under steps.<pipeline>.<mover>.
put(t, pipes, "next.8", seat.Pipeline{Pipeline: "next.8", Branch: "next", Source: 8, Outcome: seat.PipelineOutcomeRunning,
Started: &t0, Steps: []seat.StepResult{}, Movers: []seat.Mover{{Module: "delta", Commit: "n8"}, {Module: "epsilon", Commit: "n8"}}})
// H-A-285, H-A-309: the record carries the runner's own kept-revisions, which show, list and stands read past.
withRevs, err := withKept(pipes["next.8"], map[string]int64{"delta": 7})
if err != nil {
t.Fatal(err)
}
pipes["next.8"] = withRevs
put(t, pipes, "steps.next.8.epsilon", seat.PipelinesByStepsPipelineMoverValue{Steps: []seat.StepResult{{Module: "epsilon",
Step: seat.StepResultStepBuild, Status: "required", Outcome: seat.StepResultOutcomePassed, Output: "next.8.build.epsilon:program"}}})
put(t, pipes, "steps.next.8.delta", seat.PipelinesByStepsPipelineMoverValue{Steps: []seat.StepResult{{Module: "delta",