plandex-ai/plandex · error
Error getting parent branch:
Error message
Error getting parent branch:
What it means
After parsing the request, CreateBranchHandler fetches the parent branch record with db.GetDbBranch(planId, branch) (branch from the URL path) and returns HTTP 500 'Error getting parent branch: <err>' on failure. This resolves the DB row for the branch the new branch will fork from; failure means the lookup itself errored (DB issue) rather than the branch simply not existing.
Source
Thrown at app/server/handlers/branches.go:121
return
}
defer func() {
log.Println("Closing request body")
r.Body.Close()
}()
var req shared.CreateBranchRequest
if err := json.Unmarshal(body, &req); err != nil {
log.Printf("Error parsing request body: %v\n", err)
http.Error(w, "Error parsing request body ", http.StatusBadRequest)
return
}
parentBranch, err := db.GetDbBranch(planId, branch)
if err != nil {
log.Printf("Error getting parent branch: %v\n", err)
http.Error(w, "Error getting parent branch: "+err.Error(), http.StatusInternalServerError)
return
}
ctx, cancel := context.WithCancel(r.Context())
err = db.ExecRepoOperation(db.ExecRepoOperationParams{
OrgId: auth.OrgId,
UserId: auth.User.Id,
PlanId: planId,
Branch: "main",
Reason: "create branch",
Scope: db.LockScopeWrite,
Ctx: ctx,
CancelFn: cancel,
}, func(repo *db.GitRepo) error {
err := db.WithTx(ctx, "create branch", func(tx *sqlx.Tx) error {
_, err = db.CreateBranch(repo, plan, parentBranch, req.Name, tx)View on GitHub (pinned to e2d772072e)
Solutions
- Check the server log for the wrapped error from GetDbBranch to distinguish DB connectivity from query errors
- Verify the parent branch path variable is a valid existing branch name for the plan
- Confirm the database is healthy and migrations are up to date
- Retry after transient DB issues resolve
Example fix
// before
parentBranch, err := db.GetDbBranch(planId, branch)
// after
parentBranch, err := db.GetDbBranch(planId, branch)
if err != nil {
return fmt.Errorf("get parent branch %s for plan %s: %w", branch, planId, err)
} Defensive patterns
Strategy: validation
Validate before calling
// client: confirm parent branch exists before creating a child
branches, err := listBranches(planId)
if err != nil { return err }
if !slices.Contains(branches, parentBranch) {
return fmt.Errorf("parent branch %q does not exist", parentBranch)
} Try / catch
// distinguish transient DB errors for retry
if resp.StatusCode == http.StatusInternalServerError && strings.Contains(body, "sql:") {
return retryWithBackoff(...)
} Prevention
- Verify the parent branch exists via the list-branches endpoint first
- Keep planId and branch path variables exact (no typos/whitespace)
- Keep database migrations current
- Retry once on transient DB errors before failing
When it happens
Trigger: POST to create a branch whose parent path variable references a branch lookup that errors — database connectivity failure, query timeout, or a corrupted plans/branches table row; also context/tx issues inside GetDbBranch.
Common situations: Database temporarily unavailable or restarted; connection pool exhausted under load; planId/branch path variable malformed causing a query error; migrated schema where the branches table is missing or drifted.
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
- branch not found
- error getting current plan state params: %v
- error getting contexts: %v
- error loading plan: %v
- error validating project
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/d3eccf3c4d4a312a.
Report an issue: GitHub.