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.
This commit is contained in:
Mathias Fredriksson
2026-03-23 11:52:34 +02:00
committed by GitHub
parent 69d430f51b
commit 75f5b60eb6
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -773,7 +773,7 @@ func (api *API) taskSend(rw http.ResponseWriter, r *http.Request) {
}
if statusResp.Status != agentapisdk.StatusStable {
return httperror.NewResponseError(http.StatusBadGateway, codersdk.Response{
return httperror.NewResponseError(http.StatusConflict, codersdk.Response{
Message: "Task app is not ready to accept input.",
Detail: fmt.Sprintf("Status: %s", statusResp.Status),
})
+5
View File
@@ -789,6 +789,11 @@ func TestTasks(t *testing.T) {
})
require.Error(t, err, "wanted error due to bad status")
var sdkErr *codersdk.Error
require.ErrorAs(t, err, &sdkErr)
require.Equal(t, http.StatusConflict, sdkErr.StatusCode())
require.Contains(t, sdkErr.Message, "not ready to accept input")
statusResponse = agentapisdk.StatusStable
//nolint:tparallel // Not intended to run in parallel.