plandex-ai/plandex · warning

Context not found

Error message

Context not found

What it means

GetContextBodyHandler iterates the plan's contexts looking for dbContext.Id == contextId from the URL path. If no context matches, it returns HTTP 404 'Context not found'. This means the plan exists and was authorized, but no context with that id is currently attached to it.

Source

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

		return nil
	})

	if err != nil {
		log.Printf("Error getting contexts: %v\n", err)
		http.Error(w, "Error getting contexts: "+err.Error(), http.StatusInternalServerError)
		return
	}

	var targetContext *db.Context
	for _, dbContext := range dbContexts {
		if dbContext.Id == contextId {
			targetContext = dbContext
			break
		}
	}

	if targetContext == nil {
		http.Error(w, "Context not found", http.StatusNotFound)
		return
	}

	response := shared.GetContextBodyResponse{
		Body: targetContext.Body,
	}

	bytes, err := json.Marshal(response)
	if err != nil {
		log.Printf("Error marshalling response: %v\n", err)
		http.Error(w, "Error marshalling response: "+err.Error(), http.StatusInternalServerError)
		return
	}

	w.Write(bytes)
}

func LoadContextHandler(w http.ResponseWriter, r *http.Request) {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Re-fetch the plan's context list and confirm the contextId exists
  2. Verify you're hitting the correct planId/branch the context belongs to
  3. Refresh client state — the context was likely deleted concurrently
  4. Correct a mistyped/copied contextId before retrying

Example fix

// before
http.Error(w, "Context not found", http.StatusNotFound)
// after
http.Error(w, fmt.Sprintf("Context %s not found on plan %s", contextId, planId), http.StatusNotFound)
Defensive patterns

Strategy: validation

Validate before calling

// caller-side check before requesting the body
resp, _ := http.Get(base + "/plans/" + planId + "/contexts")
var ctxs []map[string]any
json.NewDecoder(resp.Body).Decode(&ctxs)
found := false
for _, c := range ctxs { if c["id"] == contextId { found = true } }
if !found { return errors.New("context does not exist on plan") }

Try / catch

if targetContext == nil {
	http.Error(w, "Context not found", http.StatusNotFound)
	return
}
// client: treat 404 as stale-state signal and refresh the context list

Prevention

When it happens

Trigger: Requesting GET .../context/{contextId}/body with a contextId that was deleted, belongs to a different plan/branch, or never existed (typo/stale id).

Common situations: Client holding a cached context list after the context was removed; using a context id from another plan; context deleted by a concurrent user or by plan rollback; switching branches where the context isn't loaded.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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