fix: return 409 Conflict instead of 502 when task agent is busy - #23424
Merged
Conversation
johnstcn
reviewed
Mar 23, 2026
| @@ -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{ | |||
Member
Author
There was a problem hiding this comment.
Good catch, should have included the test assertion from the start. Added in 82e3ba9.
Scanned the diff, found the gap, replied in 15 characters. Efficient.
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.
mafredri
force-pushed
the
mafredri/fix-task-send-status-code
branch
from
March 23, 2026 09:43
c706e26 to
82e3ba9
Compare
johnstcn
approved these changes
Mar 23, 2026
mafredri
marked this pull request as ready for review
March 23, 2026 09:49
mafredri
enabled auto-merge (squash)
March 23, 2026 09:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
taskSendhandler returns 502 Bad Gateway when the agentapireports a non-stable status (e.g. "running"). The server successfully
reached the agent and got a valid response, the agent is just busy
processing a previous prompt. 502 is semantically wrong here.
409 Conflict is the correct status code, consistent with how the same
handler already returns 409 for pending, initializing, and paused
states in
authAndDoWithTaskAppClient.Other 502s in the file are unchanged because they represent actual
gateway failures (connection refused, dial errors, agent unreachable).