{"record":{"id":"64dd38361c1fda64","repo":"plandex-ai/plandex","slug":"failed-to-list-contexts-v","errorCode":null,"errorMessage":"failed to list contexts: %v","messagePattern":"failed to list contexts: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/context_load.go","lineNumber":129,"sourceCode":"\terrCh := make(chan error)\n\tignoredPaths := make(map[string]string)\n\n\tmapFilesTruncatedTooLarge := []filePathWithSize{}\n\tmapFilesSkippedAfterSizeLimit := []string{}\n\n\t// We'll reuse these for all skipping, including directory-tree partial skipping and URLs\n\tfilesSkippedTooLarge := []filePathWithSize{}\n\tfilesSkippedAfterSizeLimit := []string{}\n\n\tvar totalSize int64\n\n\tnumRoutines := 0\n\n\t// filter out already loaded contexts\n\talreadyLoadedByComposite := make(map[string]*shared.Context)\n\texistingContexts, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)\n\tif apiErr != nil {\n\t\tonErr(fmt.Errorf(\"failed to list contexts: %v\", apiErr.Msg))\n\t}\n\n\texistsByComposite := make(map[string]*shared.Context)\n\tfor _, context := range existingContexts {\n\t\tswitch context.ContextType {\n\t\tcase shared.ContextFileType, shared.ContextDirectoryTreeType, shared.ContextMapType, shared.ContextImageType:\n\t\t\texistsByComposite[strings.Join([]string{string(context.ContextType), context.FilePath}, \"|\")] = context\n\t\tcase shared.ContextURLType:\n\t\t\texistsByComposite[strings.Join([]string{string(context.ContextType), context.Url}, \"|\")] = context\n\t\t}\n\t}\n\n\tvar cachedMapPaths map[string]bool\n\tvar cachedMapLoadRes *shared.LoadContextResponse\n\n\tmapInputShas := map[string]string{}\n\tmapInputTokens := map[string]int{}\n\tmapInputSizes := map[string]int64{}","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_load.go#L111-L147","documentation":"MustLoadContext fetches existing contexts with api.Client.ListContext to avoid re-loading already-loaded files; this error means that list call failed via ApiErr.Msg. Without the existing-context list, deduplication cannot happen and the load aborts via onErr.","triggerScenarios":"api.Client.ListContext(CurrentPlanId, CurrentBranch) returns non-nil ApiErr — server unreachable, expired auth session, invalid plan/branch id, or server-side error.","commonSituations":"Stale session token after server restart; plan deleted in another terminal; offline/proxy outage; server deploy mid-command.","solutions":["Check server connectivity (PLANDEX_HOST / daemon status)","Re-authenticate if the message points at auth or permission","Verify plan/branch exist (`plandex plans`, `plandex branches`)","Retry; inspect server logs for the wrapped ApiErr.Msg"],"exampleFix":"// before\nexistingContexts, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)\nif apiErr != nil {\n\tonErr(fmt.Errorf(\"failed to list contexts: %v\", apiErr.Msg))\n}\n// after\nexistingContexts, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)\nif apiErr != nil {\n\tif apiErr.Type == shared.ApiErrTypeAuthExpired {\n\t\tonErr(fmt.Errorf(\"session expired — run `plandex login`: %v\", apiErr.Msg))\n\t}\n\tonErr(fmt.Errorf(\"failed to list contexts: %v\", apiErr.Msg))\n}","handlingStrategy":"retry","validationCode":"// pre-check auth and plan before listing contexts\nif auth.Current == nil || auth.Current.SessionId == \"\" {\n\treturn fmt.Errorf(\"not logged in — run `plandex login` first\")\n}\nif CurrentPlanId == \"\" {\n\treturn fmt.Errorf(\"no current plan selected\")\n}","typeGuard":"// Go: nil-guard the ApiErr before reading Msg\nfunc isApiErr(err error) (*shared.ApiErr, bool) {\n\tif apiErr, ok := err.(*shared.ApiErr); ok && apiErr != nil { return apiErr, true }\n\treturn nil, false\n}","tryCatchPattern":"// Go: exponential backoff on list failures\nvar existingContexts []*shared.Context\nvar apiErr *shared.ApiErr\nfor i := 0; i < 3; i++ {\n\texistingContexts, apiErr = api.Client.ListContext(CurrentPlanId, CurrentBranch)\n\tif apiErr == nil { break }\n\ttime.Sleep(time.Duration(1<<i) * 500 * time.Millisecond)\n}\nif apiErr != nil { onErr(fmt.Errorf(\"failed to list contexts: %v\", apiErr.Msg)) }","preventionTips":["Keep sessions fresh; re-login after server restarts","Confirm plan/branch exist before load operations","Monitor server availability in CI before running plandex commands","Pin matching CLI/server versions"],"tags":["api","network","context-loading","cli"],"backgroundTag":"api-request-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"}