plandex-ai/plandex · error

error getting current plan state: %v

Error message

error getting current plan state: %v

What it means

Returned from the get-current-plan-state repo operation when db.GetCurrentPlanState fails to assemble the plan's current state (files, contexts, versions) from the database. The ExecRepoOperation closure aborts and the handler responds 500 'Error getting current plan state: error getting current plan state'.

Source

Thrown at app/server/handlers/plans_changes.go:81

			if err != nil {
				return fmt.Errorf("error checking out sha: %v", err)
			}

			defer func() {
				checkoutErr := repo.GitCheckoutBranch(branch)
				if checkoutErr != nil {
					log.Printf("Error checking out branch: %v\n", checkoutErr)
				}
			}()
		}

		planState, err = db.GetCurrentPlanState(db.CurrentPlanStateParams{
			OrgId:  auth.OrgId,
			PlanId: planId,
		})

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

		return nil
	})

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

	jsonBytes, err := json.Marshal(planState)

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

View on GitHub (pinned to e2d772072e)

Solutions

  1. Confirm the planId is valid and the plan still exists in the requesting org
  2. Check server logs for the wrapped error to identify the exact DB failure
  3. Retry once transient lock/connection issues clear — the operation takes a read lock and can contend with writers
  4. Verify migrations ran fully if state rows appear missing or malformed

Example fix

// before: deleted plan id
client.GetCurrentPlanState("outdated-plan-id")
// after: list plans first and use a live id
plans := client.ListPlans(); client.GetCurrentPlanState(plans[0].Id)
Defensive patterns

Strategy: retry

Validate before calling

// ensure the plan exists and is accessible before querying state
const plan = (await client.ListPlans()).find(p => p.id === planId)
if (!plan) throw new Error('plan not found: ' + planId)

Try / catch

try {
  state = await client.GetCurrentPlanState(planId)
} catch (err) {
  if (String(err.message).includes('error getting current plan state')) {
    await new Promise(r => setTimeout(r, 1500)) // allow lock contention to clear
    state = await client.GetCurrentPlanState(planId)
  }
}

Prevention

When it happens

Trigger: GET plan-state where db.GetCurrentPlanState({OrgId, PlanId}) hits a DB error: missing/invalid plan row, corrupt or partially-migrated state rows, connection failure, or query timeout under lock contention.

Common situations: Querying a plan that was deleted or belongs to another org; DB pool exhaustion while other repo operations hold write locks; schema drift after a version upgrade.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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