conn.AnswerSeat holds a verb its seat definition marks needs-approval through the
holder's gate (process.Conn.Gate, go/approval held.go): waiting calls call.<id>,
act.<escaped digest> by create or compare-and-set, claimed.<ask id> by create; a
call carrying the x-wait: held header answered {asked, call} in the reply's field
held; on the router's record read under the module's name, the oldest waiting call
run once within 30 minutes of the Approve and recorded through
mesh-hand-acts.warranted, the others asked anew; declined unasked for 10 minutes;
expired and refused ends; every end said on gated-ended.<caller>.<call>; the read
at start; gate-unanswered past the ask's 60 minutes; the verb approvals. A call
without the header takes ADR 0286 §37's path. process.Conn's seat call sends the
header on every seat call and, answered held, waits on its own gated-ended.
Builds: design 47 G §677, §700, lead answers A-158, A-186, A-209, A-219, A-224, A-228, A-244
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
101 lines
3.4 KiB
Go
101 lines
3.4 KiB
Go
package approval
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// UnreadableAfter is how long the state approvals fails before the runner's finding says so (§19).
|
|
const UnreadableAfter = 5 * time.Minute
|
|
|
|
// unreadableKey is the bound key whose expiry raises `approvals-unreadable` (lead answer A-157).
|
|
func (g *Gate) unreadableKey() string { return g.d.Node + ".unreadable." + StateName }
|
|
|
|
// held says why no marked call can be asked now, or "" (§19): no module holds operator-channel, as the assigner's view
|
|
// of the seat's holders says, or that view is not read.
|
|
func (g *Gate) held() string {
|
|
if g.d.Channel == nil {
|
|
return "the tool runner reaches no operator channel to ask on"
|
|
}
|
|
if g.d.Holder == nil && g.d.Holding {
|
|
return "" // a process holder reads no view of the seats' holders: an ask nobody takes is said by its gate-unanswered (design 47 G §677)
|
|
}
|
|
if g.d.Holder == nil {
|
|
return "the tool runner reads no view of the seats' holders, so it cannot tell that a module holds " + g.d.Channel.Seat()
|
|
}
|
|
on := g.d.Channel.Seat()
|
|
ok, err := g.d.Holder(on)
|
|
switch {
|
|
case err != nil:
|
|
return fmt.Sprintf("whether a module holds %s cannot be read: %v", on, err)
|
|
case !ok:
|
|
return "no module holds " + on + ", so nobody can be asked"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// stateFailed notes that the state approvals could not be read or written: no marked call runs on this machine until it
|
|
// can, the failed read or write is made again at the next marked call and at the next membership change (A-157), and
|
|
// five minutes on the runner's finding says it (§19).
|
|
func (g *Gate) stateFailed(err error) {
|
|
g.mu.Lock()
|
|
first := g.failingSince.IsZero()
|
|
if first {
|
|
g.failingSince = g.d.Now()
|
|
}
|
|
g.mu.Unlock()
|
|
if first {
|
|
g.d.Logf("[approval] the state %s on %s cannot be read or written (%v): no marked call runs here until it can", StateName, g.d.Node, err)
|
|
if g.d.Bounds != nil {
|
|
if e := g.d.Bounds.CreateTTL(g.unreadableKey(), map[string]string{"since": g.d.Now().UTC().Format(time.RFC3339)}, UnreadableAfter); e != nil {
|
|
g.d.Logf("[approval] the bound of the state %s's failure is not kept: %v", StateName, e)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// stateRead notes that the state approvals was read or written: a failure noted before ends, its finding cleared.
|
|
func (g *Gate) stateRead() {
|
|
g.mu.Lock()
|
|
was := !g.failingSince.IsZero()
|
|
g.failingSince = time.Time{}
|
|
g.mu.Unlock()
|
|
if !was {
|
|
return
|
|
}
|
|
if g.d.Bounds != nil {
|
|
_ = g.d.Bounds.Delete(g.unreadableKey())
|
|
}
|
|
g.finding(StateName, KindApprovalsUnreadable, false, "the state "+StateName+" is read again", "")
|
|
}
|
|
|
|
// failing says the state approvals is failing now.
|
|
func (g *Gate) failing() bool {
|
|
g.mu.Lock()
|
|
defer g.mu.Unlock()
|
|
return !g.failingSince.IsZero()
|
|
}
|
|
|
|
// StateAgain makes the failed read of the state approvals again: at the next membership change the runner hears (A-157).
|
|
func (g *Gate) StateAgain() {
|
|
if g.d.State == nil || !g.failing() {
|
|
return
|
|
}
|
|
if _, err := g.d.State.Keys(); err != nil {
|
|
return
|
|
}
|
|
g.stateRead()
|
|
}
|
|
|
|
// unreadableExpired is the bound key of a failing state expiring: the finding raised while the state still fails.
|
|
func (g *Gate) unreadableExpired() {
|
|
g.mu.Lock()
|
|
since := g.failingSince
|
|
g.mu.Unlock()
|
|
if since.IsZero() {
|
|
return
|
|
}
|
|
g.finding(StateName, KindApprovalsUnreadable, true, fmt.Sprintf("the state %s on %s cannot be read or written since %s: no marked call "+
|
|
"runs here until it can", StateName, g.d.Node, since.UTC().Format(time.RFC3339)), "approvals unreadable on "+g.d.Node)
|
|
}
|