@@ -857,13 +857,15 @@ func runDaemonRemoteStream(ctx context.Context, runner conversation.Runner, now
857857 if options .ReconnectMaxDelay <= 0 {
858858 options .ReconnectMaxDelay = 30 * time .Second
859859 }
860+ streamStartedAt := now .UTC ().Format (time .RFC3339Nano )
860861 pumpState := remotepkg.PumpState {
861- SessionID : runner .SessionID ,
862- RuntimeState : remotepkg .PumpRunning ,
863- Transport : "websocket_stream" ,
864- PollURL : remotepkg .DisplayEndpoint (registration .PollURL ),
865- WebSocketURL : remotepkg .DisplayEndpoint (registration .WebSocketURL ),
866- LastPollAt : now .UTC ().Format (time .RFC3339Nano ),
862+ SessionID : runner .SessionID ,
863+ RuntimeState : remotepkg .PumpRunning ,
864+ Transport : "websocket_stream" ,
865+ PollURL : remotepkg .DisplayEndpoint (registration .PollURL ),
866+ WebSocketURL : remotepkg .DisplayEndpoint (registration .WebSocketURL ),
867+ LastPollAt : streamStartedAt ,
868+ StreamStartedAt : streamStartedAt ,
867869 }
868870 writeStreamState := func () {
869871 _ = remotepkg .WritePumpState (pumpPath , pumpState )
@@ -887,6 +889,8 @@ func runDaemonRemoteStream(ctx context.Context, runner conversation.Runner, now
887889 pumpState .ConnectCount = result .ConnectCount
888890 pumpState .ReconnectCount = result .ReconnectCount
889891 pumpState .LastPollAt = time .Now ().UTC ().Format (time .RFC3339Nano )
892+ pumpState .StreamEndedAt = pumpState .LastPollAt
893+ pumpState .StreamStopReason = daemonRemoteStreamStopReason (ctx , streamOptions , result )
890894 if result .Error != "" {
891895 pumpState .RuntimeState = remotepkg .PumpFailed
892896 pumpState .ErrorCount ++
@@ -902,6 +906,9 @@ func runDaemonRemoteStream(ctx context.Context, runner conversation.Runner, now
902906 structured ["frame_count" ] = pumpState .FrameCount
903907 structured ["connect_count" ] = pumpState .ConnectCount
904908 structured ["reconnect_count" ] = pumpState .ReconnectCount
909+ structured ["stream_started_at" ] = pumpState .StreamStartedAt
910+ structured ["stream_ended_at" ] = pumpState .StreamEndedAt
911+ structured ["stream_stop_reason" ] = pumpState .StreamStopReason
905912 structured ["event_count" ] = pumpState .EventCount
906913 structured ["delivered_count" ] = pumpState .DeliveredCount
907914 structured ["duplicate_count" ] = pumpState .DuplicateCount
@@ -915,6 +922,19 @@ func runDaemonRemoteStream(ctx context.Context, runner conversation.Runner, now
915922 }
916923}
917924
925+ func daemonRemoteStreamStopReason (ctx context.Context , options remotepkg.WebSocketOptions , result remotepkg.WebSocketResult ) string {
926+ if strings .TrimSpace (result .Error ) != "" {
927+ return "error"
928+ }
929+ if ctx .Err () != nil {
930+ return "context_cancelled"
931+ }
932+ if options .MaxFrames > 0 && result .FrameCount >= options .MaxFrames {
933+ return "max_frames"
934+ }
935+ return "closed"
936+ }
937+
918938func runDaemonDueSchedules (ctx context.Context , runner conversation.Runner , now time.Time ) (contracts.ToolResult , error ) {
919939 return tasktools .RunDueSchedules (tool.Context {
920940 Context : ctx ,
0 commit comments