{"record":{"id":"d226bb9f761dfc72","repo":"plandex-ai/plandex","slug":"error-getting-current-plan-state","errorCode":null,"errorMessage":"Error getting current plan state: ","messagePattern":"Error getting current plan state: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_changes.go","lineNumber":89,"sourceCode":"\t\t\t\t}\n\t\t\t}()\n\t\t}\n\n\t\tplanState, err = db.GetCurrentPlanState(db.CurrentPlanStateParams{\n\t\t\tOrgId:  auth.OrgId,\n\t\t\tPlanId: planId,\n\t\t})\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error getting current plan state: %v\", err)\n\t\t}\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error getting current plan state: %v\\n\", err)\n\t\thttp.Error(w, \"Error getting current plan state: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tjsonBytes, err := json.Marshal(planState)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error marshalling plan state: %v\\n\", err)\n\t\thttp.Error(w, \"Error marshalling plan state: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"Successfully retrieved current plan state\")\n\n\tw.Write(jsonBytes)\n}\n\nfunc ApplyPlanHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for ApplyPlanHandler\")","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_changes.go#L71-L107","documentation":"CurrentPlanHandler failed inside its ExecRepoOperation block: either checking out the requested sha, or db.GetCurrentPlanState reading the plan's git-backed state from the database. The handler responds 500 with the underlying error string appended, so the exact cause (checkout failure, DB error, lock failure) is in the response and server log.","triggerScenarios":"GET current plan with ?sha=<sha> where the sha does not exist or checkout fails; GetCurrentPlanState DB query fails; repo operation lock cannot be acquired or context is cancelled during the read.","commonSituations":"Client caching a sha that was garbage-collected or belongs to another branch; Postgres unavailable; concurrent operation holding the plan repo lock; plan corrupted by an interrupted apply.","solutions":["Read the appended error detail in the 500 response — it names the failing step (checkout vs. state query)","If a sha was passed, verify it exists on the branch (git rev-parse) and retry without the sha parameter","Check for a stuck repo lock from a crashed session and that Postgres is healthy","If the plan state is corrupt, reject all pending changes or restore the plan from backup"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"if (sha) { /* confirm sha exists on the branch, e.g. via plan revisions list, before requesting it */ }","typeGuard":"null","tryCatchPattern":"try {\n  const res = await fetch(currentPlanUrl);\n  if (!res.ok) {\n    const msg = await res.text(); // includes underlying cause (checkout/DB/lock)\n    if (msg.includes('error checking out sha')) { /* retry without sha param */ }\n    throw new Error(msg);\n  }\n  const planState = await res.json();\n} catch (err) { /* handle */ }","preventionTips":["Only request shas returned by the server's own revision/diff endpoints","Avoid hammering current-plan while another operation is applying — retry on lock errors","Monitor Postgres health; most 500s here are DB-side","After a crashed session, verify plan state before reads"],"tags":["git","database","plan-state","http"],"backgroundTag":"plan-state-read-failed","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"}