on main help sign in
chore(server): acknowledge accepted prompts with HTTP 202
ee94df0Christian Rocha
internal/server/agent_cancel_test.go+2−2
@@ -139,7 +139,7 @@ func TestPostAgent_ReturnsOKOnContextCanceled(t *testing.T) {
139 // The handler returns immediately, before the dispatched run is
139 // The handler returns immediately, before the dispatched run is
140 // released, because the run no longer owns the HTTP response.
140 // released, because the run no longer owns the HTTP response.
141 rec := postAgent(t, c, t.Context(), wsID, "S1")
141 rec := postAgent(t, c, t.Context(), wsID, "S1")
142− require.Equal(t, http.StatusOK, rec.Code, "fire-and-forget SendMessage must return 200 without waiting for the run")
142+ require.Equal(t, http.StatusAccepted, rec.Code, "fire-and-forget SendMessage must return 202 without waiting for the run")
143
143
144 // The run is dispatched on a goroutine; let it return
144 // The run is dispatched on a goroutine; let it return
145 // context.Canceled. Nothing from that path reaches the (already
145 // context.Canceled. Nothing from that path reaches the (already
@@ -169,7 +169,7 @@ func TestPostAgent_DetachesRequestContext(t *testing.T) {
169 // The handler returns immediately; the run keeps executing on its
169 // The handler returns immediately; the run keeps executing on its
170 // own goroutine bound to the workspace context.
170 // own goroutine bound to the workspace context.
171 rec := postAgent(t, c, reqCtx, wsID, "S1")
171 rec := postAgent(t, c, reqCtx, wsID, "S1")
172− require.Equal(t, http.StatusOK, rec.Code)
172+ require.Equal(t, http.StatusAccepted, rec.Code)
173
173
174 select {
174 select {
175 case <-coord.entered:
175 case <-coord.entered:
internal/server/proto.go+5−2
@@ -740,9 +740,10 @@ func (c *controllerV1) handleGetWorkspaceAgent(w http.ResponseWriter, r *http.Re
740// @Accept json
740// @Accept json
741// @Param id path string true "Workspace ID"
741// @Param id path string true "Workspace ID"
742// @Param request body proto.AgentMessage true "Agent message"
742// @Param request body proto.AgentMessage true "Agent message"
743−// @Success 200
743+// @Success 202
744// @Failure 400 {object} proto.Error
744// @Failure 400 {object} proto.Error
745// @Failure 404 {object} proto.Error
745// @Failure 404 {object} proto.Error
746+// @Failure 409 {object} proto.Error
746// @Failure 500 {object} proto.Error
747// @Failure 500 {object} proto.Error
747// @Router /workspaces/{id}/agent [post]
748// @Router /workspaces/{id}/agent [post]
748func (c *controllerV1) handlePostWorkspaceAgent(w http.ResponseWriter, r *http.Request) {
749func (c *controllerV1) handlePostWorkspaceAgent(w http.ResponseWriter, r *http.Request) {
@@ -767,7 +768,7 @@ func (c *controllerV1) handlePostWorkspaceAgent(w http.ResponseWriter, r *http.R
767 c.handleError(w, r, err)
768 c.handleError(w, r, err)
768 return
769 return
769 }
770 }
770− w.WriteHeader(http.StatusOK)
771+ w.WriteHeader(http.StatusAccepted)
771}
772}
772
773
773// handlePostWorkspaceAgentInit initializes the agent for a workspace.
774// handlePostWorkspaceAgentInit initializes the agent for a workspace.
@@ -1061,6 +1062,8 @@ func (c *controllerV1) handleError(w http.ResponseWriter, r *http.Request, err e
1061 status = http.StatusBadRequest
1062 status = http.StatusBadRequest
1062 case errors.Is(err, backend.ErrClientNotAttached):
1063 case errors.Is(err, backend.ErrClientNotAttached):
1063 status = http.StatusNotFound
1064 status = http.StatusNotFound
1065+ case errors.Is(err, backend.ErrWorkspaceClosing):
1066+ status = http.StatusConflict
1064 }
1067 }
1065 c.server.logError(r, err.Error())
1068 c.server.logError(r, err.Error())
1066 jsonError(w, status, err.Error())
1069 jsonError(w, status, err.Error())