plandex-ai/plandex · error

failed to get contexts: %v

Error message

failed to get contexts: %v

What it means

AutoLoadContextFiles wraps a failure from api.Client.ListContext(CurrentPlanId, CurrentBranch), the remote call that enumerates contexts for the current plan/branch. Nothing was loaded, so the function returns an empty string and this error, usually indicating connectivity or an invalid plan/branch identifier.

Source

Thrown at app/cli/lib/context_auto_load.go:20

import (
	"context"
	"encoding/base64"
	"fmt"
	"log"
	"os"
	"plandex-cli/api"
	"plandex-cli/types"
	shared "plandex-shared"
	"sync"

	"github.com/sashabaranov/go-openai"
)

func AutoLoadContextFiles(ctx context.Context, files []string) (string, error) {
	contexts, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)
	if err != nil {
		return "", fmt.Errorf("failed to get contexts: %v", err)
	}

	var totalSize int64
	totalContexts := len(contexts)

	for _, context := range contexts {
		totalSize += context.BodySize
	}

	loadContextReqsByIndex := make(map[int]*shared.LoadContextParams)
	filesSkippedTooLarge := []filePathWithSize{}
	filesSkippedAfterSizeLimit := []string{}

	var mu sync.Mutex
	errCh := make(chan error, len(files))

	for i, path := range files {
		totalContexts++

View on GitHub (pinned to e2d772072e)

Solutions

  1. Verify the client is authenticated and the API base URL is reachable (check credentials/env).
  2. Ensure CurrentPlanId and CurrentBranch are set — initialize or select a plan/branch before calling AutoLoadContextFiles.
  3. Refresh the local plan/branch reference if it was deleted remotely.
  4. Retry on transient network errors; return a graceful empty result if no contexts are configured.
  5. Check server status / API version compatibility if 5xx persists.

Example fix

// before
func AutoLoadContextFiles(ctx context.Context, files []string) (string, error) {
    contexts, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)
// after
func AutoLoadContextFiles(ctx context.Context, files []string) (string, error) {
    if CurrentPlanId == "" || CurrentBranch == "" {
        return "", nil // nothing to load yet
    }
    contexts, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)
Defensive patterns

Strategy: try-catch

Validate before calling

if CurrentPlanId == "" || CurrentBranch == "" {
    return "", nil // no plan/branch selected yet; nothing to load
}
if err := api.Client.Ping(ctx); err != nil {
    return "", fmt.Errorf("API unreachable: %w", err)
}

Try / catch

contexts, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)
if err != nil {
    var apiErr *api.Error
    if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusUnauthorized {
        return "", fmt.Errorf("re-authenticate: %w", err)
    }
    return "", fmt.Errorf("failed to get contexts: %v", err)
}

Prevention

When it happens

Trigger: api.Client.ListContext(CurrentPlanId, CurrentBranch) returns an error: API unreachable/unauthenticated, CurrentPlanId or CurrentBranch empty or pointing at a deleted plan/branch, or server 4xx/5xx.

Common situations: Running before any plan/branch was initialized (CurrentPlanId is zero-value), expired API credentials, network outage, or the plan/branch being deleted remotely while a stale local reference remains.

Related errors


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