Fix build breakers and remaining runtime bugs across stack.

Remove corrupt empty main.go files, harden WebSocket reconnect and pre-auth handling, complete live stats in the dashboard hook, wire AI share counts, and refresh PROBLEMS.md.
This commit is contained in:
drjones
2026-05-28 16:23:24 -07:00
parent edffb03e00
commit fabc632384
8 changed files with 146 additions and 163 deletions

View File

@@ -187,18 +187,24 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
defer func() {
if agentID != "" {
h.mu.Lock()
delete(h.agents, agentID)
delete(h.agentConfigs, agentID)
delete(h.agentLogs, agentID)
h.mu.Unlock()
if h.aiHandler != nil {
h.aiHandler.RemoveEngine(agentID)
cur := h.agents[agentID]
// Only tear down fleet state if this connection is still the active one.
if cur != nil && cur.Conn == conn {
delete(h.agents, agentID)
delete(h.agentConfigs, agentID)
delete(h.agentLogs, agentID)
h.mu.Unlock()
if h.aiHandler != nil {
h.aiHandler.RemoveEngine(agentID)
}
h.db.SetAgentOffline(agentID)
h.broadcastDashboard(Message{
Type: "agent_offline",
Payload: mustMarshal(map[string]string{"agent_id": agentID}),
})
} else {
h.mu.Unlock()
}
h.db.SetAgentOffline(agentID)
h.broadcastDashboard(Message{
Type: "agent_offline",
Payload: mustMarshal(map[string]string{"agent_id": agentID}),
})
}
conn.Close()
}()
@@ -328,6 +334,12 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
}
h.mu.Lock()
if old, ok := h.agents[agentID]; ok && old.Conn != conn {
oldConn := old.Conn
h.mu.Unlock()
oldConn.Close()
h.mu.Lock()
}
h.agents[agentID] = &AgentConnection{AgentID: agentID, Conn: conn}
h.mu.Unlock()
@@ -342,6 +354,9 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
})
case "stats":
if agentID == "" {
continue
}
var stats struct {
Hashrate15s float64 `json:"hashrate_15s"`
Hashrate1m float64 `json:"hashrate_1m"`
@@ -383,6 +398,9 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
})
case "submit_share":
if agentID == "" {
continue
}
var share models.Share
if err := json.Unmarshal(msg.Payload, &share); err != nil {
continue
@@ -460,9 +478,12 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
wallet = h.defaultPool.Wallet
}
proxy.SubmitShare(agentID, wallet, share.JobID, share.Nonce, share.Hash, sendShareResult)
go proxy.SubmitShare(agentID, wallet, share.JobID, share.Nonce, share.Hash, sendShareResult)
case "get_job":
if agentID == "" {
continue
}
var proxy *pool.Proxy
if h.poolManager != nil {
poolCfg := h.agentPoolConfig(agentID)
@@ -485,6 +506,9 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
}
case "log_tail":
if agentID == "" {
continue
}
var payload struct {
Content string `json:"content"`
Lines int `json:"lines"`
@@ -501,6 +525,9 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
})
case "command_result":
if agentID == "" {
continue
}
var payload map[string]interface{}
if err := json.Unmarshal(msg.Payload, &payload); err != nil {
continue