Skip to content

fix: return 409 Conflict instead of 502 when task agent is busy - #23424

Merged
mafredri merged 1 commit into
mainfrom
mafredri/fix-task-send-status-code
Mar 23, 2026
Merged

fix: return 409 Conflict instead of 502 when task agent is busy#23424
mafredri merged 1 commit into
mainfrom
mafredri/fix-task-send-status-code

Conversation

@mafredri

@mafredri mafredri commented Mar 23, 2026

Copy link
Copy Markdown
Member

The taskSend handler returns 502 Bad Gateway when the agentapi
reports 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).

🤖 This PR was created with the help of Coder Agents, and has been reviewed by a human. 🏂🏻

Comment thread coderd/aitasks.go
@@ -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{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
mafredri force-pushed the mafredri/fix-task-send-status-code branch from c706e26 to 82e3ba9 Compare March 23, 2026 09:43
@mafredri
mafredri marked this pull request as ready for review March 23, 2026 09:49
@mafredri
mafredri enabled auto-merge (squash) March 23, 2026 09:50
@mafredri
mafredri merged commit 75f5b60 into main Mar 23, 2026
35 checks passed
@mafredri
mafredri deleted the mafredri/fix-task-send-status-code branch March 23, 2026 09:52
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants