plandex-ai/plandex · error

Error reading request body

Error message

Error reading request body

What it means

HTTP 500 error returned by LoadContextHandler when io.ReadAll fails while reading the raw request body, before any JSON parsing of shared.LoadContextRequest occurs. It indicates a transport-level failure reading the stream from the client (connection reset, read timeout, or closed body), not malformed request content. The plan has already been authorized when this fires.

Source

Thrown at app/server/handlers/plans_context.go:176

	if auth == nil {
		return
	}

	vars := mux.Vars(r)
	planId := vars["planId"]
	branchName := vars["branch"]
	log.Println("planId: ", planId)

	plan := authorizePlan(w, planId, auth)
	if plan == nil {
		return
	}

	// read the request body
	body, err := io.ReadAll(r.Body)
	if err != nil {
		log.Printf("Error reading request body: %v\n", err)
		http.Error(w, "Error reading request body", http.StatusInternalServerError)
		return
	}
	defer r.Body.Close()

	var requestBody shared.LoadContextRequest
	if err := json.Unmarshal(body, &requestBody); err != nil {
		log.Printf("Error parsing request body: %v\n", err)
		http.Error(w, "Error parsing request body", http.StatusBadRequest)
		return
	}

	res, _ := loadContexts(loadContextsParams{
		w:          w,
		r:          r,
		auth:       auth,
		loadReq:    &requestBody,
		plan:       plan,
		branchName: branchName,

View on GitHub (pinned to e2d772072e)

Solutions

  1. Retry the request from the client
  2. Check for disconnects or proxies truncating large bodies
  3. Verify Content-Length matches the body size
Defensive patterns

Strategy: validation

Validate before calling

// client-side: send a complete, bounded body
payload, _ := json.Marshal(req)
httpReq, _ := http.NewRequest(http.MethodPost, url, bytes.NewReader(payload))
httpReq.ContentLength = int64(len(payload))
httpReq.Header.Set("Content-Type", "application/json")

Try / catch

body, err := io.ReadAll(r.Body)
if err != nil {
	if errors.Is(err, context.Canceled) || errors.Is(err, io.ErrUnexpectedEOF) {
		http.Error(w, "Error reading request body", http.StatusBadRequest)
		return
	}
	http.Error(w, "Error reading request body", http.StatusInternalServerError)
	return
}

Prevention

When it happens

Trigger: Thrown at app/server/handlers/plans_context.go:176 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/b08a46ab91ca91a4. Report an issue: GitHub.