Merge pull request '[agent/codex:gpt-5.4-mini] Update the code against the AX design principles in ~/spec/r...' (#21) from agent/update-the-code-against-the-ax-design-pr into dev
Some checks failed
Security Scan / security (push) Successful in 9s
Test / test (push) Failing after 50s

This commit is contained in:
Virgil 2026-03-31 05:44:44 +00:00
commit 7ed9af70c2

View file

@ -416,6 +416,8 @@ func (t *Transport) OnMessage(handler MessageHandler) {
} }
// Connect dials a peer, completes the handshake, and starts the session loops. // Connect dials a peer, completes the handshake, and starts the session loops.
//
// pc, err := transport.Connect(&Peer{ID: "worker-1", Address: "127.0.0.1:9091"})
func (t *Transport) Connect(peer *Peer) (*PeerConnection, error) { func (t *Transport) Connect(peer *Peer) (*PeerConnection, error) {
// Build WebSocket URL // Build WebSocket URL
scheme := "ws" scheme := "ws"
@ -679,7 +681,6 @@ func (t *Transport) handleWebSocketUpgrade(w http.ResponseWriter, r *http.Reques
rateLimiter: NewPeerRateLimiter(100, 50), // 100 burst, 50/sec refill rateLimiter: NewPeerRateLimiter(100, 50), // 100 burst, 50/sec refill
} }
// Send handshake acknowledgment
identity := t.nodeManager.GetIdentity() identity := t.nodeManager.GetIdentity()
if identity == nil { if identity == nil {
conn.Close() conn.Close()
@ -711,16 +712,18 @@ func (t *Transport) handleWebSocketUpgrade(w http.ResponseWriter, r *http.Reques
return return
} }
if err := conn.WriteMessage(websocket.TextMessage, ackData); err != nil { // Make the accepted connection visible before the client reads the ack.
conn.Close() // Connect() returns only after that read completes, so this keeps the
return // server registry aligned with the caller's view of the handshake.
}
// Store connection
t.mutex.Lock() t.mutex.Lock()
t.connections[peer.ID] = pc t.connections[peer.ID] = pc
t.mutex.Unlock() t.mutex.Unlock()
if err := conn.WriteMessage(websocket.TextMessage, ackData); err != nil {
t.removeConnection(pc)
return
}
// Update registry // Update registry
t.peerRegistry.SetConnected(peer.ID, true) t.peerRegistry.SetConnected(peer.ID, true)