KartaWeb.Messaging.ConnectSocket (Karta v1.0.0)

An agent's WebSocket (postduif.v1, GET /messaging/v1/connect): one process per connection, speaking the protocol of docs/suite/plans/postduif-protocol.md from Karta's side.

The connection is the agent's only way in and Karta never connects out: it sends challenge, the agent answers hello with its proof, Karta answers welcome (the contracts both support, the position it has committed, all the settings) and then the commands that are not yet done, in seq order. After that events flow up (each events frame is applied in one transaction, then acknowledged: Karta.Messaging.Inbound), commands flow down from the connector's outbox (Karta.Messaging.Commands), and ping/pong keep it alive.

Several replicas. This process is the connector's session in the database (Karta.Messaging.Sessions). A command written by any replica reaches it through the cluster's PubSub when the replicas are joined and through the database notification otherwise (Karta.Relay), and the process reads the outbox itself every 5 seconds: the announcements only make it quicker.

Back-pressure. A frame is applied before the next is read, so a slow database slows the agent through TCP; at most 100 commands are unanswered at a time; an events frame has at most 100 items.

Close codes are the protocol's: 4001 bad proof or nonce, 4002 unknown or revoked, 4003 version, 4004 replaced, 4005 agent too old, 4006 too many attempts.