A12: assigner_want_drop drops one want by hand, recorded first

The tool takes node, module and why: the act is recorded through the seat
mesh-hand-acts, then the key want.<node>.<module> is deleted from the state
wants; the next pass writes the want of the new form. Refused with no want
under the key, no why, no proven caller, or when the act is not recorded.

Builds: design 47 H §765; H-A-58

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-20 04:57:45 +01:00
parent 4613300bcd
commit 4923d22ac6
7 changed files with 115 additions and 5 deletions
@@ -124,7 +124,7 @@ func (c *compositionSteps) say1(ctx context.Context, id string, run meshwants.St
stopWait()
}()
phase := &stepPhase{phase: meshwants.StepProgressEventPhaseFetch}
stop := c.sayProgress(id, "", phase) // no asker known: the callers lists go (design 47 H §752, H-A-66)
stop := c.sayProgress(id, run.Asker, phase)
o := how(context.WithValue(ctx, phaseKey{}, phase), id, run)
stop()
if ctx.Err() != nil {
@@ -96,7 +96,8 @@ func TestARunningCompositionStepSaysItsProgress(t *testing.T) {
<-release
return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed}
}}
body, _ := json.Marshal(meshwants.StepRun{Pipeline: "main.4", Step: meshwants.StepRunStepComposition, Module: "m", Branch: "main"})
// A11/AC1 (design 47 H §752, H-A-88): with no callers in mesh-wants, the progress names the asker the step run carries.
body, _ := json.Marshal(meshwants.StepRun{Pipeline: "main.4", Step: meshwants.StepRunStepComposition, Module: "m", Branch: "main", Asker: "mesh-pipeline-runner"})
if !c.take(context.Background(), "ask-1", body) {
t.Fatal("the composition step is not taken")
}
@@ -110,7 +111,7 @@ func TestARunningCompositionStepSaysItsProgress(t *testing.T) {
said.mu.Lock()
p, ok := said.said[progress].(meshwants.StepProgressEvent)
said.mu.Unlock()
if !ok || p.Ask != "ask-1" || p.Asker != "" || p.Phase != meshwants.StepProgressEventPhaseRun || !p.At.Equal(at) ||
if !ok || p.Ask != "ask-1" || p.Asker != "mesh-pipeline-runner" || p.Phase != meshwants.StepProgressEventPhaseRun || !p.At.Equal(at) ||
len(p.Shared) != 1 || p.Shared[0].Ask != "run-1" { // the runs the step waits on (§723)
t.Fatalf("step-progress %+v", p)
}
@@ -420,6 +420,7 @@ func serveTools() error {
tools = append(tools, writtenTools(runtimeStore{})...)
tools = append(tools, whyTools(runtimeStore{})...)
tools = append(tools, askAgainTools(runtimeStore{}, stdio.Ask, time.Now)...)
tools = append(tools, wantDropTools(runtimeStore{}, stdio.Ask)...)
return stdio.Serve("", tools)
}
@@ -0,0 +1,62 @@
package main
import (
"encoding/json"
"errors"
"fmt"
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
stdio "git.novox.be/novox/mesh-sdk/go"
)
// wantDropTool drops one want of a node for a module by hand (design 47 H §765, H-A-58): a held or failed want of the earlier
// model goes at the clean state, its key deleted and the act written in the hand-act log; the next pass writes the want of the
// new form.
const wantDropTool = "assigner_want_drop"
// wantsState is the state the wants are kept in.
const wantsState = "wants"
// dropWant deletes the want of module on node, the act first recorded through the seat mesh-hand-acts.
func dropWant(st seatStore, ask func(string, any) (json.RawMessage, error), node, module, why, by string) (any, error) {
switch {
case node == "" || module == "":
return nil, errors.New("name the node and the module whose want is dropped")
case why == "":
return nil, errors.New("a want dropped by hand says why")
case by == "" || by == stdio.Unproven:
return nil, errors.New("a want dropped by hand names who drops it, and the runtime proved no caller")
}
key, err := mwc.WantKey(node, module)
if err != nil {
return nil, err
}
raw, _, found, err := st.get(wantsState, key)
if err != nil {
return nil, err
}
if !found {
return nil, fmt.Errorf("the assigner holds no want under %s", key)
}
taken, err := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: wantDropTool + " " + key, Why: why + " (" + by + ")", Cause: "want-drop"})
if err != nil {
return nil, fmt.Errorf("the drop of %s is not recorded, so the want stays: %w", key, err)
}
if err := st.del(wantsState, key); err != nil {
return nil, fmt.Errorf("the want %s is not dropped: %w", key, err)
}
return map[string]any{"key": key, "dropped": json.RawMessage(raw), "by": by, "hand-act": taken.Log}, nil
}
// wantDropTools is the tool over the runtime's states.
func wantDropTools(st seatStore, ask func(string, any) (json.RawMessage, error)) []stdio.Tool {
return []stdio.Tool{{Name: wantDropTool, Description: "Drop one want by hand (design 47 H §765): the want of module on node is " +
"deleted from the state wants, as the clean state drops a held or failed want of the earlier model; the next pass writes the " +
"want of the new form. Recorded as a hand act first; refused with no want under the key.",
Input: schema(map[string]string{"node": "the node's name", "module": "the module's name", "why": "why the want is dropped"},
[]string{"node", "module", "why"}),
Run: func(a map[string]any) (any, error) {
return dropWant(st, ask, arg(a, "node"), arg(a, "module"), arg(a, "why"), stdio.CallerOf(a))
}}}
}
@@ -0,0 +1,45 @@
package main
import (
"encoding/json"
"errors"
"strings"
"testing"
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
)
// A12/AC1 (design 47 H §765, H-A-58): assigner_want_drop with node, module and why records the act in the hand-act log first
// and then deletes that want; with no want under the key, no why or no proven caller, and when the act is not recorded, nothing is
// dropped.
func TestAWantIsDroppedByHandAndRecorded(t *testing.T) {
key, _ := mwc.WantKey("ace", "web")
held, _ := mwc.EncodeWant(mwc.Want{Fp: fpTest, Put: true, Hold: true, Words: "put: x"})
for _, c := range []struct {
name, node, module, why, by string
refuse error
dropped bool
}{
{"dropped", "ace", "web", "the clean state", "person.jochen", nil, true},
{"no want there", "ace", "db", "the clean state", "person.jochen", nil, false},
{"no why", "ace", "web", "", "person.jochen", nil, false},
{"no caller", "ace", "web", "the clean state", "", nil, false},
{"not recorded", "ace", "web", "the clean state", "person.jochen", errors.New("no responders"), false},
} {
st := memStore{wantsState: &memKV{values: map[string][]byte{key: held}}}
var asked []string
ask := func(verb string, body any) (json.RawMessage, error) {
raw, _ := json.Marshal(body)
asked = append(asked, verb+" "+string(raw))
return json.RawMessage(`{}`), c.refuse
}
out, err := dropWant(st, ask, c.node, c.module, c.why, c.by)
_, there := st[wantsState].values[key]
switch {
case c.dropped && (err != nil || there || len(asked) != 1 || !strings.Contains(asked[0], "seat:mesh-hand-acts.hand-act ") || !strings.Contains(asked[0], wantDropTool+" "+key)):
t.Errorf("%s: %v, %v; the want left %v, asked %v", c.name, out, err, there, asked)
case !c.dropped && (err == nil || !there):
t.Errorf("%s: %v, %v; the want left %v, want it refused and kept", c.name, out, err, there)
}
}
}
@@ -105,7 +105,7 @@ func TestManifest(t *testing.T) {
// which lists and asks again what each node's engine reads.
if !slices.Equal(m.Tools, []string{"assigner_put", "assigner_release", "assigner_puts", "assigner_waits", "assigner_inputs", "assigner_inputs_drop", "assigner_compositions", "assigner_compositions_drop", "assignments", "seat-holders", "wants", "asks",
"assigner_read_assignments", "assigner_read_seat_holders", "assigner_read_wants", "assigner_read_findings", "assigner_read_differences", "assigner_read_copies",
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why"}) {
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why", "assigner_want_drop"}) {
t.Errorf("the assigner serves tools %v, want its three put tools, three first views, six read tools, assigner_engine_reads, the seat list's two (ADR 0636 §7) assigner_ask_again (ADR 0668 §5) and assigner_why (design 47 G A-439)", m.Tools)
}
if m.RunsAs != m.Module || m.SecretsOwner != m.RunsAs {
+2 -1
View File
@@ -129,7 +129,8 @@
"assigner_seat_list_again",
"assigner_ask_again",
"assigner_written",
"assigner_why"
"assigner_why",
"assigner_want_drop"
],
"state": [
{ "name": "assignments", "history": 64 },