Skip to content

Commit 5918b87

Browse files
andystimeclaude
andcommitted
fix: ensure connections field is always array instead of null
Fixed critical bug where connection info was not being sent to the server properly, causing connections to never display on the website. Root Cause: - When no connection files existed for a worker, connections was nil - nil slice marshals to null in JSON - Server checks: if (connectionChanged && workerStatus.connections) - null is falsy in JavaScript, so server skipped processing - Result: connections never synced to database The Fix: 1. Always initialize connections as empty slice: make([]api.ConnectionInfo, 0) 2. Empty slice marshals to [] in JSON instead of null 3. [] is truthy in JavaScript, so server processes the connections 4. Server correctly handles empty arrays: - Deletes old connections if worker reports [] - Adds new connections if worker reports [...] - No-op if DB has [] and worker reports [] Changes Made: - collectWorkerStatusFromHypervisor: Initialize connections as empty slice - collectWorkerStatusFromConfig: Initialize connections as empty slice - Both paths now send connections: [] instead of connections: null This ensures: - Connections are always synced to database when connectionChanged=true - Empty connection arrays properly clear old connections from DB - New connections are properly added to DB - Connection display works correctly on frontend Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 79a42de commit 5918b87

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

internal/agent/agent.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,8 @@ func (a *Agent) collectWorkerStatusFromHypervisor(
11711171
gpuChanged := forceRefresh || a.anyGPUChanged(w.AllocatedDevices, gpuChanges)
11721172

11731173
// Get connections for this worker
1174-
var connections []api.ConnectionInfo
1174+
// Initialize as empty slice (not nil) so it marshals to [] instead of null in JSON
1175+
connections := make([]api.ConnectionInfo, 0)
11751176
if connLines, ok := currentConnections[w.WorkerUID]; ok {
11761177
connections = parseConnectionsToAPI(connLines)
11771178
if len(connections) > 0 {
@@ -1226,7 +1227,12 @@ func (a *Agent) collectWorkerStatusFromConfig(
12261227
workerChanged := true
12271228
connectionChanged := true
12281229
gpuChanged := forceRefresh || len(gpuChanges) > 0
1229-
connections := w.Connections
1230+
1231+
// Initialize as empty slice (not nil) so it marshals to [] instead of null in JSON
1232+
connections := make([]api.ConnectionInfo, 0)
1233+
if w.Connections != nil {
1234+
connections = w.Connections
1235+
}
12301236
if connLines, ok := currentConnections[w.WorkerID]; ok {
12311237
connections = parseConnectionsToAPI(connLines)
12321238
if len(connections) > 0 {

0 commit comments

Comments
 (0)