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

Commit0740e74

Browse files
committed
Only override agent status if agent api is configured
1 parentd1a09cb commit0740e74

File tree

2 files changed

+68
-31
lines changed

2 files changed

+68
-31
lines changed

‎cli/exp_mcp.go‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,19 @@ func (s *mcpServer) startServer(ctx context.Context, inv *serpent.Invocation, in
676676
// Add tool dependencies.
677677
toolOpts:= []func(*toolsdk.Deps){
678678
toolsdk.WithTaskReporter(func(args toolsdk.ReportTaskArgs)error {
679+
// The agent does not reliably report its status correctly. If AgentAPI
680+
// is enabled, we will always set the status to "working" when we get an
681+
// MCP message, and rely on the screen watcher to eventually catch the
682+
// idle state.
683+
state:=codersdk.WorkspaceAppStatusStateWorking
684+
ifs.aiAgentAPIClient==nil {
685+
state=codersdk.WorkspaceAppStatusState(args.State)
686+
}
679687
returns.queue.Push(taskReport{
680688
link:args.Link,
681689
selfReported:true,
682-
// The agent does not reliably report its status correctly. We will
683-
// always set the status to "working" when we get an MCP message, and
684-
// rely on the screen watcher to eventually catch the idle state.
685-
state:codersdk.WorkspaceAppStatusStateWorking,
686-
summary:args.Summary,
690+
state:state,
691+
summary:args.Summary,
687692
})
688693
}),
689694
}

‎cli/exp_mcp_test.go‎

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,9 @@ func TestExpMcpReporter(t *testing.T) {
793793
}
794794

795795
runs:= []struct {
796-
namestring
797-
tests []test
796+
namestring
797+
tests []test
798+
disableAgentAPIbool
798799
}{
799800
// In this run the AI agent starts with a state change but forgets to update
800801
// that it finished.
@@ -954,6 +955,29 @@ func TestExpMcpReporter(t *testing.T) {
954955
},
955956
},
956957
},
958+
// When AgentAPI is not being used, we accept agent state updates as-is.
959+
{
960+
name:"KeepAgentState",
961+
tests: []test{
962+
{
963+
state:codersdk.WorkspaceAppStatusStateWorking,
964+
summary:"doing work",
965+
expected:&codersdk.WorkspaceAppStatus{
966+
State:codersdk.WorkspaceAppStatusStateWorking,
967+
Message:"doing work",
968+
},
969+
},
970+
{
971+
state:codersdk.WorkspaceAppStatusStateIdle,
972+
summary:"finished",
973+
expected:&codersdk.WorkspaceAppStatus{
974+
State:codersdk.WorkspaceAppStatusStateIdle,
975+
Message:"finished",
976+
},
977+
},
978+
},
979+
disableAgentAPI:true,
980+
},
957981
}
958982

959983
for_,run:=rangeruns {
@@ -980,25 +1004,6 @@ func TestExpMcpReporter(t *testing.T) {
9801004
returna
9811005
}).Do()
9821006

983-
// Mock the AI AgentAPI server.
984-
listening:=make(chanfunc(sse codersdk.ServerSentEvent)error)
985-
srv:=httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
986-
send,closed,err:=httpapi.ServerSentEventSender(w,r)
987-
iferr!=nil {
988-
httpapi.Write(ctx,w,http.StatusInternalServerError, codersdk.Response{
989-
Message:"Internal error setting up server-sent events.",
990-
Detail:err.Error(),
991-
})
992-
return
993-
}
994-
// Send initial message.
995-
send(*makeMessageEvent(0,agentapi.RoleAgent))
996-
listening<-send
997-
<-closed
998-
}))
999-
t.Cleanup(srv.Close)
1000-
aiAgentAPIURL:=srv.URL
1001-
10021007
// Watch the workspace for changes.
10031008
watcher,err:=client.WatchWorkspace(ctx,r.Workspace.ID)
10041009
require.NoError(t,err)
@@ -1019,15 +1024,39 @@ func TestExpMcpReporter(t *testing.T) {
10191024
}
10201025
}
10211026

1022-
inv,_:=clitest.New(t,
1027+
args:=[]string{
10231028
"exp","mcp","server",
1024-
// We need the agent credentials, AI AgentAPI url, and a slug for reporting.
1029+
// We need the agent credentials, AI AgentAPI url (if not
1030+
// disabled), and a slug for reporting.
10251031
"--agent-url",client.URL.String(),
10261032
"--agent-token",r.AgentToken,
10271033
"--app-status-slug","vscode",
1028-
"--ai-agentapi-url",aiAgentAPIURL,
10291034
"--allowed-tools=coder_report_task",
1030-
)
1035+
}
1036+
1037+
// Mock the AI AgentAPI server.
1038+
listening:=make(chanfunc(sse codersdk.ServerSentEvent)error)
1039+
if!run.disableAgentAPI {
1040+
srv:=httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
1041+
send,closed,err:=httpapi.ServerSentEventSender(w,r)
1042+
iferr!=nil {
1043+
httpapi.Write(ctx,w,http.StatusInternalServerError, codersdk.Response{
1044+
Message:"Internal error setting up server-sent events.",
1045+
Detail:err.Error(),
1046+
})
1047+
return
1048+
}
1049+
// Send initial message.
1050+
send(*makeMessageEvent(0,agentapi.RoleAgent))
1051+
listening<-send
1052+
<-closed
1053+
}))
1054+
t.Cleanup(srv.Close)
1055+
aiAgentAPIURL:=srv.URL
1056+
args=append(args,"--ai-agentapi-url",aiAgentAPIURL)
1057+
}
1058+
1059+
inv,_:=clitest.New(t,args...)
10311060
inv=inv.WithContext(ctx)
10321061

10331062
pty:=ptytest.New(t)
@@ -1050,7 +1079,10 @@ func TestExpMcpReporter(t *testing.T) {
10501079
_=pty.ReadLine(ctx)// ignore echo
10511080
_=pty.ReadLine(ctx)// ignore init response
10521081

1053-
sender:=<-listening
1082+
varsenderfunc(sse codersdk.ServerSentEvent)error
1083+
if!run.disableAgentAPI {
1084+
sender=<-listening
1085+
}
10541086

10551087
for_,test:=rangerun.tests {
10561088
iftest.event!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp