Skip to content

Commit 75f5b60

Browse files
authored
fix: return 409 Conflict instead of 502 when task agent is busy (#23424)
The "Task app is not ready to accept input" error occurs when the agent responds successfully but its status is not "stable" (e.g. "running"). This is a state conflict, not a gateway error. 502 was semantically wrong because the gateway communication succeeded. 409 Conflict is correct because the request conflicts with the agent's current state. This is consistent with how authAndDoWithTaskAppClient already returns 409 for pending, initializing, and paused agent states.
1 parent 69d430f commit 75f5b60

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

coderd/aitasks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ func (api *API) taskSend(rw http.ResponseWriter, r *http.Request) {
773773
}
774774

775775
if statusResp.Status != agentapisdk.StatusStable {
776-
return httperror.NewResponseError(http.StatusBadGateway, codersdk.Response{
776+
return httperror.NewResponseError(http.StatusConflict, codersdk.Response{
777777
Message: "Task app is not ready to accept input.",
778778
Detail: fmt.Sprintf("Status: %s", statusResp.Status),
779779
})

coderd/aitasks_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,11 @@ func TestTasks(t *testing.T) {
789789
})
790790
require.Error(t, err, "wanted error due to bad status")
791791

792+
var sdkErr *codersdk.Error
793+
require.ErrorAs(t, err, &sdkErr)
794+
require.Equal(t, http.StatusConflict, sdkErr.StatusCode())
795+
require.Contains(t, sdkErr.Message, "not ready to accept input")
796+
792797
statusResponse = agentapisdk.StatusStable
793798

794799
//nolint:tparallel // Not intended to run in parallel.

0 commit comments

Comments
 (0)