{"record":{"id":"ee85f8482962361a","repo":"plandex-ai/plandex","slug":"error-applying-plan","errorCode":null,"errorMessage":"Error applying plan: ","messagePattern":"Error applying plan: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_changes.go","lineNumber":242,"sourceCode":"\t\tScope:          db.LockScopeWrite,\n\t\tCtx:            ctx,\n\t\tCancelFn:       cancel,\n\t\tClearRepoOnErr: true,\n\t}, func(repo *db.GitRepo) error {\n\t\treturn db.ApplyPlan(repo, ctx, db.ApplyPlanParams{\n\t\t\tOrgId:                  auth.OrgId,\n\t\t\tUserId:                 auth.User.Id,\n\t\t\tBranchName:             branch,\n\t\t\tPlan:                   plan,\n\t\t\tCurrentPlanState:       currentPlan,\n\t\t\tCurrentPlanStateParams: &currentPlanParams,\n\t\t\tCommitMsg:              commitMsg,\n\t\t})\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error applying plan: %v\\n\", err)\n\t\thttp.Error(w, \"Error applying plan: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tw.Write([]byte(commitMsg))\n\n\tlog.Println(\"Successfully applied plan\", planId)\n}\n\nfunc RejectAllChangesHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for RejectAllChangesHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\tvars := mux.Vars(r)\n\tplanId := vars[\"planId\"]","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_changes.go#L224-L260","documentation":"The final db.ApplyPlan call inside the write-lock ExecRepoOperation failed, so the handler returns 500 'Error applying plan: <detail>'. Because ClearRepoOnErr is set, the plan's internal git repo is cleared on failure to avoid a corrupt intermediate state — pending results are left unapplied.","triggerScenarios":"Git operations inside ApplyPlan fail (checkout/merge conflict, dirty repo, detached head); DB write of the applied context/files fails; context cancellation mid-apply; lock contention forcing an error with repo clear.","commonSituations":"Two clients applying simultaneously; plan file conflicts with current branch state; disk full or git lock files left by a crashed process; Postgres failure mid-commit; user navigated away and context cancelled.","solutions":["Check the appended error detail and server log for the failing git/DB step","Remove stale .git lock files in the plan repo if a previous crash left them","Ensure no concurrent apply/reject is running on the same plan/branch, then retry","Verify disk space and Postgres health; if the repo was cleared, re-apply from pending results"],"exampleFix":"null","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"const res = await fetch(applyUrl, opts);\nif (res.status === 500 && (await res.text()).includes('Error applying plan')) {\n  // repo may have been cleared (ClearRepoOnErr): check plan state, then re-apply\n  const state = await fetch(currentPlanUrl);\n  // verify pending results still exist before retrying\n}","preventionTips":["Only one apply per plan/branch at a time; lock client-side","Keep adequate disk space and clean stale git lock files on the server","Keep the request context alive (no premature aborts) during apply","After a failed apply, re-fetch plan state before retrying"],"tags":["git","database","apply","http"],"backgroundTag":"plan-apply-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"}