{"record":{"id":"ac50c13a48553d90","repo":"plandex-ai/plandex","slug":"error-retrieving-context-v","errorCode":null,"errorMessage":"error retrieving context: %v","messagePattern":"error retrieving context: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/context_update.go","lineNumber":311,"sourceCode":"}\n\ntype mapState struct {\n\tremovedMapPaths      []string\n\tmapInputShas         map[string]string\n\tmapInputTokens       map[string]int\n\tmapInputSizes        map[string]int64\n\ttotalMapSize         int64\n\tcurrentMapInputBatch shared.FileMapInputs\n\tmapInputBatches      []shared.FileMapInputs\n}\n\nfunc checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (*types.ContextOutdatedResult, error) {\n\tvar contexts []*shared.Context\n\n\tif maybeContexts == nil {\n\t\tcontextsRes, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)\n\t\tif apiErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"error retrieving context: %v\", apiErr)\n\t\t}\n\t\tcontexts = contextsRes\n\t} else {\n\t\tcontexts = maybeContexts\n\t}\n\n\ttotalTokens := 0\n\tfor _, c := range contexts {\n\t\ttotalTokens += c.NumTokens\n\t}\n\n\tvar errs []error\n\n\treqFns := map[string]func() (*shared.UpdateContextParams, error){}\n\n\tvar updatedContexts []*shared.Context\n\tvar tokenDiffsById = map[string]int{}\n\tvar numFiles int","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_update.go#L293-L329","documentation":"checkOutdatedAndMaybeUpdateContext (backing CheckOutdatedContext) fetches the plan's context via api.Client.ListContext when no contexts are supplied; an API failure is wrapped as 'error retrieving context'. Without the stored context list, staleness cannot be evaluated.","triggerScenarios":"Calling CheckOutdatedContext with nil/maybeContexts==nil and api.Client.ListContext(CurrentPlanId, CurrentBranch) errors: invalid CurrentPlanId or CurrentBranch, expired auth, server down, network unreachable, plan deleted.","commonSituations":"Running commands outside a loaded plan session (stale CurrentPlanId); server daemon not running; VPN/network change; branch deleted remotely by another client.","solutions":["Load/verify the plan first (plandex plans, plandex cd / set current plan) so CurrentPlanId/CurrentBranch are valid","Re-authenticate if the wrapped error is 401/403","Check the server is reachable (daemon running, correct server URL) and retry on transient network errors","Alternatively pass cached contexts (maybeContexts) to skip the API call when you already have them"],"exampleFix":"// before: nil contexts forces API call that may fail\noutdated, err := lib.CheckOutdatedContext(nil, projectPaths)\n// after: supply already-fetched contexts to avoid the retrieval error\ncontexts, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)\nif apiErr != nil { /* handle auth/network first */ }\noutdated, err := lib.CheckOutdatedContext(contexts, projectPaths)","handlingStrategy":"fallback","validationCode":"if CurrentPlanId == \"\" || CurrentBranch == \"\" {\n    return fmt.Errorf(\"no plan/branch selected; load a plan before checking context\")\n}","typeGuard":null,"tryCatchPattern":"outdated, err := lib.CheckOutdatedContext(nil, paths) // triggers ListContext\nif err != nil && strings.Contains(err.Error(), \"error retrieving context\") {\n    // fallback: use locally cached contexts instead of the API\n    if cached != nil {\n        outdated, err = lib.CheckOutdatedContext(cached, paths)\n    }\n}","preventionTips":["Always load/select a plan before context operations","Handle auth expiry proactively (re-sign-in on 401)","Cache context lists to fall back on API outages","Verify server URL/daemon is up in scripts"],"tags":["go","api","network","context"],"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"}