T1a verb-timeout-ask: a bundle's ask waits the timeout its verb's definition names
The runner reads the `timeout` (whole seconds) of a seat's verb from the seat list's definitions beside `chunked` and hands it to the bus connection's ask (AskWithin, AskAsWithin, AskAsChunkedWithin); a verb that names none, a seat the definitions do not hold and a module's tool wait the runner's own bound, RequestTimeout. Builds: design 47 H §760, H-A-43 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -32,9 +32,18 @@ import (
|
||||
"github.com/novox/mesh-tools/node-tools/internal/wire"
|
||||
)
|
||||
|
||||
// RequestTimeout is how long a call waits for its answer — what modules already expect.
|
||||
// RequestTimeout is how long a call waits for its answer when its verb's definition names no `timeout`: the tool runner's own
|
||||
// bound, what modules already expect (design 47 H §760, H-A-43).
|
||||
const RequestTimeout = 30 * time.Second
|
||||
|
||||
// waitOf is the bound a call waits: within where the verb's definition names one, else the tool runner's own.
|
||||
func waitOf(within time.Duration) time.Duration {
|
||||
if within > 0 {
|
||||
return within
|
||||
}
|
||||
return RequestTimeout
|
||||
}
|
||||
|
||||
// Credential is a broker credential as the mesh delivers it (novox/hq ADR 0120).
|
||||
type Credential struct {
|
||||
URL string `json:"url"`
|
||||
@@ -793,6 +802,12 @@ func (c *Conn) reachedAt(key string) (string, error) {
|
||||
// Ask calls a tool by key — or on a subject the mesh listed for it — and learns which machine
|
||||
// answered. Core request/reply: a tool call is never persisted (design 25 §3).
|
||||
func (c *Conn) Ask(key string, body any, on string) (Answered, error) {
|
||||
return c.AskWithin(key, body, on, 0)
|
||||
}
|
||||
|
||||
// AskWithin is Ask that waits within for its answer, the `timeout` its verb's definition names (design 47 H §760, H-A-43);
|
||||
// zero waits the tool runner's own bound, RequestTimeout.
|
||||
func (c *Conn) AskWithin(key string, body any, on string, within time.Duration) (Answered, error) {
|
||||
subject := on
|
||||
if subject == "" {
|
||||
s, err := c.reachedAt(key)
|
||||
@@ -809,12 +824,12 @@ func (c *Conn) Ask(key string, body any, on string) (Answered, error) {
|
||||
// account publish with its own name alone; asked again on the subject that names no caller only when the
|
||||
// first reached nobody — nothing serves it yet, or the bus does not grant it yet — so no call is done twice.
|
||||
if called := CalledSubject(subject, c.cred.User); called != "" {
|
||||
answered, fallBack, err := c.askCalled(called, data)
|
||||
answered, fallBack, err := c.askCalled(called, data, within)
|
||||
if !fallBack {
|
||||
return answered, err
|
||||
}
|
||||
}
|
||||
return c.askOnce(subject, data)
|
||||
return c.askOnce(subject, data, within)
|
||||
}
|
||||
|
||||
// ErrNoResponders is the bus's own refusal: nothing subscribes to the subject asked. It is told apart
|
||||
@@ -822,8 +837,8 @@ func (c *Conn) Ask(key string, body any, on string) (Answered, error) {
|
||||
var ErrNoResponders = errors.New("503 no responders")
|
||||
|
||||
// askOnce asks once.
|
||||
func (c *Conn) askOnce(subject string, data []byte) (Answered, error) {
|
||||
msg, err := c.nc.Request(subject, data, RequestTimeout)
|
||||
func (c *Conn) askOnce(subject string, data []byte, within time.Duration) (Answered, error) {
|
||||
msg, err := c.nc.Request(subject, data, waitOf(within))
|
||||
if err != nil {
|
||||
if errors.Is(err, nats.ErrNoResponders) {
|
||||
return Answered{}, ErrNoResponders
|
||||
@@ -1036,6 +1051,11 @@ func SeatToolSubject(seat, verb, scope, node string) string {
|
||||
// `<module>.<tool>` another's, `seat:<seat>.<verb>[@<node>]` a role's — resolved through what the
|
||||
// mesh issued that module to reach, as its own runtime resolved it, else the derived shape.
|
||||
func (c *Conn) AskAs(module, key string, body any) (Answered, error) {
|
||||
return c.AskAsWithin(module, key, body, 0)
|
||||
}
|
||||
|
||||
// AskAsWithin is AskAs that waits within for its answer (design 47 H §760); zero waits RequestTimeout.
|
||||
func (c *Conn) AskAsWithin(module, key string, body any, within time.Duration) (Answered, error) {
|
||||
name, wanted, _ := strings.Cut(key, "@")
|
||||
subject := ""
|
||||
if m := c.Membership(module); m != nil {
|
||||
@@ -1058,7 +1078,7 @@ func (c *Conn) AskAs(module, key string, body any) (Answered, error) {
|
||||
}
|
||||
subject = s
|
||||
}
|
||||
return c.Ask(key, body, subject)
|
||||
return c.AskWithin(key, body, subject, within)
|
||||
}
|
||||
|
||||
// EventsStream is where every module's events land, and ConsumerOf the durable consumer the
|
||||
|
||||
Reference in New Issue
Block a user