{"record":{"id":"c7f74ecaa7508ecb","repo":"plandex-ai/plandex","slug":"error-loading-contexts","errorCode":null,"errorMessage":"Error loading contexts: ","messagePattern":"Error loading contexts: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/context_helper.go","lineNumber":284,"sourceCode":"\t\tif loadRes.MaxTokensExceeded {\n\t\t\treturn nil\n\t\t}\n\n\t\tlog.Printf(\"[ContextHelper] Committing changes to branch %s\", branchName)\n\t\terr = repo.GitAddAndCommit(branchName, res.Msg)\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error committing changes: %v\", err)\n\t\t}\n\n\t\tlog.Printf(\"[ContextHelper] Committing changes to branch %s completed successfully\", branchName)\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error loading contexts: %v\\n\", err)\n\t\thttp.Error(w, \"Error loading contexts: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn nil, nil\n\t}\n\n\tif loadRes.MaxTokensExceeded {\n\t\tlog.Printf(\"The total number of tokens (%d) exceeds the maximum allowed (%d)\", loadRes.TotalTokens, loadRes.MaxTokens)\n\t\tbytes, err := json.Marshal(loadRes)\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 nil, nil\n\t\t}\n\n\t\tw.Write(bytes)\n\t\treturn nil, nil\n\t}\n\n\treturn loadRes, dbContexts","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/context_helper.go#L266-L302","documentation":"The actual persistence step: db.ExecRepoOperation takes a write lock and db.LoadContexts writes the contexts into the plan's git-based repo, then commits. Any error from the repo operation, the load itself, or the subsequent git commit is returned here and sent as HTTP 500 with 'Error loading contexts: ' + err.","triggerScenarios":"db.LoadContexts fails (map/token computation, storage write) or repo.GitAddAndCommit fails inside the repo operation — also on lock contention timeouts or context cancellation of r.Context().","commonSituations":"Corrupt or locked plan git repo; disk full on the server; concurrent writes racing the branch lock; git identity/hooks misconfigured on self-hosted servers; client disconnect cancelling the request mid-load.","solutions":["Check the server log for the wrapped error after 'Error loading contexts:' to find root cause","Inspect the plan's git repo (git status / git fsck in plans storage) and repair or ClearRepoOnErr artifacts if corrupt","Ensure adequate disk space and that git user config exists for the server process","Retry if caused by a transient lock timeout or cancelled request"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-check: repo is not dirty/locked and disk has headroom\nif repoDirty(planDir) || !diskHasSpace(planDir, 100*1024*1024) {\n    return fmt.Errorf(\"plan repo busy or disk low; resolve before loading contexts\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := doLoad(req)\nif err != nil && strings.Contains(err.Error(), \"Error loading contexts\") {\n    if isTransient(err) { // lock timeout, network blip\n        return retryWithBackoff(doLoad)\n    }\n    return repairPlanRepo(err) // git fsck / clear repo on corruption\n}","preventionTips":["Ensure ample disk space and git identity for the server process","Avoid concurrent heavy loads against the same plan/branch","Run git fsck on plan repos after crashes","Keep server and CLI versions aligned"],"tags":["http-500","git","storage","context-load","plandex"],"backgroundTag":"git-commit-failure","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"}