Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit62b94b7

Browse files
committed
fix: handle new user messages correctly
Two things:1. Message IDs can be zero-based.2. We were not actually updating the last user message ID.
1 parent1006b98 commit62b94b7

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

‎cli/exp_mcp.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func (*RootCmd) mcpConfigureCursor() *serpent.Command {
363363

364364
typetaskReportstruct {
365365
linkstring
366-
messageIDint64
366+
messageID*int64
367367
selfReportedbool
368368
state codersdk.WorkspaceAppStatusState
369369
summarystring
@@ -391,7 +391,7 @@ func (r *RootCmd) mcpServer() *serpent.Command {
391391
// lastUserMessageID is the ID of the last *user* message that we saw. A
392392
// user message only happens when interacting via the AI AgentAPI (as
393393
// opposed to interacting with the terminal directly).
394-
varlastUserMessageIDint64
394+
lastUserMessageID:=int64(-1)
395395
varlastReporttaskReport
396396
// Create a queue that skips duplicates and preserves summaries.
397397
queue:= cliutil.NewQueue[taskReport](512).WithPredicate(func(reporttaskReport) (taskReport,bool) {
@@ -415,8 +415,9 @@ func (r *RootCmd) mcpServer() *serpent.Command {
415415
// user manually submits a new prompt and the AI agent becomes active
416416
// (and does not update itself), but it avoids spamming useless status
417417
// updates as the user is typing, so the tradeoff is worth it.
418-
ifreport.messageID>lastUserMessageID {
418+
ifreport.messageID!=nil&&*report.messageID>lastUserMessageID {
419419
report.state=codersdk.WorkspaceAppStatusStateWorking
420+
lastUserMessageID=*report.messageID
420421
}elseifreport.state==codersdk.WorkspaceAppStatusStateWorking&&!report.selfReported&&lastReport.state!="" {
421422
returnreport,false
422423
}
@@ -607,7 +608,7 @@ func (s *mcpServer) startWatcher(ctx context.Context, inv *serpent.Invocation) {
607608
case agentapi.EventMessageUpdate:
608609
ifev.Role==agentapi.RoleUser {
609610
err:=s.queue.Push(taskReport{
610-
messageID:ev.Id,
611+
messageID:&ev.Id,
611612
})
612613
iferr!=nil {
613614
cliui.Warnf(inv.Stderr,"Failed to queue update: %s",err)

‎cli/exp_mcp_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ func TestExpMcpReporter(t *testing.T) {
835835
},
836836
// Agent messages are ignored.
837837
{
838-
event:makeMessageEvent(1,agentapi.RoleAgent),
838+
event:makeMessageEvent(0,agentapi.RoleAgent),
839839
},
840840
// AI agent reports that it failed and URI is blank.
841841
{
@@ -854,7 +854,7 @@ func TestExpMcpReporter(t *testing.T) {
854854
// ... but this time we have a new user message so we know there is AI
855855
// agent activity. This time the "working" update will not be skipped.
856856
{
857-
event:makeMessageEvent(2,agentapi.RoleUser),
857+
event:makeMessageEvent(1,agentapi.RoleUser),
858858
expected:&codersdk.WorkspaceAppStatus{
859859
State:codersdk.WorkspaceAppStatusStateWorking,
860860
Message:"oops",
@@ -895,6 +895,15 @@ func TestExpMcpReporter(t *testing.T) {
895895
URI:"",
896896
},
897897
},
898+
// Zero ID should be accepted.
899+
{
900+
event:makeMessageEvent(0,agentapi.RoleUser),
901+
expected:&codersdk.WorkspaceAppStatus{
902+
State:codersdk.WorkspaceAppStatusStateWorking,
903+
Message:"",
904+
URI:"",
905+
},
906+
},
898907
},
899908
},
900909
}
@@ -954,6 +963,7 @@ func TestExpMcpReporter(t *testing.T) {
954963
casew,ok:=<-watcher:
955964
require.True(t,ok,"watch channel closed")
956965
ifw.LatestAppStatus!=nil&&w.LatestAppStatus.ID!=lastAppStatus.ID {
966+
t.Logf("Got status update: %s > %s",lastAppStatus.State,w.LatestAppStatus.State)
957967
lastAppStatus=*w.LatestAppStatus
958968
returnlastAppStatus
959969
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp