{"record":{"id":"ed9f31223ab701b0","repo":"plandex-ai/plandex","slug":"error-error-updating-contexts","errorCode":null,"errorMessage":"Error error updating contexts: ","messagePattern":"Error error updating contexts: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_context.go","lineNumber":289,"sourceCode":"\t\t\treturn err\n\t\t}\n\n\t\tif updateRes.MaxTokensExceeded {\n\t\t\treturn nil\n\t\t}\n\n\t\terr = repo.GitAddAndCommit(branchName, updateRes.Msg)\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error committing changes: %v\", err)\n\t\t}\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error error updating contexts: %v\\n\", err)\n\t\thttp.Error(w, \"Error error updating contexts: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tif updateRes.MaxTokensExceeded {\n\t\tlog.Printf(\"The total number of tokens (%d) exceeds the maximum allowed (%d)\", updateRes.TotalTokens, updateRes.MaxTokens)\n\t\tbytes, err := json.Marshal(updateRes)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error marshalling response: %v\\n\", err)\n\t\t\thttp.Error(w, \"Error marshalling response: \"+err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\tw.Write(bytes)\n\t\treturn\n\t}\n\n\tbytes, err := json.Marshal(updateRes)","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_context.go#L271-L307","documentation":"The repo operation wrapped in db.ExecRepoOperation inside UpdateContextHandler failed: either db.UpdateContexts errored (DB/storage) or repo.GitAddAndCommit errored (git commit). Because ClearRepoOnErr is true, the repo is cleared/reset on failure. The handler responds with HTTP 500 including the wrapped error text.","triggerScenarios":"db.UpdateContexts returns an error (context row not found, DB failure) or repo.GitAddAndCommit fails (stale .git/index.lock, merge conflict, disk full) inside the write-locked ExecRepoOperation callback; the returned error propagates to the handler's err check at line 287.","commonSituations":"Updating a context id that no longer exists on the branch; concurrent writers contending on the repo lock; index.lock left by a crashed process; branch deleted by another user mid-request; storage backend outages.","solutions":["Read the appended error text in the 500/log ('error committing changes: ...' vs UpdateContexts error) to locate the failing step","Remove a stale .git/index.lock in the plan repo if a crashed writer left one","Verify the context IDs in the request still exist on the target branch (refresh plan/branch state first)","Retry the update after resolving concurrent-writer conflicts; the repo was already cleared on error","Check disk space and DB connectivity for the plan storage backend"],"exampleFix":"// before\nerr = repo.GitAddAndCommit(branchName, updateRes.Msg)\nif err != nil {\n    return fmt.Errorf(\"error committing changes: %v\", err)\n}\n// after\nerr = repo.GitAddAndCommit(branchName, updateRes.Msg)\nif err != nil {\n    if strings.Contains(err.Error(), \"index.lock\") {\n        os.Remove(filepath.Join(repo.Path(), \".git\", \"index.lock\"))\n    }\n    return fmt.Errorf(\"error committing changes: %w\", err)\n}","handlingStrategy":"fallback","validationCode":"// before updating, confirm the contexts still exist on the branch\nbranch, err := getBranch(planId, branchName)\nif err != nil { return err }\nfor id := range req.Ids {\n    if !branchHasContext(branch, id) {\n        return fmt.Errorf(\"context %s no longer exists on %s\", id, branchName)\n    }\n}","typeGuard":null,"tryCatchPattern":"resp, err := sendUpdate(req)\nif err != nil && resp != nil && resp.StatusCode == 500 {\n    // repo was cleared on error; re-fetch state, then retry once\n    if err := refreshPlanState(planId, branchName); err != nil {\n        return err\n    }\n    return retryOnce(req)\n}","preventionTips":["Fetch fresh context IDs immediately before updating","Avoid concurrent writers to the same plan branch, or serialize via locks","Monitor for leftover .git/index.lock files in plan repos","Ensure adequate disk space on the repo storage volume"],"tags":["http","go","git","database","server","internal-error"],"backgroundTag":"repo-operation-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}