G10 records-end-with-their-record: an end writes each mover's and act's end after the head's, the ledger gives its own ended-days, record-retention goes

The ledger records asks max-mib 3072 and its own configuration max-age-days 90 and ended-days 30; record,
mover and act name ends-with ended, mover and act gain the field ended and the operation end. A record's
end writes the head's end first, then each mover's and act's with the head's ended; a reopening empties
theirs first, then the head's; a late running moves every one's end alike. The setting record-retention
leaves the manifest, its settings file and its code; the words of room name ended-days.

Builds: design 47 H2 H-A-634 (2), H-A-688, H-A-691, H-A-721
This commit is contained in:
2026-11-25 17:17:34 +01:00
parent c6f478aee9
commit b1b7940f4f
9 changed files with 179 additions and 75 deletions
@@ -61,7 +61,7 @@ func main() {
}
h.init()
h.SaySeat = stdio.SeatPublish
h.Records = &Records{Ledger: sdkLedger{}, Now: h.Now, Retention: h.recordRetention, Say: stdio.SeatPublish, Logf: logf, TooLarge: h.recordTooLarge,
h.Records = &Records{Ledger: sdkLedger{}, Now: h.Now, Say: stdio.SeatPublish, Logf: logf, TooLarge: h.recordTooLarge,
Class: seatCatalog{ask: stdio.Ask}.Class}
h.Records.Changed = h.recordChanged
h.Forge = seatGit{ask: stdio.Ask}
@@ -29,11 +29,12 @@ const MoversIndex = "movers"
// The operations of a mover's entry; the manifest's type mover declares exactly these (record_test.go).
const (
OpMover = "mover" // set-fields: its record's key, its module, its class, its pipeline and its version
// OpEntry and OpOutcome write its entries and outcomes as they did on the whole record.
// OpEntry and OpOutcome write its entries and outcomes as they did on the whole record; OpEnd (record.go) gives it the
// head's ended, its type's ends-with (design 47 H2 H-A-634 (2)).
)
// MoverOperations are a mover's operations, in the order the manifest's type allows them.
var MoverOperations = []string{OpMover, OpEntry, OpOutcome}
var MoverOperations = []string{OpMover, OpEntry, OpOutcome, OpEnd}
// OpMovers is the head entry's count of its movers (set-fields movers).
const OpMovers = "movers"
@@ -59,6 +60,8 @@ type Mover struct {
Class string `json:"class,omitempty"`
Entries map[string]RecordEntry `json:"entries,omitempty"`
Outcomes map[string]RecordOutcome `json:"outcomes,omitempty"`
// Ended is the head's ended, copied when the record ends; absent while the record is open (H-A-634 (2)).
Ended *RecordEnded `json:"ended,omitempty"`
}
// Running are the machines the mover runs healthy on, each with when it was first said.
@@ -71,6 +71,8 @@ type RecordAct struct {
Words string `json:"words,omitempty"`
At time.Time `json:"at"`
Owed seat.Owed `json:"owed"`
// Ended is the head's ended, copied when the record ends; absent while the record is open (H-A-634 (2)).
Ended *RecordEnded `json:"ended,omitempty"`
}
// TypeAct is the ledger type of an act's entry, and ActsIndex the ledger's index of the acts' entries on their record's key
@@ -81,7 +83,7 @@ const (
)
// ActOperations are an act's operations, in the order the manifest's type act allows them.
var ActOperations = []string{OpAct}
var ActOperations = []string{OpAct, OpEnd}
// ActInstance is the entry of a record's act: `act/<branch.source.act.id>`, escaped as a name.
func ActInstance(milestone, id string) (string, error) {
@@ -274,6 +274,50 @@ func TestTheDeliveryRecordIsALedgerInstanceKeyedByItsSourceRevision(t *testing.T
}
})
// Design 47 H2 H-A-634 (2): a record's end writes the head's end first, then an end on each of its movers and acts with the
// head's ended; a reopening empties theirs first, then the head's; an end written again moves every one's alike.
t.Run("an end writes the head, then each mover and act with its ended; a reopening empties theirs first", func(t *testing.T) {
l := newLedgerFake(t)
rs := &Records{Ledger: l, Now: func() time.Time { return at }}
r, _, err := rs.Open(opening("main", 91, heads))
if err != nil {
t.Fatal(err)
}
for _, module := range []string{"mod-b", "mod-a"} {
if err := rs.AddEntry(r, RecordEntry{Module: module, Fingerprint: "src2:f" + module}); err != nil {
t.Fatal(err)
}
}
if err := rs.Act(r, RecordAct{ID: "view@1.a", Act: "view", Repository: "novox/app", Number: 3, Head: heads["novox/app@3"]}); err != nil {
t.Fatal(err)
}
l.history = nil
if err := rs.End(r, "by hand", "person"); err != nil {
t.Fatal(err)
}
if len(l.history) != 4 || !strings.HasPrefix(l.history[0], "record/") || !strings.HasPrefix(l.history[3], "act/") ||
!strings.Contains(l.history[1], "mod-a") || !strings.Contains(l.history[2], "mod-b") {
t.Fatalf("an end wrote %v: the head's first, then each mover's by module, then each act's", l.history)
}
for _, inst := range l.history[1:3] {
inst = strings.TrimSuffix(inst, " end")
if !strings.Contains(string(l.states[inst]), `"ended":{"at":`) || !strings.Contains(string(l.states[inst]), `"why":"by hand"`) {
t.Errorf("%s holds %s: the head's ended copied", inst, l.states[inst])
}
}
l.history = nil
if err := rs.Reopen(r, 2); err != nil {
t.Fatal(err)
}
if len(l.history) != 4 || l.history[3] != r.Instance+" end" {
t.Fatalf("a reopening wrote %v: the movers' and acts' ended first, the head's last", l.history)
}
if inst := strings.TrimSuffix(l.history[0], " end"); !strings.HasPrefix(inst, "mover/") || strings.Contains(string(l.states[inst]), `"at"`) ||
r.Ended != nil || r.Movers()["mod-a"].Ended != nil {
t.Errorf("a reopened record's mover holds %s, the record ended %+v", l.states[inst], r.Ended)
}
})
// A record keeps its delivery time and class; gate_times judges them against the budgets (design 47 H2 §810; H-A-394).
t.Run("a core record ended 11 minutes after merge-called is over its budget", func(t *testing.T) {
now := at
@@ -442,37 +486,6 @@ func TestTheDeliveryRecordIsALedgerInstanceKeyedByItsSourceRevision(t *testing.T
t.Fatalf("list %+v", list)
}
})
t.Run("the setting record-retention, in days", func(t *testing.T) {
dir := t.TempDir()
for _, c := range []struct {
file string
want time.Duration
bad bool
}{
{`{}`, DefaultRecordRetention, false},
{`{"record-retention": 30}`, 30 * 24 * time.Hour, false},
{`{"record-retention": 0}`, 0, true},
{`{"record-retention": 1.5}`, 0, true},
{`{"record-retention": "90"}`, 0, true},
} {
p := filepath.Join(dir, "settings.json")
if err := os.WriteFile(p, []byte(c.file), 0o600); err != nil {
t.Fatal(err)
}
s, err := readSettings(p)
if (err != nil) != c.bad {
t.Fatalf("%s: %v", c.file, err)
}
if c.bad {
continue
}
h := &Holder{Settings: func() Settings { return s }}
if got := h.recordRetention(); got != c.want {
t.Fatalf("%s: %s, wanted %s", c.file, got, c.want)
}
}
})
}
// W11.1: the manifest's ledger types allow exactly the operations the gate applies, and the ledger is capped at 768 MiB.
@@ -488,9 +501,39 @@ func TestTheManifestsLedgerTypesAreTheRecordsOperations(t *testing.T) {
t.Errorf("the type %s allows %v, the gate applies %v", name, got, want)
}
}
// The records ledger's cap and its own configuration (design 47 H2 H-A-688, H-A-634 (2)): 3 GiB, its history kept 90 days,
// an ended instance's keys 30 days (7 or more, the judge's floor for a record a person may still read), and the ending
// types; the month lists' operations stay declared for the replay of the history and are applied by no part (H-A-691,
// H-A-721: no forget).
var manifest struct {
Requires []catalogue.BusStateEntry `json:"requires"`
Config map[string]json.RawMessage `json:"config"`
}
raw, _ := os.ReadFile(filepath.Join("..", "..", "module.json"))
if !strings.Contains(string(raw), `"max-mib": 1024`) {
t.Error("the records ledger is not capped at 1 GiB (design 47 H2 §809)")
if err := json.Unmarshal(raw, &manifest); err != nil {
t.Fatal(err)
}
for _, e := range manifest.Requires {
if e.Name != RecordsLedger {
continue
}
var days, kept int
_ = json.Unmarshal(e.Configuration[catalogue.ConfigEndedDays], &days)
_ = json.Unmarshal(e.Configuration[catalogue.OptionAgeDays], &kept)
if string(e.Options[catalogue.OptionCapMiB]) != "3072" || days < 7 || days > 30 || kept != 90 {
t.Errorf("the records ledger asks %v and %v: want max-mib 3072, ended-days from 7 to 30 and max-age-days 90", e.Options, e.Configuration)
}
for _, ty := range e.Types {
if (ty.Name == TypeRecord || ty.Name == TypeMover || ty.Name == TypeAct) != (ty.EndsWith == "ended") {
t.Errorf("the type %s ends with %q: record, mover and act end with ended, held with nothing", ty.Name, ty.EndsWith)
}
if _, has := ty.Schema["ended"]; ty.EndsWith != "" && !has {
t.Errorf("the type %s ends with a field its schema lacks", ty.Name)
}
}
}
if _, kept := manifest.Config["record-retention"]; kept || strings.Contains(string(raw), "forget") {
t.Error("the manifest keeps the setting record-retention or a forget: the bus ends a record's keys by ended-days (H-A-634 (2), H-A-721)")
}
if ix := l.types[TypeMover].Indexes; len(ix) != 1 || ix[0].Name != MoversIndex || !slices.Equal(ix[0].On, []string{"record"}) {
t.Errorf("the type mover's indexes are %+v, not one %s on its record's key", ix, MoversIndex)
@@ -167,6 +167,7 @@ func (rs *Records) end(r *Record, why, by string) error {
r.DeliveryTime, r.Class = took.String(), class
}
rs.keep(r)
rs.endEntries(r, &e)
if rs.Changed != nil {
rs.Changed(r, RecordChange{What: "ended", Why: why, Ended: true})
}
@@ -221,6 +222,7 @@ func (rs *Records) RanAfterEnd(r *Record, o RecordOutcome, applied bool) error {
r.DeliveryTime, r.Class = took.String(), class
}
rs.keep(r)
rs.endEntries(r, &e)
if rs.Logf != nil {
rs.Logf("[mesh-delivery] the record %s took the running of %s on %s at %s, after it ended at %s; it ends at %s, its delivery time %q, end %d",
r.Instance, o.Module, o.Node, o.At.UTC().Format(time.RFC3339Nano), was.UTC().Format(time.RFC3339Nano),
@@ -229,12 +231,72 @@ func (rs *Records) RanAfterEnd(r *Record, o RecordOutcome, applied bool) error {
return rs.sayEnded(r)
}
// endEntries writes the head's ended, or none (nil, a reopening), on each of the record's movers and acts by their `end`, so
// an ended record's entries all take the lifetime of its end and an open one's none (design 47 H2 H-A-634 (2)). A write that
// fails is said in the journal, the record, the instance and the error, and the record's end stands.
func (rs *Records) endEntries(r *Record, e *RecordEnded) {
var value any
if e != nil {
value = *e
}
say := func(instance string, err error) {
if rs.Logf != nil {
rs.Logf("[mesh-delivery] the record %s: the end of its entry %s is not written: %v", r.Instance, instance, err)
}
}
modules := make([]string, 0, len(r.movers))
for module := range r.movers {
modules = append(modules, module)
}
sort.Strings(modules)
for _, module := range modules {
m := r.movers[module]
next := *m
next.Ended = copyEnded(e)
seq, err := rs.write(r, m.Instance, OpEnd, map[string]any{"ended": value}, next)
if err != nil {
say(m.Instance, err)
continue
}
m.Ended, m.Sequence = next.Ended, seq
}
ids := make([]string, 0, len(r.Acts))
for id := range r.Acts {
ids = append(ids, id)
}
sort.Strings(ids)
for _, id := range ids {
inst, err := ActInstance(r.Milestone, id)
if err != nil {
say(id, err)
continue
}
a := r.Acts[id]
a.Ended = copyEnded(e)
if _, err := rs.write(r, inst, OpEnd, map[string]any{"ended": value}, a); err != nil {
say(inst, err)
continue
}
r.Acts[id] = a
}
}
func copyEnded(e *RecordEnded) *RecordEnded {
if e == nil {
return nil
}
c := *e
return &c
}
// Reopen reopens an ended record whose pipeline ended again with a higher end count (H-A-609 (2), H-A-728): its `ended` is
// emptied and pipeline-ends takes the count, its own end count staying; the next end says ends one higher.
func (rs *Records) Reopen(r *Record, pipelineEnds int) error {
if r.Ended == nil {
return nil
}
// Its movers' and acts' ended first, then the head's, so no open head has an entry whose key is ageing (H-A-634 (2)).
rs.endEntries(r, nil)
next := *r
next.Ended, next.PipelineEnds = nil, pipelineEnds
seq, err := rs.write(r, r.Instance, OpEnd, map[string]any{"ended": nil, "pipeline-ends": pipelineEnds}, next.head())
@@ -95,7 +95,7 @@ func (rs *Records) refuseFull(milestone, inst string) (before buscalls.Fill, rea
rs.sayFill(meshdelivery.SubjectFull, "full-"+inst, before,
"the next record, "+inst+" of "+milestone+"; its merge is held until room is said")
return before, true, fmt.Errorf("%w (%d of %d bytes): the record %s of %s is not opened, and its merge is held until "+
"room is said: the setting record-retention or a larger cap is the operator's", ErrRecordsFull, before.Bytes, before.MaxBytes, inst, milestone)
"room is said: ended-days of the ledger's own configuration or a larger cap is the operator's", ErrRecordsFull, before.Bytes, before.MaxBytes, inst, milestone)
}
// sayFilling says filling when the record just opened took the ledger past FillingPercent of its cap.
@@ -14,9 +14,6 @@ import (
// Settings are the operator's values for this module.
type Settings struct {
// RecordRetentionDays is how many days a delivery record is kept from when it opened (design 47 *The delivery
// record*); nil keeps DefaultRecordRetention.
RecordRetentionDays *int `json:"record-retention"`
// UntakenBoundMinutes is how many minutes a head may stand untaken before head-untaken is raised (design 47 H §740); nil
// keeps DefaultUntakenBound.
UntakenBoundMinutes *int `json:"untaken-bound"`
@@ -25,7 +22,7 @@ type Settings struct {
// DefaultUntakenBound is untaken-bound when the setting gives none (§740).
const DefaultUntakenBound = 10 * time.Minute
// readSettings reads the settings file; a value that is not a whole number of days, from 1 to 3650, is refused.
// readSettings reads the settings file; a value that is not a whole number of minutes, at least 1, is refused.
func readSettings(path string) (Settings, error) {
var s Settings
if path == "" {
@@ -39,17 +36,6 @@ func readSettings(path string) (Settings, error) {
if err := json.Unmarshal(raw, &loose); err != nil {
return s, fmt.Errorf("the settings file is not JSON: %v", err)
}
switch v := loose["record-retention"].(type) {
case nil:
case float64:
n := int(v)
if v < 1 || v > 3650 || v != float64(n) {
return Settings{}, errors.New("record-retention is not a whole number of days, from 1 to 3650")
}
s.RecordRetentionDays = &n
default:
return Settings{}, errors.New("record-retention is not a number")
}
switch v := loose["untaken-bound"].(type) {
case nil:
case float64:
@@ -63,14 +49,3 @@ func readSettings(path string) (Settings, error) {
}
return s, nil
}
// recordRetention is how long a delivery record is kept from when it opened.
func (h *Holder) recordRetention() time.Duration {
if h.Settings == nil {
return DefaultRecordRetention
}
if n := h.Settings().RecordRetentionDays; n != nil {
return time.Duration(*n) * 24 * time.Hour
}
return DefaultRecordRetention
}
@@ -1,4 +1,3 @@
{
"record-retention": 90,
"untaken-bound": 10
}
+30 -10
View File
@@ -38,11 +38,16 @@
"storage": "ledger",
"template": "ledger",
"options": {
"max-mib": 1024
"max-mib": 3072
},
"configuration": {
"max-age-days": 90,
"ended-days": 30
},
"types": [
{
"name": "record",
"ends-with": "ended",
"schema": {
"milestone": {
"type": "string"
@@ -210,6 +215,7 @@
},
{
"name": "mover",
"ends-with": "ended",
"schema": {
"record": {
"type": "string"
@@ -249,6 +255,9 @@
},
"class": {
"type": "string"
},
"ended": {
"type": "object"
}
},
"operations": [
@@ -294,6 +303,14 @@
"into": "outcomes",
"key": "key",
"sequence": true
},
{
"name": "end",
"effect": "set-fields",
"fields": [
"ended"
],
"sequence": true
}
],
"indexes": [
@@ -307,6 +324,7 @@
},
{
"name": "act",
"ends-with": "ended",
"schema": {
"record": {
"type": "string"
@@ -337,6 +355,9 @@
},
"owed": {
"type": "object"
},
"ended": {
"type": "object"
}
},
"operations": [
@@ -356,6 +377,14 @@
"owed"
],
"sequence": true
},
{
"name": "end",
"effect": "set-fields",
"fields": [
"ended"
],
"sequence": true
}
],
"indexes": [
@@ -470,14 +499,6 @@
"mesh-delivery-gate_state_prune_now"
],
"config": {
"record-retention": {
"type": "number",
"description": "days a delivery record is kept from when it opened (design 47 *The delivery record*): ninety covers every trace asked of a past delivery so far; when a record is removed at its retention, the gate says freed for each graph revision it pinned. Nothing else is removed to make room.",
"minimum": 1,
"maximum": 3650,
"trusted": false,
"default": 90
},
"untaken-bound": {
"type": "number",
"description": "minutes a watched branch's head may stand that no merge call delivered before the gate raises head-untaken (design 47 H §740); the gate keeps one deadline timer for the earliest.",
@@ -532,7 +553,6 @@
"path": "${dir:state}/settings.json",
"mode": "0600",
"takes-config": [
"record-retention",
"untaken-bound"
],
"merge": "json",