Skip to content

Implement BrainRegistry — one connection manager per robot ESN #15

@infraax

Description

@infraax

Task: BrainRegistry

Parent epic: #4 (M1 — Robot Connection)
Depends on: #14 (vector-go-sdk in go.mod)

What to do

Create internal/brain/registry.go — a registry that holds one ConnectionManager per robot ESN. The Go HTTP handlers get/create robot connections through this registry.

// Package brain manages persistent SDK connections to Vector robots.
// One ConnectionManager per ESN, created on first event and held for the process lifetime.
package brain

type Registry struct { ... }

func NewRegistry(cfg *config.Config) *Registry
func (r *Registry) Get(esn string) (*ConnectionManager, bool)
func (r *Registry) GetOrCreate(esn string) *ConnectionManager
func (r *Registry) All() []*ConnectionManager
func (r *Registry) Shutdown(ctx context.Context) error

Integration

  • Registry is created in main.go and passed to buildRouter
  • /health reads registry.All() to report connection status
  • /api/v1/robots reads registry.All() for the robot list
  • /api/v1/robots/{esn}/state reads registry.Get(esn) for state

Notes

  • One registry, held for process lifetime. Thread-safe (multiple HTTP handlers read it concurrently).
  • The registry does not create connections proactively — ConnectionManager does that lazily on first use or immediately if configured.

Definition of done

Registry compiles. /health returns "connected" or "disconnected" per ESN (not "configured").

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions