{"record":{"id":"01cc0aabf59bd326","repo":"plandex-ai/plandex","slug":"error-loading-context-v","errorCode":null,"errorMessage":"error loading context: %v","messagePattern":"error loading context: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/result_helpers.go","lineNumber":657,"sourceCode":"\t\t\t\t})\n\t\t\t}\n\n\t\t\tif len(loadReq) > 0 {\n\t\t\t\tres, _, err := LoadContexts(\n\t\t\t\t\tctx,\n\t\t\t\t\tLoadContextsParams{\n\t\t\t\t\t\tOrgId:                    orgId,\n\t\t\t\t\t\tUserId:                   userId,\n\t\t\t\t\t\tPlan:                     plan,\n\t\t\t\t\t\tBranchName:               branchName,\n\t\t\t\t\t\tReq:                      &loadReq,\n\t\t\t\t\t\tSkipConflictInvalidation: true, // no need to invalidate conflicts when applying plan--and fixes race condition since invalidation check loads description\n\t\t\t\t\t\tAutoLoaded:               true,\n\t\t\t\t\t},\n\t\t\t\t)\n\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCh <- fmt.Errorf(\"error loading context: %v\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tloadContextRes = res\n\t\t\t}\n\n\t\t\terrCh <- nil\n\t\t}()\n\t}\n\n\tif len(pendingUpdatedFilesSet) > 0 {\n\t\tgo func() {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tlog.Printf(\"panic in ApplyPlan: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\terrCh <- fmt.Errorf(\"panic in ApplyPlan: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t\t}","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/result_helpers.go#L639-L675","documentation":"This error wraps a failure from LoadContexts() while ApplyPlan loads newly-added plan files as file-type contexts on the plan's branch. ApplyPlan launches a goroutine that batches every path in pendingNewFilesSet into a LoadContextRequest; if LoadContexts returns an error (file missing on disk, invalid body, storage/DB failure), it is wrapped with \"error loading context: %v\" and sent over errCh, which ApplyPlan then surfaces wrapped again as \"error applying plan\". The plan apply is aborted, so no PlanApply record is stored.","triggerScenarios":"Calling ApplyPlan with a plan state whose CurrentPlanFiles.Files contains paths in pendingNewFilesSet whose Body is missing/invalid, whose FilePath does not exist on disk, or when the underlying context store (DB/file storage) fails during LoadContexts; also triggered when loadContextRes assignment path errors before errCh <- nil, leaving numRoutines waiting on errCh satisfied only by this error.","commonSituations":"Plan applied after the workspace files were deleted or renamed outside the tool; partial plan state where file bodies were never persisted; storage directory permissions changed or disk full; concurrent apply of the same plan racing on the same context files; org/plan/branch identifiers stale after a branch switch or plan deletion.","solutions":["Inspect the wrapped inner error in the message to identify the LoadContexts failure (missing file, bad body, storage error) and fix that root cause.","Verify each file path in the plan's pendingNewFiles exists on disk and has a non-empty Body in CurrentPlanFiles.Files before calling ApplyPlan.","Check permissions on the context/results storage directories and available disk space.","Ensure no concurrent ApplyPlan or branch switch is running against the same plan; serialize applies per plan.","Re-generate or re-fetch the plan state so file bodies are complete, then retry the apply."],"exampleFix":"// before: applying a plan whose new-file bodies were lost\napplyRes, err := db.ApplyPlan(ctx, params) // -> error loading context: open /path: no such file\n\n// after: pre-validate new file bodies before applying\nfor path := range planState.CurrentPlanFiles.Files {\n    if planState.CurrentPlanFiles.Files[path] == \"\" {\n        return fmt.Errorf(\"plan file %s has empty body; re-generate plan before applying\", path)\n    }\n}\napplyRes, err := db.ApplyPlan(ctx, params)","handlingStrategy":"validation","validationCode":"for path := range planState.CurrentPlanFiles.Files {\n    if planState.CurrentPlanFiles.Files[path] == \"\" {\n        return fmt.Errorf(\"plan file %s has empty body\", path)\n    }\n    if _, err := os.Stat(path); err != nil {\n        return fmt.Errorf(\"plan file %s missing on disk: %w\", path, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"res, err := db.ApplyPlan(ctx, params)\nif err != nil {\n    var loadErr *fmt.WrapError\n    if strings.Contains(err.Error(), \"error loading context:\") {\n        // refresh plan state / re-load contexts and retry once\n    }\n    return err\n}","preventionTips":["Validate all new-file bodies exist and are non-empty in plan state before ApplyPlan.","Confirm workspace files referenced by the plan still exist at their paths.","Check storage directory permissions and free disk space before large applies.","Serialize ApplyPlan calls per plan to avoid concurrent state races."],"tags":["go","context-loading","plan-apply","file-storage"],"backgroundTag":"context-load-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"}