A3g item 1: a process holder's gate-unanswered rests on a bound key, and its act names no node
A waiting call's ask's 60 minutes are a key with its own time to live in the holder's state approvals, its end heard as the bus's marker, so no clock waits in the process; a call whose key ended while the holder was away is judged at its start. A process holder's act names no node, so two instances raise one ask. Builds: design 47 G §677, lead answer A-255 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
+41
-1
@@ -36,8 +36,9 @@ func (c *Conn) Gate(g Gating) *approval.Gate {
|
||||
if build == "" {
|
||||
build = OwnBuild().Fingerprint
|
||||
}
|
||||
state := c.State(approval.StateName)
|
||||
return approval.New(approval.Deps{Node: c.account.Node, Runner: c.account.Module, Holding: true, Build: build,
|
||||
State: c.State(approval.StateName), Channel: g.Channel, Findings: g.Findings, Logf: g.Logf,
|
||||
State: state, Bounds: heldBounds{state}, Channel: g.Channel, Findings: g.Findings, Logf: g.Logf,
|
||||
Warranted: func(asker, ask string, open func() (bool, error)) error {
|
||||
_, err := c.CallKeptWhileOpen(busretry.Open{Key: ask, Open: func(string) (bool, error) { return open() }, Logf: g.Logf},
|
||||
"seat:mesh-hand-acts.warranted", map[string]string{"asker": asker, "ask": ask})
|
||||
@@ -48,6 +49,45 @@ func (c *Conn) Gate(g Gating) *approval.Gate {
|
||||
}})
|
||||
}
|
||||
|
||||
// heldBounds is the holder's bound keys in its own state approvals (lead answer A-255): a key with its own time to live,
|
||||
// whose end the bus says as a marker that a watch hears, so a waiting call's 60 minutes need no clock in the process.
|
||||
type heldBounds struct{ s State }
|
||||
|
||||
func (b heldBounds) CreateTTL(key string, value any, ttl time.Duration) error {
|
||||
_, err := b.s.CreateTTL(key, value, ttl)
|
||||
return err
|
||||
}
|
||||
|
||||
func (b heldBounds) Delete(key string) error { return b.s.Delete(key) }
|
||||
|
||||
// Watch hands expired each key under pattern whose own time to live ended, heard from now on: the bus's marker of a time
|
||||
// to live is a purge, which this state's own writes never make (a delete is not one).
|
||||
func (b heldBounds) Watch(pattern string, expired func(key string)) (func(), error) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
bind, stop := context.WithTimeout(ctx, stateTimeout)
|
||||
kv, err := b.s.store(bind)
|
||||
stop()
|
||||
if err != nil {
|
||||
cancel()
|
||||
return nil, err
|
||||
}
|
||||
w, err := kv.Watch(ctx, watchPattern(pattern), jetstream.UpdatesOnly())
|
||||
if err != nil {
|
||||
cancel()
|
||||
return nil, fmt.Errorf("%s's state %s, watching %q: %w", b.s.Module, b.s.Name, pattern, err)
|
||||
}
|
||||
go func() {
|
||||
defer cancel()
|
||||
defer func() { _ = w.Stop() }()
|
||||
for e := range w.Updates() {
|
||||
if e != nil && e.Operation() == jetstream.KeyValuePurge {
|
||||
expired(e.Key())
|
||||
}
|
||||
}
|
||||
}()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
// HearDecided hands the gate each `decided` of the holder's own asks that hub hears (§677): only the ask's id is read
|
||||
// from it, the gate reading the router's own record.
|
||||
func HearDecided(g *approval.Gate, ch approval.Channel, module string, hub *EventHub) error {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/approval"
|
||||
"git.novox.be/novox/mesh-sdk/go/operatorask"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
@@ -98,7 +99,8 @@ func TestAProcessHoldersMarkedVerbIsAskedApprovedRunAndRecorded(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: "holder_" + approval.StateName, TTL: 48 * time.Hour}); err != nil {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: "holder_" + approval.StateName, TTL: 48 * time.Hour,
|
||||
LimitMarkerTTL: time.Minute}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: EventsStream, Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.operator-channel.event.>"}}); err != nil {
|
||||
@@ -238,6 +240,54 @@ func TestAProcessHoldersMarkedVerbIsAskedApprovedRunAndRecorded(t *testing.T) {
|
||||
t.Errorf("ran %d", ran)
|
||||
}
|
||||
})
|
||||
t.Run("a waiting call's bound key is kept with its time to live, and its end is heard", func(t *testing.T) {
|
||||
// A-255: gate-unanswered rests on a bound key in the state approvals, never a clock wait.
|
||||
state := holder.State(approval.StateName)
|
||||
kept := make(chan string, 1)
|
||||
if err := state.Watch("unanswered.*", func(c stdio.StateChange) error {
|
||||
if c.Op == stdio.OpPut && !c.Current {
|
||||
kept <- c.Key
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
done := callWipe(map[string]string{"dir": "bound"})
|
||||
a := asked()
|
||||
var bound string
|
||||
select {
|
||||
case bound = <-kept:
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("no bound key kept within 10s")
|
||||
}
|
||||
decide(a, approval.OptionDecline)
|
||||
wait(done)
|
||||
if e, _ := state.Get(bound); e != nil {
|
||||
t.Errorf("the bound %s of an ended call is kept", bound)
|
||||
}
|
||||
heard := make(chan string, 2)
|
||||
stop, err := heldBounds{state}.Watch("unanswered.*", func(k string) { heard <- k })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer stop()
|
||||
b := heldBounds{state}
|
||||
if err := b.CreateTTL("unanswered.gone", map[string]string{}, MinTTL); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := b.CreateTTL("unanswered.deleted", map[string]string{}, time.Hour); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = b.Delete("unanswered.deleted")
|
||||
select {
|
||||
case k := <-heard:
|
||||
if k != "unanswered.gone" {
|
||||
t.Errorf("heard %s", k)
|
||||
}
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("the bound key's end was not heard within 10s")
|
||||
}
|
||||
})
|
||||
t.Run("failing closed: no gate, or no state approvals", func(t *testing.T) {
|
||||
if _, err := holder.AnswerSeat("bare", marked("bare"), wipe); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user