plandex-ai/plandex · error

Error loading contexts:

Error message

Error loading contexts: 

What it means

The actual persistence step: db.ExecRepoOperation takes a write lock and db.LoadContexts writes the contexts into the plan's git-based repo, then commits. Any error from the repo operation, the load itself, or the subsequent git commit is returned here and sent as HTTP 500 with 'Error loading contexts: ' + err.

Source

Thrown at app/server/handlers/context_helper.go:284

		if loadRes.MaxTokensExceeded {
			return nil
		}

		log.Printf("[ContextHelper] Committing changes to branch %s", branchName)
		err = repo.GitAddAndCommit(branchName, res.Msg)

		if err != nil {
			return fmt.Errorf("error committing changes: %v", err)
		}

		log.Printf("[ContextHelper] Committing changes to branch %s completed successfully", branchName)

		return nil
	})

	if err != nil {
		log.Printf("Error loading contexts: %v\n", err)
		http.Error(w, "Error loading contexts: "+err.Error(), http.StatusInternalServerError)
		return nil, nil
	}

	if loadRes.MaxTokensExceeded {
		log.Printf("The total number of tokens (%d) exceeds the maximum allowed (%d)", loadRes.TotalTokens, loadRes.MaxTokens)
		bytes, err := json.Marshal(loadRes)

		if err != nil {
			log.Printf("Error marshalling response: %v\n", err)
			http.Error(w, "Error marshalling response: "+err.Error(), http.StatusInternalServerError)
			return nil, nil
		}

		w.Write(bytes)
		return nil, nil
	}

	return loadRes, dbContexts

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the server log for the wrapped error after 'Error loading contexts:' to find root cause
  2. Inspect the plan's git repo (git status / git fsck in plans storage) and repair or ClearRepoOnErr artifacts if corrupt
  3. Ensure adequate disk space and that git user config exists for the server process
  4. Retry if caused by a transient lock timeout or cancelled request
Defensive patterns

Strategy: retry

Validate before calling

// pre-check: repo is not dirty/locked and disk has headroom
if repoDirty(planDir) || !diskHasSpace(planDir, 100*1024*1024) {
    return fmt.Errorf("plan repo busy or disk low; resolve before loading contexts")
}

Try / catch

resp, err := doLoad(req)
if err != nil && strings.Contains(err.Error(), "Error loading contexts") {
    if isTransient(err) { // lock timeout, network blip
        return retryWithBackoff(doLoad)
    }
    return repairPlanRepo(err) // git fsck / clear repo on corruption
}

Prevention

When it happens

Trigger: db.LoadContexts fails (map/token computation, storage write) or repo.GitAddAndCommit fails inside the repo operation — also on lock contention timeouts or context cancellation of r.Context().

Common situations: Corrupt or locked plan git repo; disk full on the server; concurrent writes racing the branch lock; git identity/hooks misconfigured on self-hosted servers; client disconnect cancelling the request mid-load.

Related errors


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