plandex-ai/plandex · error

error getting contexts: %v

Error message

error getting contexts: %v

What it means

Returned by DeleteContextHandler when db.GetPlanContexts(auth.OrgId, planId, false, false) fails at the start of the delete-contexts repo operation. The list of existing contexts could not be loaded, so the handler cannot determine which requested IDs exist; the wrapped %v carries the underlying DB error and the client receives HTTP 500 'Error deleting contexts'.

Source

Thrown at app/server/handlers/plans_context.go:386

	removeTokens := 0
	var toRemoveApiContexts []*shared.Context

	err = db.ExecRepoOperation(db.ExecRepoOperationParams{
		OrgId:          auth.OrgId,
		UserId:         auth.User.Id,
		PlanId:         planId,
		Branch:         branchName,
		Reason:         "delete contexts",
		Scope:          db.LockScopeWrite,
		Ctx:            ctx,
		CancelFn:       cancel,
		ClearRepoOnErr: true,
	}, func(repo *db.GitRepo) error {
		var err error
		dbContexts, err = db.GetPlanContexts(auth.OrgId, planId, false, false)

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

		for _, dbContext := range dbContexts {
			if _, ok := requestBody.Ids[dbContext.Id]; ok {
				toRemove = append(toRemove, dbContext)
			}
		}

		err = db.ContextRemove(auth.OrgId, planId, toRemove)

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

		for _, dbContext := range toRemove {
			toRemoveApiContexts = append(toRemoveApiContexts, dbContext.ToApi())
			removeTokens += dbContext.NumTokens
		}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the wrapped DB error in the server logs
  2. Verify DB connectivity and that the plan/org rows are intact
  3. Confirm the planId in the URL belongs to the authenticated org
  4. Retry after transient DB failures
Defensive patterns

Strategy: retry

Validate before calling

if planId == "" || orgId == "" {
    return errors.New("orgId and planId are required to list plan contexts")
}
if err := db.PingContext(ctx); err != nil {
    return fmt.Errorf("database unreachable: %w", err)
}

Try / catch

dbContexts, err = db.GetPlanContexts(auth.OrgId, planId, false, false)
if err != nil {
    return fmt.Errorf("error getting contexts: %w", err)
}
// caller: retry with backoff on transient DB errors before returning 500
if err != nil {
    http.Error(w, "contexts temporarily unavailable", http.StatusServiceUnavailable)
    return
}

Prevention

When it happens

Trigger: Calling the delete-context endpoint when the contexts query fails: DB unreachable, plan has no contexts table entry / query error, or org-scoped query error for the planId.

Common situations: DB outage or connection-pool exhaustion; plan deleted concurrently; schema migration in progress; orgId/planId mismatch after auth changes.

Related errors


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