Skip to content

Commit 234bead

Browse files
committed
Only report user messages
1 parent 6cb03be commit 234bead

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

cli/exp_mcp.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,14 @@ func (s *mcpServer) startWatcher(ctx context.Context, inv *serpent.Invocation) {
599599
return
600600
}
601601
case agentapi.EventMessageUpdate:
602-
err := s.queue.Push(reportTask{
603-
messageID: ev.Id,
604-
})
605-
if err != nil {
606-
cliui.Warnf(inv.Stderr, "Failed to queue update: %s", err)
607-
return
602+
if ev.Role == agentapi.RoleUser {
603+
err := s.queue.Push(reportTask{
604+
messageID: ev.Id,
605+
})
606+
if err != nil {
607+
cliui.Warnf(inv.Stderr, "Failed to queue update: %s", err)
608+
return
609+
}
608610
}
609611
}
610612
case err := <-errCh:

cli/exp_mcp_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,12 @@ func TestExpMcpReporter(t *testing.T) {
790790
}
791791
}
792792

793-
makeMessageEvent := func(id int64) *codersdk.ServerSentEvent {
793+
makeMessageEvent := func(id int64, role agentapi.ConversationRole) *codersdk.ServerSentEvent {
794794
return &codersdk.ServerSentEvent{
795795
Type: ServerSentEventTypeMessageUpdate,
796796
Data: agentapi.EventMessageUpdate{
797-
Id: id,
797+
Id: id,
798+
Role: role,
798799
},
799800
}
800801
}
@@ -813,7 +814,7 @@ func TestExpMcpReporter(t *testing.T) {
813814
return
814815
}
815816
// Send initial message.
816-
send(*makeMessageEvent(0))
817+
send(*makeMessageEvent(0, agentapi.RoleAgent))
817818
listening <- send
818819
<-closed
819820
}))
@@ -902,13 +903,17 @@ func TestExpMcpReporter(t *testing.T) {
902903
URI: "https://dev.coder.com",
903904
},
904905
},
905-
// Terminal becomes active again according to the screen watcher, but
906-
// message length is the same. This could be the LLM being active again,
907-
// but it could also be the user messing around. We will prefer not
908-
// updating the status so the "working" update here should be skipped.
906+
// Terminal becomes active again according to the screen watcher, but no
907+
// new user message. This could be the LLM being active again, but it
908+
// could also be the user messing around. We will prefer not updating the
909+
// status so the "working" update here should be skipped.
909910
{
910911
event: makeStatusEvent(agentapi.StatusRunning),
911912
},
913+
// Agent messages are ignored.
914+
{
915+
event: makeMessageEvent(1, agentapi.RoleAgent),
916+
},
912917
// LLM reports that it failed and URI is blank.
913918
{
914919
state: codersdk.WorkspaceAppStatusStateFailure,
@@ -923,10 +928,10 @@ func TestExpMcpReporter(t *testing.T) {
923928
{
924929
event: makeStatusEvent(agentapi.StatusRunning),
925930
},
926-
// ... but this time the message length has increased so we know there is
927-
// LLM activity. This time the "working" update will not be skipped.
931+
// ... but this time we have a new user message so we know there is LLM
932+
// activity. This time the "working" update will not be skipped.
928933
{
929-
event: makeMessageEvent(1),
934+
event: makeMessageEvent(2, agentapi.RoleUser),
930935
expected: &codersdk.WorkspaceAppStatus{
931936
State: codersdk.WorkspaceAppStatusStateWorking,
932937
Message: "oops",

0 commit comments

Comments
 (0)