{"record":{"id":"106cdb9db6908426","repo":"plandex-ai/plandex","slug":"context-not-found","errorCode":null,"errorMessage":"Context not found","messagePattern":"Context not found","errorType":"http","errorClass":null,"httpStatus":404,"severity":"warning","filePath":"app/server/handlers/plans_context.go","lineNumber":136,"sourceCode":"\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error getting contexts: %v\\n\", err)\n\t\thttp.Error(w, \"Error getting contexts: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tvar targetContext *db.Context\n\tfor _, dbContext := range dbContexts {\n\t\tif dbContext.Id == contextId {\n\t\t\ttargetContext = dbContext\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif targetContext == nil {\n\t\thttp.Error(w, \"Context not found\", http.StatusNotFound)\n\t\treturn\n\t}\n\n\tresponse := shared.GetContextBodyResponse{\n\t\tBody: targetContext.Body,\n\t}\n\n\tbytes, err := json.Marshal(response)\n\tif err != nil {\n\t\tlog.Printf(\"Error marshalling response: %v\\n\", err)\n\t\thttp.Error(w, \"Error marshalling response: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tw.Write(bytes)\n}\n\nfunc LoadContextHandler(w http.ResponseWriter, r *http.Request) {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_context.go#L118-L154","documentation":"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.","triggerScenarios":"Requesting GET .../context/{contextId}/body with a contextId that was deleted, belongs to a different plan/branch, or never existed (typo/stale id).","commonSituations":"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.","solutions":["Re-fetch the plan's context list and confirm the contextId exists","Verify you're hitting the correct planId/branch the context belongs to","Refresh client state — the context was likely deleted concurrently","Correct a mistyped/copied contextId before retrying"],"exampleFix":"// before\nhttp.Error(w, \"Context not found\", http.StatusNotFound)\n// after\nhttp.Error(w, fmt.Sprintf(\"Context %s not found on plan %s\", contextId, planId), http.StatusNotFound)","handlingStrategy":"validation","validationCode":"// caller-side check before requesting the body\nresp, _ := http.Get(base + \"/plans/\" + planId + \"/contexts\")\nvar ctxs []map[string]any\njson.NewDecoder(resp.Body).Decode(&ctxs)\nfound := false\nfor _, c := range ctxs { if c[\"id\"] == contextId { found = true } }\nif !found { return errors.New(\"context does not exist on plan\") }","typeGuard":null,"tryCatchPattern":"if targetContext == nil {\n\thttp.Error(w, \"Context not found\", http.StatusNotFound)\n\treturn\n}\n// client: treat 404 as stale-state signal and refresh the context list","preventionTips":["Re-fetch the context list before fetching a specific body","Include planId/branch in the client's context cache key","Handle 404 by refreshing state rather than retrying blindly","Avoid reusing context ids across plans/branches"],"tags":["go","http-404","stale-id"],"backgroundTag":"resource-not-found","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}