feat(staterpc): add the task-log read contract to the State Store service

One task attempt's persisted log lives in the state directory the State Store
process owns, and no contract carried it: the dashboard process therefore had
no way to read a log at all, and answered every attempt with "task logging is
optional and was not enabled for this run" in a deployment where logging is
unconditional.

ReadTaskLog returns a decoded page and StreamTaskLogContent returns the raw
bytes server-streamed -- a log rotates at 20 MB, past gRPC's unary cap, the
same reason StreamCaptures superseded ListCaptures. found=false with no error
means the attempt has no log; a service with no reader answers Unavailable,
and keeping those apart is the point: only the second is a deployment
condition.
This commit is contained in:
sam committed 2026-09-17 12:09:43 +00:00
1 parent 884fcd0ce8
commit 781358c862
3 files changed
+888 -281

No files matched your search

File diff suppressed because it is too large. Load diff
+99 -2
View File
@@ -45,6 +45,8 @@ const (
StateStoreService_TokensByDay_FullMethodName = "/state.v1.StateStoreService/TokensByDay"
StateStoreService_PutConfigSnapshot_FullMethodName = "/state.v1.StateStoreService/PutConfigSnapshot"
StateStoreService_GetConfigSnapshot_FullMethodName = "/state.v1.StateStoreService/GetConfigSnapshot"
StateStoreService_ReadTaskLog_FullMethodName = "/state.v1.StateStoreService/ReadTaskLog"
StateStoreService_StreamTaskLogContent_FullMethodName = "/state.v1.StateStoreService/StreamTaskLogContent"
StateStoreService_InsertCapture_FullMethodName = "/state.v1.StateStoreService/InsertCapture"
StateStoreService_ListCaptures_FullMethodName = "/state.v1.StateStoreService/ListCaptures"
StateStoreService_StreamCaptures_FullMethodName = "/state.v1.StateStoreService/StreamCaptures"
@@ -114,6 +116,17 @@ type StateStoreServiceClient interface {
// configuration page").
PutConfigSnapshot(ctx context.Context, in *PutConfigSnapshotRequest, opts ...grpc.CallOption) (*PutConfigSnapshotResponse, error)
GetConfigSnapshot(ctx context.Context, in *GetConfigSnapshotRequest, opts ...grpc.CallOption) (*GetConfigSnapshotResponse, error)
// Task log: one task attempt's persisted log. Task log files live in the
// state directory this process owns, so the dashboard reads them over this
// contract rather than opening them itself
// (docs/prds/ui-service-boundary.md).
ReadTaskLog(ctx context.Context, in *ReadTaskLogRequest, opts ...grpc.CallOption) (*ReadTaskLogResponse, error)
// StreamTaskLogContent returns one attempt's log verbatim, one chunk per
// message, for a download. A log file is unbounded input (it rotates at
// DefaultMaxSizeMB), so a unary response would exceed gRPC's 4MiB message
// cap on a real log -- the same reason ListCaptures was superseded by
// StreamCaptures.
StreamTaskLogContent(ctx context.Context, in *StreamTaskLogContentRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[StreamTaskLogContentResponse], error)
// Capture
InsertCapture(ctx context.Context, in *InsertCaptureRequest, opts ...grpc.CallOption) (*InsertCaptureResponse, error)
// Deprecated: Do not use.
@@ -419,6 +432,35 @@ func (c *stateStoreServiceClient) GetConfigSnapshot(ctx context.Context, in *Get
return out, nil
}
func (c *stateStoreServiceClient) ReadTaskLog(ctx context.Context, in *ReadTaskLogRequest, opts ...grpc.CallOption) (*ReadTaskLogResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ReadTaskLogResponse)
err := c.cc.Invoke(ctx, StateStoreService_ReadTaskLog_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *stateStoreServiceClient) StreamTaskLogContent(ctx context.Context, in *StreamTaskLogContentRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[StreamTaskLogContentResponse], error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &StateStoreService_ServiceDesc.Streams[0], StateStoreService_StreamTaskLogContent_FullMethodName, cOpts...)
if err != nil {
return nil, err
}
x := &grpc.GenericClientStream[StreamTaskLogContentRequest, StreamTaskLogContentResponse]{ClientStream: stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type StateStoreService_StreamTaskLogContentClient = grpc.ServerStreamingClient[StreamTaskLogContentResponse]
func (c *stateStoreServiceClient) InsertCapture(ctx context.Context, in *InsertCaptureRequest, opts ...grpc.CallOption) (*InsertCaptureResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(InsertCaptureResponse)
@@ -442,7 +484,7 @@ func (c *stateStoreServiceClient) ListCaptures(ctx context.Context, in *ListCapt
func (c *stateStoreServiceClient) StreamCaptures(ctx context.Context, in *StreamCapturesRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[StreamCapturesResponse], error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &StateStoreService_ServiceDesc.Streams[0], StateStoreService_StreamCaptures_FullMethodName, cOpts...)
stream, err := c.cc.NewStream(ctx, &StateStoreService_ServiceDesc.Streams[1], StateStoreService_StreamCaptures_FullMethodName, cOpts...)
if err != nil {
return nil, err
}
@@ -602,7 +644,7 @@ func (c *stateStoreServiceClient) ListUndispatchedCaptures(ctx context.Context,
func (c *stateStoreServiceClient) StreamUndispatchedCaptures(ctx context.Context, in *StreamUndispatchedCapturesRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[StreamUndispatchedCapturesResponse], error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &StateStoreService_ServiceDesc.Streams[1], StateStoreService_StreamUndispatchedCaptures_FullMethodName, cOpts...)
stream, err := c.cc.NewStream(ctx, &StateStoreService_ServiceDesc.Streams[2], StateStoreService_StreamUndispatchedCaptures_FullMethodName, cOpts...)
if err != nil {
return nil, err
}
@@ -677,6 +719,17 @@ type StateStoreServiceServer interface {
// configuration page").
PutConfigSnapshot(context.Context, *PutConfigSnapshotRequest) (*PutConfigSnapshotResponse, error)
GetConfigSnapshot(context.Context, *GetConfigSnapshotRequest) (*GetConfigSnapshotResponse, error)
// Task log: one task attempt's persisted log. Task log files live in the
// state directory this process owns, so the dashboard reads them over this
// contract rather than opening them itself
// (docs/prds/ui-service-boundary.md).
ReadTaskLog(context.Context, *ReadTaskLogRequest) (*ReadTaskLogResponse, error)
// StreamTaskLogContent returns one attempt's log verbatim, one chunk per
// message, for a download. A log file is unbounded input (it rotates at
// DefaultMaxSizeMB), so a unary response would exceed gRPC's 4MiB message
// cap on a real log -- the same reason ListCaptures was superseded by
// StreamCaptures.
StreamTaskLogContent(*StreamTaskLogContentRequest, grpc.ServerStreamingServer[StreamTaskLogContentResponse]) error
// Capture
InsertCapture(context.Context, *InsertCaptureRequest) (*InsertCaptureResponse, error)
// Deprecated: Do not use.
@@ -800,6 +853,12 @@ func (UnimplementedStateStoreServiceServer) PutConfigSnapshot(context.Context, *
func (UnimplementedStateStoreServiceServer) GetConfigSnapshot(context.Context, *GetConfigSnapshotRequest) (*GetConfigSnapshotResponse, error) {
return nil, status.Error(codes.Unimplemented, "method GetConfigSnapshot not implemented")
}
func (UnimplementedStateStoreServiceServer) ReadTaskLog(context.Context, *ReadTaskLogRequest) (*ReadTaskLogResponse, error) {
return nil, status.Error(codes.Unimplemented, "method ReadTaskLog not implemented")
}
func (UnimplementedStateStoreServiceServer) StreamTaskLogContent(*StreamTaskLogContentRequest, grpc.ServerStreamingServer[StreamTaskLogContentResponse]) error {
return status.Error(codes.Unimplemented, "method StreamTaskLogContent not implemented")
}
func (UnimplementedStateStoreServiceServer) InsertCapture(context.Context, *InsertCaptureRequest) (*InsertCaptureResponse, error) {
return nil, status.Error(codes.Unimplemented, "method InsertCapture not implemented")
}
@@ -1346,6 +1405,35 @@ func _StateStoreService_GetConfigSnapshot_Handler(srv interface{}, ctx context.C
return interceptor(ctx, in, info, handler)
}
func _StateStoreService_ReadTaskLog_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ReadTaskLogRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(StateStoreServiceServer).ReadTaskLog(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: StateStoreService_ReadTaskLog_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(StateStoreServiceServer).ReadTaskLog(ctx, req.(*ReadTaskLogRequest))
}
return interceptor(ctx, in, info, handler)
}
func _StateStoreService_StreamTaskLogContent_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(StreamTaskLogContentRequest)
if err := stream.RecvMsg(m); err != nil {
return err
}
return srv.(StateStoreServiceServer).StreamTaskLogContent(m, &grpc.GenericServerStream[StreamTaskLogContentRequest, StreamTaskLogContentResponse]{ServerStream: stream})
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type StateStoreService_StreamTaskLogContentServer = grpc.ServerStreamingServer[StreamTaskLogContentResponse]
func _StateStoreService_InsertCapture_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(InsertCaptureRequest)
if err := dec(in); err != nil {
@@ -1785,6 +1873,10 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetConfigSnapshot",
Handler: _StateStoreService_GetConfigSnapshot_Handler,
},
{
MethodName: "ReadTaskLog",
Handler: _StateStoreService_ReadTaskLog_Handler,
},
{
MethodName: "InsertCapture",
Handler: _StateStoreService_InsertCapture_Handler,
@@ -1855,6 +1947,11 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "StreamTaskLogContent",
Handler: _StateStoreService_StreamTaskLogContent_Handler,
ServerStreams: true,
},
{
StreamName: "StreamCaptures",
Handler: _StateStoreService_StreamCaptures_Handler,
+70
View File
@@ -53,6 +53,18 @@ service StateStoreService {
rpc PutConfigSnapshot(PutConfigSnapshotRequest) returns (PutConfigSnapshotResponse);
rpc GetConfigSnapshot(GetConfigSnapshotRequest) returns (GetConfigSnapshotResponse);
// Task log: one task attempt's persisted log. Task log files live in the
// state directory this process owns, so the dashboard reads them over this
// contract rather than opening them itself
// (docs/prds/ui-service-boundary.md).
rpc ReadTaskLog(ReadTaskLogRequest) returns (ReadTaskLogResponse);
// StreamTaskLogContent returns one attempt's log verbatim, one chunk per
// message, for a download. A log file is unbounded input (it rotates at
// DefaultMaxSizeMB), so a unary response would exceed gRPC's 4MiB message
// cap on a real log -- the same reason ListCaptures was superseded by
// StreamCaptures.
rpc StreamTaskLogContent(StreamTaskLogContentRequest) returns (stream StreamTaskLogContentResponse);
// Capture
rpc InsertCapture(InsertCaptureRequest) returns (InsertCaptureResponse);
// ListCaptures is superseded by StreamCaptures (kept, unmodified, so an
@@ -372,6 +384,64 @@ message GetConfigSnapshotResponse {
bool found = 2;
}
// TaskLogEntry mirrors internal/logging.Entry: one decoded log line. fields
// carries every remaining key as a JSON object string, the same way Event
// carries its data, so structured context survives the hop without this
// contract having to know what a call site attached.
message TaskLogEntry {
int64 id = 1;
google.protobuf.Timestamp time = 2;
string level = 3;
string msg = 4;
string fields_json = 5;
}
// ReadTaskLog returns a page of one task attempt's decoded log. attempt is the
// attempt the caller resolved (the dashboard sends the task's current attempt
// when the request omitted one). levels, component, contains, since and until
// carry the whole query the logging package's Tail accepts -- the wire mirrors
// that query rather than a subset of it, so a filter cannot silently stop
// working by crossing the boundary. limit is caller-capped
// (docs/prds/state-store-contract.md §8: the log cap is 2000).
message ReadTaskLogRequest {
int64 task_id = 1;
int64 attempt = 2;
int64 limit = 3;
repeated string levels = 4;
string component = 5;
string contains = 6;
google.protobuf.Timestamp since = 7;
google.protobuf.Timestamp until = 8;
}
// found=false is not an error: the task has no log file for that attempt.
// That is a different condition from a process that cannot read logs at all
// (codes.Unavailable), and the dashboard reports them differently.
message ReadTaskLogResponse {
repeated TaskLogEntry entries = 1;
bool truncated = 2;
int64 attempt = 3;
bool found = 4;
repeated string components = 5;
// file is the path read, so the page can name where the log came from. It
// is the state directory's own layout, reported to an already-authenticated
// operator; no caller is expected to open it.
string file = 6;
}
// StreamTaskLogContent returns one attempt's log verbatim, for a download. The
// bytes are the file's own JSONL, not a re-encoding of it: this contract
// transports the log, it does not restate the format. found=false, with no
// chunks, means the attempt has no log file -- not an error.
message StreamTaskLogContentRequest {
int64 task_id = 1;
int64 attempt = 2;
}
message StreamTaskLogContentResponse {
bytes chunk = 1;
int64 attempt = 2;
bool found = 3;
}
message InsertCaptureRequest {
CapturedEvent capture = 1;
int64 retention_seconds = 2;