plandex-ai/plandex · error
Error getting contexts:
Error message
Error getting contexts:
What it means
ListContextHandler calls db.GetPlanContexts inside db.ExecRepoOperation under a read repo lock. Any failure from the lock/repo layer or the contexts SQL query is returned to the client as HTTP 500 'Error getting contexts: <err>'.
Source
Thrown at app/server/handlers/plans_context.go:59
Branch: branch,
Reason: "list contexts",
Scope: db.LockScopeRead,
Ctx: ctx,
CancelFn: cancel,
}, func(repo *db.GitRepo) error {
res, err := db.GetPlanContexts(auth.OrgId, planId, false, false)
if err != nil {
return err
}
dbContexts = res
return nil
})
if err != nil {
log.Printf("Error getting contexts: %v\n", err)
http.Error(w, "Error getting contexts: "+err.Error(), http.StatusInternalServerError)
return
}
var apiContexts []*shared.Context
for _, dbContext := range dbContexts {
apiContexts = append(apiContexts, dbContext.ToApi())
}
bytes, err := json.Marshal(apiContexts)
if err != nil {
log.Printf("Error marshalling contexts: %v\n", err)
http.Error(w, "Error marshalling contexts: "+err.Error(), http.StatusInternalServerError)
return
}
w.Write(bytes)View on GitHub (pinned to e2d772072e)
Solutions
- Inspect the wrapped error in the server log to identify DB vs git-repo cause
- Verify PostgreSQL connectivity/credentials and that the contexts table exists with the expected schema
- Retry — lock contention is transient
- Check the plan's git repo directory on the server; reinitialize/restore if missing
- Run any pending database migrations if the deployment was recently upgraded
Defensive patterns
Strategy: retry
Validate before calling
if err := db.Conn.Ping(); err != nil { return fmt.Errorf("database unreachable: %w", err) } Try / catch
err := db.ExecRepoOperation(params, fn)
if err != nil {
if errors.Is(err, context.Canceled) { return } // client went away
http.Error(w, "Error getting contexts: "+err.Error(), http.StatusInternalServerError)
} Prevention
- Keep DB credentials/DSN in env config and validate at startup
- Run schema migrations on deploy to avoid column mismatches
- Retry transient lock/DB errors with backoff
- Ensure plan repo volumes are backed up and monitored
When it happens
Trigger: ExecRepoOperation fails (lock wait canceled, missing/corrupt plan git repo) or db.GetPlanContexts errors querying the contexts table for the org/plan.
Common situations: Database unreachable or misconfigured (bad DSN, wrong credentials); contexts table schema mismatch after version upgrade; plan repo directory missing on disk; client canceled the request while the handler waited for a lock.
Related errors
- Error creating project:
- error adding plan context tokens: %v
- error adding org member: %v
- error listing org roles: %v
- error adding org user: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/358a46ebd31e545e.
Report an issue: GitHub.