H1 integration bound: the repairs' refresh keeps the tools it still serves
When a module's ledger binding came or went, refreshRepairs stopped every subscription of its tools and served them all again, so a call in that gap was dropped the same way as on a membership (H-A-158). serve is now the one routine that changes a module's subscriptions, by tool address: it keeps those still named, subscribes the new, then stops those no longer named; refreshRepairs and the first serve both go through it, so no tool is served twice or not at all. The ledger test's later binding now comes and goes ten times, and the module's own tool must answer the first call after each, within the tests' 2 s bound; it failed without the change at GOMAXPROCS=1 and 24. Builds: design 47 H §774, H-A-158, H-A-160; principle 11
This commit is contained in:
@@ -185,10 +185,6 @@ func (r *runner) refreshRepairs() {
|
||||
if served == (repairs != nil) {
|
||||
continue
|
||||
}
|
||||
for i := len(l.serving) - 1; i >= 0; i-- {
|
||||
l.serving[i]()
|
||||
}
|
||||
l.serving, l.names = nil, nil
|
||||
l.own, l.regs = withRepairs(l.own, repairs), withRepairs(l.regs, repairs)
|
||||
r.serve(l)
|
||||
changed = true
|
||||
@@ -207,14 +203,14 @@ type loadedModule struct {
|
||||
regs []registration // every registration its bundles made
|
||||
own []registration // those under the name of a module served here
|
||||
failed string
|
||||
names []string // the tools it serves, as module.tool
|
||||
serving []func() // its tools' subscriptions
|
||||
names []string // the tools it serves, as module.tool
|
||||
serving map[string]func() // its tools' subscriptions, by module.tool; serve alone changes it
|
||||
}
|
||||
|
||||
// unload stops serving the module's tools and stops its bundles.
|
||||
func (l *loadedModule) unload() {
|
||||
for i := len(l.serving) - 1; i >= 0; i-- {
|
||||
l.serving[i]()
|
||||
for _, stop := range l.serving {
|
||||
stop()
|
||||
}
|
||||
l.serving, l.names = nil, nil
|
||||
for i := len(l.children) - 1; i >= 0; i-- {
|
||||
@@ -493,25 +489,47 @@ func refusal(own []registration) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// serve binds a loaded module's tools. r.mu is held.
|
||||
// serve binds a loaded module's tools as its registrations name them now, and is the one routine that changes its
|
||||
// subscriptions (design 47 H, H-A-158, H-A-160): a tool still named keeps its subscription, a newly named one is
|
||||
// subscribed, and only then is one no longer named stopped — no tool is served twice, and none is dropped while the
|
||||
// module's tools are served again. r.mu is held.
|
||||
func (r *runner) serve(l *loadedModule) {
|
||||
if l.serving == nil {
|
||||
l.serving = map[string]func(){}
|
||||
}
|
||||
named := map[string]bool{}
|
||||
l.names = nil
|
||||
for _, reg := range l.own {
|
||||
for _, t := range reg.tools {
|
||||
t := t
|
||||
// Told who called, from the subject the call arrived on, never from its body (novox/hq issue 365).
|
||||
// Through the approval gate, before the bundle or the runner's own tool (design 46 7-approval-mark §20).
|
||||
module, own := reg.module, reg.repairs
|
||||
stop, err := r.conn.HandleCalled(reg.module+"."+t.Name, func(caller string, body json.RawMessage) (any, error) {
|
||||
return r.events.gated(approval.Call{Address: module + "." + t.Name, Module: module, Name: t.Name, Own: own,
|
||||
Fingerprint: r.fingerprintOf(module), Env: r.envOf(module), Caller: caller, Args: argsOf(body),
|
||||
Description: t.Description}, t, caller)
|
||||
})
|
||||
if err != nil {
|
||||
r.logf("[mesh-tools] cannot serve %s.%s: %v", reg.module, t.Name, err)
|
||||
address := reg.module + "." + t.Name
|
||||
if named[address] {
|
||||
continue
|
||||
}
|
||||
l.names = append(l.names, reg.module+"."+t.Name)
|
||||
l.serving = append(l.serving, stop)
|
||||
named[address] = true
|
||||
if _, kept := l.serving[address]; !kept {
|
||||
// Told who called, from the subject the call arrived on, never from its body (novox/hq issue 365).
|
||||
// Through the approval gate, before the bundle or the runner's own tool (design 46 7-approval-mark §20).
|
||||
module, own := reg.module, reg.repairs
|
||||
stop, err := r.conn.HandleCalled(address, func(caller string, body json.RawMessage) (any, error) {
|
||||
return r.events.gated(approval.Call{Address: module + "." + t.Name, Module: module, Name: t.Name, Own: own,
|
||||
Fingerprint: r.fingerprintOf(module), Env: r.envOf(module), Caller: caller, Args: argsOf(body),
|
||||
Description: t.Description}, t, caller)
|
||||
})
|
||||
if err != nil {
|
||||
r.logf("[mesh-tools] cannot serve %s.%s: %v", reg.module, t.Name, err)
|
||||
delete(named, address)
|
||||
continue
|
||||
}
|
||||
l.serving[address] = stop
|
||||
}
|
||||
l.names = append(l.names, address)
|
||||
}
|
||||
}
|
||||
for address, stop := range l.serving {
|
||||
if !named[address] {
|
||||
stop()
|
||||
delete(l.serving, address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user