feat(state): carry channel lifecycle from the Messaging Service to the dashboard

archie-core-8cda.6.8's carrier. The service now records channel lifecycle and has
nowhere to put it: /api/channels answered with nothing because
webui.Server.Channels had no production source, and reload answered 501 for the
same reason. This adds the surface the register decided on, following the split
archie-core-ymut established for config snapshots -- a pair of administrative RPCs
whose writer is one process and whose reader is the UI -- and wires both ends.

Wire and store: PutChannelStatus / ListChannelStatus, with ChannelStatus carrying
id, name, state, detail, configured, reload_supported and observed_at. The store
holds one row per channel and replaces the reported set, so a channel the reporter
no longer mentions is deleted rather than left standing as a stale "running"; an
empty report clears the table, because hosting no channels is a fact worth
reporting. A row without an id is refused: it could never be replaced or removed
by a later report.

Writer: the service publishes on every lifecycle transition through a coalescing
signal -- a burst of transitions is one write, since a reader only wants the latest
state of every channel -- plus a start-up report and a final report after shutdown,
so a stopped service leaves the store honest. A failed write is logged and retried
on the next signal; the dashboard losing channel state is worth a warning and never
worth failing a channel start over.

Reader: webui.Server.Channels becomes a source rather than a concrete manager, and
webui.RemoteChannelStatus reads the store the way RemoteConfigView reads the config
snapshot. A store it cannot reach reports nothing rather than a stale "running",
and a state the reader does not recognise is carried through rather than dropped.

The contract's own index gains the group in the same change that adds the RPCs --
a surface the grouped table does not list is one nobody finds -- and the count moves
to 51. The register records why the surface is the State Store rather than a
resource kind, and why reload gets its own surface rather than a field here: reading
status must not be able to retrigger an action, a transient request is not
distinguishable from state once anything polls it, and it would invert the
writer/reader relationship the precedent establishes.

Verified: task check exit 0. New coverage: the store's replace-the-set semantics
and its refusal of an id-less row, the reader's mapping including an unknown state,
and the publisher's start-up, transition and final reports.
This commit is contained in:
sam committed 2026-09-22 08:04:44 +10:00
1 parent fb265f2ad0
commit d6f526ce4f
23 files changed
+1445 -406

No files matched your search

@@ -51,6 +51,7 @@ var (
_ storecontract.BindingTaskCreator = (*Client)(nil)
_ storecontract.PlaybookDispatcher = (*Client)(nil)
_ storecontract.ConfigSnapshotStore = (*Client)(nil)
_ storecontract.ChannelStatusStore = (*Client)(nil)
_ storecontract.ApplyStatusStore = (*Client)(nil)
_ identity.Repository = (*Client)(nil)
)
@@ -291,6 +292,26 @@ func (c *Client) ConfigSnapshot(ctx context.Context) (storecontract.ConfigSnapsh
return configSnapshotValue(reply.Snapshot), true, nil
}
// PutChannelStatus publishes the channel state the hosting process observes.
// Administrative, like the config snapshot pair: the server admits it on the
// administrative token only, so a task-scoped grant cannot reach it.
func (c *Client) PutChannelStatus(ctx context.Context, channels []storecontract.ChannelStatus) error {
_, err := c.client.PutChannelStatus(ctx, &pb.PutChannelStatusRequest{Channels: channelStatusesProto(channels)})
if err != nil {
return unmapError(err)
}
return nil
}
// ChannelStatus reads every reported channel.
func (c *Client) ChannelStatus(ctx context.Context) ([]storecontract.ChannelStatus, error) {
reply, err := c.client.ListChannelStatus(ctx, &pb.ListChannelStatusRequest{})
if err != nil {
return nil, unmapError(err)
}
return channelStatusesValue(reply.Channels), nil
}
// PutApplyStatus reports what this process applied for one resource kind.
// Administrative, like the config snapshot pair: a task-scoped grant cannot
// reach it.
+41 -6
View File
@@ -31,6 +31,7 @@ import (
var (
errCaptureUnavailable = status.Error(codes.Unavailable, "capture store unavailable")
errConfigSnapshotsUnavailable = status.Error(codes.Unavailable, "config snapshot store unavailable")
errChannelStatusUnavailable = status.Error(codes.Unavailable, "channel status store unavailable")
errApplyStatusUnavailable = status.Error(codes.Unavailable, "apply status store unavailable")
errMappingUnavailable = status.Error(codes.Unavailable, "mapping store unavailable")
errBindingUnavailable = status.Error(codes.Unavailable, "binding store unavailable")
@@ -59,12 +60,16 @@ const taskLogChunkBytes = 256 << 10
// codes.Unavailable) exactly as their daemon-side consumers already treat a
// nil Mappings/Bindings/BindingDispatcher/BindingTaskCreator as "disabled".
type Deps struct {
ControlPlane controlpb.ControlPlaneServiceServer
Identities identity.Repository
Grants *TaskGrants
Tasks storecontract.TaskStore
Captures storecontract.CaptureStore
ConfigSnapshots storecontract.ConfigSnapshotStore
ControlPlane controlpb.ControlPlaneServiceServer
Identities identity.Repository
Grants *TaskGrants
Tasks storecontract.TaskStore
Captures storecontract.CaptureStore
ConfigSnapshots storecontract.ConfigSnapshotStore
// ChannelStatus is the channel runtime state the process hosting the channels
// reports. Optional: nil disables the pair with codes.Unavailable, which is
// the honest answer for a store service no messaging process is writing to.
ChannelStatus storecontract.ChannelStatusStore
ApplyStatus storecontract.ApplyStatusStore
Mappings storecontract.MappingStore
Bindings storecontract.BindingStore
@@ -389,6 +394,36 @@ func (s *server) GetConfigSnapshot(ctx context.Context, _ *pb.GetConfigSnapshotR
return &pb.GetConfigSnapshotResponse{Snapshot: configSnapshotProto(snapshot), Found: true}, nil
}
func (s *server) channelStatuses() (storecontract.ChannelStatusStore, error) {
if s.deps.ChannelStatus == nil {
return nil, errChannelStatusUnavailable
}
return s.deps.ChannelStatus, nil
}
func (s *server) PutChannelStatus(ctx context.Context, r *pb.PutChannelStatusRequest) (*pb.PutChannelStatusResponse, error) {
cs, err := s.channelStatuses()
if err != nil {
return nil, err
}
if err := cs.PutChannelStatus(ctx, channelStatusesValue(r.Channels)); err != nil {
return nil, s.logErr("PutChannelStatus", err)
}
return &pb.PutChannelStatusResponse{}, nil
}
func (s *server) ListChannelStatus(ctx context.Context, _ *pb.ListChannelStatusRequest) (*pb.ListChannelStatusResponse, error) {
cs, err := s.channelStatuses()
if err != nil {
return nil, err
}
channels, err := cs.ChannelStatus(ctx)
if err != nil {
return nil, s.logErr("ListChannelStatus", err)
}
return &pb.ListChannelStatusResponse{Channels: channelStatusesProto(channels)}, nil
}
func (s *server) InsertCapture(ctx context.Context, r *pb.InsertCaptureRequest) (*pb.InsertCaptureResponse, error) {
cs, err := s.capture()
if err != nil {
@@ -407,6 +407,45 @@ func configSnapshotValue(snapshot *pb.ConfigSnapshot) storecontract.ConfigSnapsh
}
}
// channelStatusesProto and channelStatusesValue carry the channel runtime state
// the hosting process reports. The state is a string rather than an enum on the
// wire: the vocabulary belongs to internal/channels/status, and a reader that
// does not know a state it receives must show it rather than reject the report.
func channelStatusesProto(channels []storecontract.ChannelStatus) []*pb.ChannelStatus {
out := make([]*pb.ChannelStatus, 0, len(channels))
for _, channel := range channels {
out = append(out, &pb.ChannelStatus{
Id: channel.ID,
Name: channel.Name,
State: channel.State,
Detail: channel.Detail,
Configured: channel.Configured,
ReloadSupported: channel.ReloadSupported,
ObservedAt: timestamp(channel.ObservedAt),
})
}
return out
}
func channelStatusesValue(channels []*pb.ChannelStatus) []storecontract.ChannelStatus {
out := make([]storecontract.ChannelStatus, 0, len(channels))
for _, channel := range channels {
if channel == nil {
continue
}
out = append(out, storecontract.ChannelStatus{
ID: channel.Id,
Name: channel.Name,
State: channel.State,
Detail: channel.Detail,
Configured: channel.Configured,
ReloadSupported: channel.ReloadSupported,
ObservedAt: timeValue(channel.ObservedAt),
})
}
return out
}
func applyStatusProto(status storecontract.ApplyStatus) *pb.ApplyStatus {
return &pb.ApplyStatus{
Process: status.Process,