plandex-ai/plandex · error

error retrieving context: %v

Error message

error retrieving context: %v

What it means

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.

Source

Thrown at app/cli/lib/context_update.go:311

}

type mapState struct {
	removedMapPaths      []string
	mapInputShas         map[string]string
	mapInputTokens       map[string]int
	mapInputSizes        map[string]int64
	totalMapSize         int64
	currentMapInputBatch shared.FileMapInputs
	mapInputBatches      []shared.FileMapInputs
}

func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (*types.ContextOutdatedResult, error) {
	var contexts []*shared.Context

	if maybeContexts == nil {
		contextsRes, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)
		if apiErr != nil {
			return nil, fmt.Errorf("error retrieving context: %v", apiErr)
		}
		contexts = contextsRes
	} else {
		contexts = maybeContexts
	}

	totalTokens := 0
	for _, c := range contexts {
		totalTokens += c.NumTokens
	}

	var errs []error

	reqFns := map[string]func() (*shared.UpdateContextParams, error){}

	var updatedContexts []*shared.Context
	var tokenDiffsById = map[string]int{}
	var numFiles int

View on GitHub (pinned to e2d772072e)

Solutions

  1. Load/verify the plan first (plandex plans, plandex cd / set current plan) so CurrentPlanId/CurrentBranch are valid
  2. Re-authenticate if the wrapped error is 401/403
  3. Check the server is reachable (daemon running, correct server URL) and retry on transient network errors
  4. Alternatively pass cached contexts (maybeContexts) to skip the API call when you already have them

Example fix

// before: nil contexts forces API call that may fail
outdated, err := lib.CheckOutdatedContext(nil, projectPaths)
// after: supply already-fetched contexts to avoid the retrieval error
contexts, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)
if apiErr != nil { /* handle auth/network first */ }
outdated, err := lib.CheckOutdatedContext(contexts, projectPaths)
Defensive patterns

Strategy: fallback

Validate before calling

if CurrentPlanId == "" || CurrentBranch == "" {
    return fmt.Errorf("no plan/branch selected; load a plan before checking context")
}

Try / catch

outdated, err := lib.CheckOutdatedContext(nil, paths) // triggers ListContext
if err != nil && strings.Contains(err.Error(), "error retrieving context") {
    // fallback: use locally cached contexts instead of the API
    if cached != nil {
        outdated, err = lib.CheckOutdatedContext(cached, paths)
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: Running commands outside a loaded plan session (stale CurrentPlanId); server daemon not running; VPN/network change; branch deleted remotely by another client.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/ac50c13a48553d90. Report an issue: GitHub.