E2: take a compose-candidate ask once by its id

The holder of mesh-wants asks each node-engine compose-candidate as a kept
call, so the same ask may come again on a transport fault. The engine reads
the ask id from the request header, keeps it in its own state taken for
compose-ask-bound (process.StateOver over the link it serves its seat on),
and a repeat while the ask's run goes joins that run and gets the answer
composed once; a repeat after the run ended is composed again, since the
verb is a read and no answer is kept. The manifest declares taken with its
8 MiB cap.

Builds: design 47 H2 §775, §820; H-A-351, H-A-364, H-A-383
This commit is contained in:
2026-11-22 00:10:01 +01:00
parent b33061088a
commit f5dcea2f10
15 changed files with 282 additions and 69 deletions
+4 -3
View File
@@ -428,8 +428,9 @@ func packagesFrom(node string, session *link.Session, composer *atomic.Pointer[s
// nec.AnswerBound, selfcompose candidateWithin). The answer is
// the seat's shape (nodeengine.ComposeCandidateAnswer), checked as it is encoded; a node whose shadow does not run yet
// answers unready, which the checker takes as no answer.
func composeCandidateFrom(node string, shadow *atomic.Pointer[selfcompose.Shadow]) func(candidate string, input bool, call string, line buscalls.ChunkLine) (any, error) {
return func(candidate string, input bool, call string, line buscalls.ChunkLine) (any, error) {
// An ask carrying an id is taken once by it (design 47 H2 §775, H-A-364).
func composeCandidateFrom(node string, shadow *atomic.Pointer[selfcompose.Shadow]) func(candidate string, input bool, call, askID string, line buscalls.ChunkLine) (any, error) {
return func(candidate string, input bool, call, askID string, line buscalls.ChunkLine) (any, error) {
ask := nodeengine.ComposeCandidateInput{Candidate: candidate, Input: input, Call: call}
if _, err := nec.EncodeAsk(ask); err != nil {
return nil, err
@@ -442,7 +443,7 @@ func composeCandidateFrom(node string, shadow *atomic.Pointer[selfcompose.Shadow
} else {
ctx, cancel := context.WithTimeout(context.Background(), nec.AnswerBound)
defer cancel()
a = s.ComposeCandidate(ctx, ask)
a = s.ComposeCandidate(ctx, ask, askID)
}
return answerComposeCandidate(a, candidate, input, call, line)
}
+2
View File
@@ -1241,6 +1241,8 @@ func composerEnv(session *link.Session, node string, say func(string), hooks com
return session.AskSeat(ctx, nodepacketfilter.Seat, nodepacketfilter.VerbAllowed, nodepacketfilter.AllowedInput{}, within)
}
env.ComposeAskBound = composeAskBound()
// And the state taken, where an ask of the seat's verbs is taken once by its id (design 47 H2 §775, H-A-364).
env.Taken = session.TakeOnce
return env
}
+2 -2
View File
@@ -866,7 +866,7 @@ func h8candidate(t *testing.T, b *itBed, fp, running string) {
before, _ := b.composed.Status()
// A-237c: asked with input and no call token (the checker's, until G removes it, G-6 §321) an input past what one answer carries
// is refused; asked with a token it is sent in chunks through the engine's call, whatever its size (A-237b).
if over, err := composeCandidateFrom(itNode, &shadowNow)(key, true, "", nil); err != nil {
if over, err := composeCandidateFrom(itNode, &shadowNow)(key, true, "", "", nil); err != nil {
t.Fatal(err)
} else if a, err := nec.DecodeAnswer(over.(json.RawMessage)); err != nil || a.Verdict != nec.Refused || !strings.Contains(a.Refused, "an answer on the bus carries") || a.Input != nil {
t.Errorf("an input over the inline bound asked with no token answered %+v (%v)", a, err)
@@ -900,7 +900,7 @@ func h8candidate(t *testing.T, b *itBed, fp, running string) {
if len(file) <= 900<<10 || !json.Valid(file) {
t.Errorf("the chunks held %d bytes, want a JSON input over 900 KiB", len(file))
}
got, err := composeCandidateFrom(itNode, &shadowNow)(key, false, "", nil)
got, err := composeCandidateFrom(itNode, &shadowNow)(key, false, "", "", nil)
if err != nil {
t.Fatal(err)
}
+13 -4
View File
@@ -36,9 +36,9 @@ import (
// says the events; the grants part composes the node's subjects from the manifest, so the test adds them to the node's grant.
func TestNatsTheRecoveryStepAsksHearsBoundsAndCatchesUpOverTheBus(t *testing.T) {
perms := nodegrant.For(itNode)
perms.Publish = append(perms.Publish, "$JS.API.>", "$KV.mesh-host_bounds.>", "mesh.seat.mesh-recovery.call.*.node~"+itNode,
perms.Publish = append(perms.Publish, "$JS.API.>", "$KV.mesh-host_bounds.>", "$KV."+link.TakenBucket+".>", "mesh.seat.mesh-recovery.call.*.node~"+itNode,
"mesh.mod.db.tool.rebuild."+itNode)
perms.Subscribe = append(perms.Subscribe, "mesh.seat.mesh-recovery.event.>", "$KV.mesh-host_bounds.>", "_INBOX.>", "$JS.ACK.>", "$JS.FC.>")
perms.Subscribe = append(perms.Subscribe, "mesh.seat.mesh-recovery.event.>", "$KV.mesh-host_bounds.>", "$KV."+link.TakenBucket+".>", "_INBOX.>", "$JS.ACK.>", "$JS.FC.>")
b := newItBedAs(t, perms)
ctx := context.Background()
@@ -52,8 +52,10 @@ func TestNatsTheRecoveryStepAsksHearsBoundsAndCatchesUpOverTheBus(t *testing.T)
if err != nil {
t.Fatal(err)
}
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: link.BoundsBucket, History: 1, LimitMarkerTTL: time.Second}); err != nil {
t.Fatal(err)
for _, bucket := range []string{link.BoundsBucket, link.TakenBucket} {
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: bucket, History: 1, LimitMarkerTTL: time.Second}); err != nil {
t.Fatal(err)
}
}
say := func(act, outcome string) {
raw, _ := json.Marshal(meshrecovery.RestoredEvent{Act: act, Module: "db", Kept: "cache", Outcome: outcome, At: time.Now().UTC()})
@@ -133,6 +135,13 @@ func TestNatsTheRecoveryStepAsksHearsBoundsAndCatchesUpOverTheBus(t *testing.T)
say("old", meshrecovery.RestoredEventOutcomeFailed) // said before anyone listens: the last message of the subject
session := b.startSession()
r := recoveryEnv(session, nil)
// Design 47 H2 §775, H-A-364: over the same session, an ask of the seat is taken once in the state taken: the first time,
// and never again within its bound.
for i, want := range []bool{true, false} {
if took, err := session.TakeOnce(nodeengine.Seat, "ask-1", time.Minute); err != nil || took != want {
t.Fatalf("take %d of ask-1: %v, %v; want %v", i+1, took, err, want)
}
}
events, stop, err := r.Hear(ctx, "restored", "db", "cache")
if err != nil {