CUB-201: add initial sync via agents.list + sessions.list RPCs
Some checks failed
Dev Build / build-test (pull_request) Failing after 1s
Some checks failed
Dev Build / build-test (pull_request) Failing after 1s
- Create gateway/sync.go with initialSync method on WSClient - Fetch agents via agents.list RPC, persist to AgentRepo - Fetch sessions via sessions.list RPC, map status to AgentStatus - Merge session state (status, sessionKey, tokens) into AgentCardData - Broadcast merged fleet as fleet.update via SSE broker - Trigger initialSync after hello-ok handshake - Re-sync automatically on reconnect (connectAndRun calls initialSync) - Handle unknown gateway fields gracefully via typed extraction
This commit is contained in:
@@ -53,6 +53,7 @@ type WSClient struct {
|
||||
logger *slog.Logger
|
||||
|
||||
handlers map[string][]eventHandler
|
||||
connId string // set after successful hello-ok
|
||||
}
|
||||
|
||||
// NewWSClient returns a WSClient wired to the given repository and broker.
|
||||
@@ -202,6 +203,16 @@ func (c *WSClient) connectAndRun(ctx context.Context) error {
|
||||
"methods", helloOK.Features.Methods,
|
||||
"events", helloOK.Features.Events)
|
||||
|
||||
// Store connId for reference
|
||||
c.connMu.Lock()
|
||||
c.connId = helloOK.ConnID
|
||||
c.connMu.Unlock()
|
||||
|
||||
// Step 2b: Initial sync — fetch agents + sessions from gateway
|
||||
if err := c.initialSync(ctx); err != nil {
|
||||
c.logger.Warn("initial sync failed, will continue with read loop", "error", err)
|
||||
}
|
||||
|
||||
// Step 3: Read loop
|
||||
return c.readLoop(ctx, conn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user