A fill while the agent restarts is judged by the last view held and, refused, is owed and told again (issue 924)
Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
This commit is contained in:
@@ -699,14 +699,36 @@ var reloadSettles = 10 * time.Second
|
||||
type agentNow struct {
|
||||
mu sync.Mutex
|
||||
ag *agent.Agent
|
||||
// last is the view of what runs the previous agent held when it stopped, kept in memory: while the next agent has
|
||||
// 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
|
||||
}
|
||||
|
||||
// runsView is what an agent said runs, to be read after the agent stopped.
|
||||
type runsView struct {
|
||||
everything []compositions.Composed
|
||||
holdsNode bool
|
||||
}
|
||||
|
||||
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 {
|
||||
c.last = v
|
||||
}
|
||||
}
|
||||
c.ag = a
|
||||
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()
|
||||
defer c.mu.Unlock()
|
||||
return c.last
|
||||
}
|
||||
|
||||
func (c *agentNow) get() *agent.Agent {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
@@ -890,11 +912,20 @@ func declaredNow(statePath string, signer ed25519.PublicKey) (*declaration.Decla
|
||||
func runsFromAgent(current *agentNow) func(string, ed25519.PublicKey) (*declaration.Declaration, error) {
|
||||
return func(statePath string, signer ed25519.PublicKey) (*declaration.Declaration, error) {
|
||||
kept := func() (*declaration.Declaration, error) { return keptDeclaration(statePath, signer) }
|
||||
ag := current.get()
|
||||
if ag == nil {
|
||||
var view *runsView
|
||||
if ag := current.get(); ag != nil {
|
||||
view = &runsView{ag.Everything(), ag.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) {
|
||||
if last := current.lastView(); last != nil {
|
||||
view = last
|
||||
}
|
||||
}
|
||||
if view == nil {
|
||||
return kept()
|
||||
}
|
||||
return whatRuns(ag.Everything(), ag.HoldsNode(), kept)
|
||||
return whatRuns(view.everything, view.holdsNode, kept)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -19,6 +20,7 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/declaration"
|
||||
|
||||
"github.com/novox/mesh-host/internal/agent"
|
||||
"github.com/novox/mesh-host/internal/filling"
|
||||
"github.com/novox/mesh-host/internal/liveness"
|
||||
"github.com/novox/mesh-host/internal/store"
|
||||
)
|
||||
@@ -237,3 +239,46 @@ func TestASharedTargetWithAnotherIDIsNotDropped(t *testing.T) {
|
||||
t.Errorf("a resource sharing only its target was dropped: %v", dropped)
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 924: the bus link drops, the agent restarts, and the filling is asked while it holds nothing yet. What runs is
|
||||
// then the last view the node held, never the retired kept declaration; and a fill refused for want of any is owed and
|
||||
// told once the agent holds the node again, so every file is written afterwards.
|
||||
func TestAFillWhileTheAgentRestartsIsWrittenAfterwards(t *testing.T) {
|
||||
keptRetired.Store(true)
|
||||
defer keptRetired.Store(false)
|
||||
node := engcomp.Composed{Node: "n1", Own: engcomp.NodeOwn{Provisioner: "mesh-node-provisioner"}}
|
||||
files := []engcomp.Composed{{Node: "n1", Module: "db", Resources: []json.RawMessage{aFileOf("db", "a")}, Filled: []string{"/tmp/r6/db/a"}}}
|
||||
view := &runsView{everything: append(files, node), holdsNode: true}
|
||||
|
||||
var placed []string
|
||||
current := &agentNow{}
|
||||
e := &filling.Engine{
|
||||
Declared: func() (*declaration.Declaration, error) { return runsFromAgent(current)("/nowhere", nil) },
|
||||
UIDOf: func(string) (uint32, error) { return 4242, nil },
|
||||
Lock: func() (func(), error) { return func() {}, nil },
|
||||
Place: func(_ context.Context, _ *declaration.Declaration, path string, _ []byte) (string, string, error) {
|
||||
placed = append(placed, path)
|
||||
return "updated", "d", nil
|
||||
},
|
||||
}
|
||||
fill := func() filling.Answer {
|
||||
return e.Write(context.Background(), 4242, filling.Request{Path: "/tmp/r6/db/a", Content: []byte("x")})
|
||||
}
|
||||
socket := filepath.Join(t.TempDir(), "sock")
|
||||
if err := os.WriteFile(socket, nil, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// The node never held a view (a cold start): refused, and owed.
|
||||
if a := fill(); a.Failed == "" && a.Refused == "" {
|
||||
t.Fatalf("a fill with nothing read was accepted: %+v", a)
|
||||
}
|
||||
// The agent stopped holding the node: the last view it held answers, and the fill is written.
|
||||
current.last = view
|
||||
if told, err := e.Knock(socket); err != nil || told == "" {
|
||||
t.Fatalf("the refused fill was not owed and told: %q, %v", told, err)
|
||||
}
|
||||
if a := fill(); a.Failed != "" || a.Refused != "" || len(placed) != 1 {
|
||||
t.Fatalf("the fill during the restart was not written: %+v, placed %v", a, placed)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user