Design 47 H2: the tool runner drains at stop, pages by cursor and reads a seat's waiting asks #88

Merged
mesh-tools merged 16 commits from feat/47-H2 into main 2026-11-22 04:56:15 +00:00
3 changed files with 24 additions and 12 deletions
Showing only changes of commit 858beb2b63 - Show all commits
@@ -180,7 +180,7 @@ func TestTheToolRunnerStartedByItsEntryServesABundleOverTheSeatListItReads(t *te
mu.Unlock()
// at its stop the runner drains (design 47 H2 §813 (12), H-A-353; the bound 2 s here for the setting's 30 s): a call of 1 s in
// flight is answered, one of 6 s is cut at the bound, said, and its caller answered nothing; a call after the stop is refused
// flight is answered, one of 6 s is cut at the bound, said, and its caller answered nothing; a call after the stop is answered nothing
type answer struct {
got string
err error
@@ -202,10 +202,12 @@ func TestTheToolRunnerStartedByItsEntryServesABundleOverTheSeatListItReads(t *te
return nil
})
stop()
// a call after the stop began is answered nothing, never refused, so the caller's kept call paces and meets the new runner
// (H-A-369): until the drain began it is still answered
mt.Until(t, func() error {
_, err := ask("ledger.who")
if err == nil || !strings.Contains(err.Error(), "takes no new call") {
return fmt.Errorf("a call after the stop was answered %v, want it refused", err)
answered, err := asker.AskWithin("ledger.who", map[string]any{}, "", 500*time.Millisecond)
if err == nil || err.Error() != "timeout" {
return fmt.Errorf("a call after the stop was answered %s, %v; want no answer", answered.Result, err)
}
return nil
})
+12 -4
View File
@@ -30,8 +30,16 @@ var asks = struct {
ended chan struct{}
}{of: map[uint64]*inFlight{}}
// errStopping is an ask made after the stop: refused, the call made after the stop is not taken (§813 (12)).
var errStopping = &Refused{Method: "", Message: "the tool runner is stopping: it takes no new call (design 47 H2 §813 (12))"}
// afterStop is an ask made after the stop began: it is not taken and its caller is answered nothing, never refused, so the
// caller's kept call paces and meets the new runner (design 47 H2 §813 (12) as H-A-369 amends it).
type afterStop struct{ module, verb string }
func (e *afterStop) Error() string {
return fmt.Sprintf("%s's %s was not taken: the tool runner is stopping, and a call after its stop is answered nothing", e.module, e.verb)
}
// Unanswered says the call is left without an answer, so its kept call asks again and meets the new runner.
func (e *afterStop) Unanswered() bool { return true }
// cutCall is a call the drain cut at its bound. Its caller is answered nothing, so it sees a transport fault (§813 (12)): the
// bus reads Unanswered and sends no reply.
@@ -44,12 +52,12 @@ func (e *cutCall) Error() string {
// Unanswered says the call is left without an answer, so its caller sees a transport fault.
func (e *cutCall) Unanswered() bool { return true }
// begin records an ask about to be made, or refuses it once the runner drains.
// begin records an ask about to be made; once the runner drains it takes none, and its caller is answered nothing.
func begin(module, verb string) (uint64, *inFlight, error) {
asks.mu.Lock()
defer asks.mu.Unlock()
if asks.draining {
return 0, nil, errStopping
return 0, nil, &afterStop{module: module, verb: verb}
}
asks.next++
f := &inFlight{module: module, verb: verb, at: time.Now(), cut: make(chan struct{})}
+6 -4
View File
@@ -27,7 +27,8 @@ while IFS= read -r line; do
done
`
// **The tool runner drains at a stop** (design 47 H2 §813 (12), H-A-342 (2), H-A-353): once it drains, no new call is taken; a call
// **The tool runner drains at a stop** (design 47 H2 §813 (12), H-A-342 (2), H-A-353, H-A-369): once it drains, no new call is
// taken and its caller is answered nothing (Unanswered), never refused; a call
// in flight that ends within the drain bound is answered; one still in flight at the bound is cut, said with its bundle, its verb
// and its age, and left unanswered (Unanswered, so the bus sends its caller nothing: a transport fault).
func TestTheToolRunnerDrainsItsCallsInFlightAtAStop(t *testing.T) {
@@ -36,7 +37,7 @@ func TestTheToolRunnerDrainsItsCallsInFlightAtAStop(t *testing.T) {
bound time.Duration
release bool
}{
{"a call that ends within the bound is answered, and a call after the stop is refused", 10 * time.Second, true},
{"a call that ends within the bound is answered, and a call after the stop is answered nothing", 10 * time.Second, true},
{"a call that outlives the bound is cut and said", 50 * time.Millisecond, false},
} {
t.Run(row.name, func(t *testing.T) {
@@ -93,8 +94,9 @@ func TestTheToolRunnerDrainsItsCallsInFlightAtAStop(t *testing.T) {
}
}
if row.release {
if _, err := run("", json.RawMessage(`{}`)); err == nil || !strings.Contains(err.Error(), "takes no new call") {
t.Errorf("a call made after the stop was answered %v, want it refused", err)
var unanswered interface{ Unanswered() bool }
if _, err := run("", json.RawMessage(`{}`)); !errors.As(err, &unanswered) || !unanswered.Unanswered() {
t.Errorf("a call made after the stop ended %v, want it answered nothing, never refused", err)
}
f, err := os.OpenFile(hold, os.O_WRONLY, 0)
if err != nil {