plandex-ai/plandex · error
error creating main branch: %v
Error message
error creating main branch: %v
What it means
This error wraps a failure from CreateBranch(repo, plan, nil, "main", tx) in CreatePlan (app/server/db/plan_helpers.go:74). Right after the plan row is created, the server must initialize the plan's git repository and create its 'main' branch; any git-level failure (repo init, object writes, or the branch DB row inserted via tx) surfaces here. Failure aborts the surrounding WithTx transaction.
Source
Thrown at app/server/db/plan_helpers.go:74
)
if err != nil {
return fmt.Errorf("error creating plan: %v", err)
}
_, err = tx.Exec("INSERT INTO lockable_plan_ids (plan_id) VALUES ($1)", plan.Id)
if err != nil {
return fmt.Errorf("error inserting lockable plan id: %v", err)
}
// the one place where we do this to skip the locking queue
// ok to cheat this once since we're creating a new plan
repo := getGitRepo(orgId, plan.Id)
_, err = CreateBranch(repo, plan, nil, "main", tx)
if err != nil {
return fmt.Errorf("error creating main branch: %v", err)
}
log.Println("Created branch main")
err = InitPlan(orgId, plan.Id)
if err != nil {
return fmt.Errorf("error initializing plan dir: %v", err)
}
log.Println("Initialized plan dir")
return nil
})
if err != nil {
return nil, err
}View on GitHub (pinned to e2d772072e)
Solutions
- Check the wrapped %v message and server logs for the underlying git or filesystem error
- Verify the plan storage root exists and is writable by the server process (check permissions and free disk space)
- Delete any stale/partial repo directory for the new plan id, then retry CreatePlan (the DB tx rolled back so a retry is safe)
- Confirm 'main' is an acceptable branch name in your git configuration (init.defaultBranch interactions) and that the branches table schema is current
Example fix
// before
_, err = CreateBranch(repo, plan, nil, "main", tx)
if err != nil {
return fmt.Errorf("error creating main branch: %v", err)
}
// after (clean up stale repo dir before retrying creation)
if err := os.RemoveAll(getPlanDir(orgId, plan.Id)); err != nil {
return fmt.Errorf("error cleaning stale plan dir: %w", err)
}
_, err = CreateBranch(repo, plan, nil, "main", tx)
if err != nil {
return fmt.Errorf("error creating main branch: %w", err)
} Defensive patterns
Strategy: validation
Validate before calling
// Go: check the plan storage root is writable and the stale repo doesn't exist before CreatePlan
storageRoot := os.Getenv("PLAN_STORAGE_ROOT")
if fi, err := os.Stat(storageRoot); err != nil || !fi.IsDir() {
return fmt.Errorf("plan storage root %s missing", storageRoot)
}
probe := filepath.Join(storageRoot, ".write-probe")
if err := os.WriteFile(probe, []byte("ok"), 0o600); err != nil {
return fmt.Errorf("plan storage root not writable: %w", err)
}
os.Remove(probe)
if free, err := diskFreeBytes(storageRoot); err == nil && free < 100<<20 {
return fmt.Errorf("insufficient disk space for plan repo")
} Type guard
func storageWritable(root string) bool {
probe := filepath.Join(root, ".probe")
if err := os.WriteFile(probe, []byte("1"), 0o600); err != nil {
return false
}
os.Remove(probe)
return true
} Try / catch
plan, err := db.CreatePlan(ctx, orgId, projectId, userId, name)
if err != nil {
if strings.Contains(err.Error(), "error creating main branch") {
// remove partial repo dir so a retry starts clean
os.RemoveAll(filepath.Join(storageRoot, "plans", planIdHint))
return nil, fmt.Errorf("branch init failed, retry after cleanup: %w", err)
}
return nil, err
} Prevention
- Monitor disk space and permissions on the plan git storage volume
- Run the server under a consistent user with ownership of the storage root
- Clean up stale plan directories from failed creation attempts
- Pin the git configuration (default branch settings) on server hosts
When it happens
Trigger: Calling CreatePlan when the plan's git repo directory cannot be created or is corrupted (bad permissions, full disk), when getGitRepo points at a misconfigured PLANCES/organizational storage root, when the 'main' branch already exists in a leftover repo dir, or when the branches DB insert inside CreateBranch fails.
Common situations: Disk full or read-only filesystem on the server volume that stores plan git data, wrong permissions after running the server under a different user, stale plan directories left by a previously failed creation attempt, or a version change that altered the on-disk repo layout.
Related errors
- error getting git root: %s
- error getting files in git repo: %s
- error invalidating conflicted results: %v
- error storing context: %v
- error committing convo message: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/d017e28a6f8fd262.
Report an issue: GitHub.