Fold three tests into existing ones, drive the marker test by channels, keep the last view through set(nil) and drop it once the node is held
Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
This commit is contained in:
@@ -703,8 +703,12 @@ type agentNow struct {
|
||||
// read no haves yet, what runs is this and never the retired kept declaration (a bus link that drops restarts the
|
||||
// agent, and every fill in that window was refused; issue 924).
|
||||
last *runsView
|
||||
// view reads an agent's view; viewOf unless a test stands in for an agent that holds the node.
|
||||
view func(*agent.Agent) *runsView
|
||||
}
|
||||
|
||||
func viewOf(a *agent.Agent) *runsView { return &runsView{a.Everything(), a.HoldsNode()} }
|
||||
|
||||
// runsView is what an agent said runs, to be read after the agent stopped.
|
||||
type runsView struct {
|
||||
everything []compositions.Composed
|
||||
@@ -714,7 +718,11 @@ type runsView struct {
|
||||
func (c *agentNow) set(a *agent.Agent) {
|
||||
c.mu.Lock()
|
||||
if a == nil && c.ag != nil {
|
||||
if v := (&runsView{c.ag.Everything(), c.ag.HoldsNode()}); len(v.everything) > 0 || v.holdsNode {
|
||||
read := c.view
|
||||
if read == nil {
|
||||
read = viewOf
|
||||
}
|
||||
if v := read(c.ag); len(v.everything) > 0 || v.holdsNode {
|
||||
c.last = v
|
||||
}
|
||||
}
|
||||
@@ -722,6 +730,22 @@ func (c *agentNow) set(a *agent.Agent) {
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *agentNow) viewFn() func(*agent.Agent) *runsView {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.view == nil {
|
||||
return viewOf
|
||||
}
|
||||
return c.view
|
||||
}
|
||||
|
||||
// holdsNode drops the kept view once the agent in hand holds the node: its own view is complete from then on.
|
||||
func (c *agentNow) holdsNode() {
|
||||
c.mu.Lock()
|
||||
c.last = nil
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
// lastView is the view the last agent held when it stopped, nil when none held any.
|
||||
func (c *agentNow) lastView() *runsView {
|
||||
c.mu.Lock()
|
||||
@@ -914,7 +938,10 @@ func runsFromAgent(current *agentNow) func(string, ed25519.PublicKey) (*declarat
|
||||
kept := func() (*declaration.Declaration, error) { return keptDeclaration(statePath, signer) }
|
||||
var view *runsView
|
||||
if ag := current.get(); ag != nil {
|
||||
view = &runsView{ag.Everything(), ag.HoldsNode()}
|
||||
view = current.viewFn()(ag)
|
||||
if view.holdsNode {
|
||||
current.holdsNode()
|
||||
}
|
||||
}
|
||||
// An agent that has read no haves yet, or none: the last view held, never the retired kept declaration.
|
||||
if view == nil || (len(view.everything) == 0 && !view.holdsNode) {
|
||||
|
||||
Reference in New Issue
Block a user