{"record":{"id":"d017e28a6f8fd262","repo":"plandex-ai/plandex","slug":"error-creating-main-branch-v","errorCode":null,"errorMessage":"error creating main branch: %v","messagePattern":"error creating main branch: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/plan_helpers.go","lineNumber":74,"sourceCode":"\t\t)\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error creating plan: %v\", err)\n\t\t}\n\n\t\t_, err = tx.Exec(\"INSERT INTO lockable_plan_ids (plan_id) VALUES ($1)\", plan.Id)\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error inserting lockable plan id: %v\", err)\n\t\t}\n\n\t\t// the one place where we do this to skip the locking queue\n\t\t// ok to cheat this once since we're creating a new plan\n\t\trepo := getGitRepo(orgId, plan.Id)\n\t\t_, err = CreateBranch(repo, plan, nil, \"main\", tx)\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error creating main branch: %v\", err)\n\t\t}\n\n\t\tlog.Println(\"Created branch main\")\n\n\t\terr = InitPlan(orgId, plan.Id)\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error initializing plan dir: %v\", err)\n\t\t}\n\n\t\tlog.Println(\"Initialized plan dir\")\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/plan_helpers.go#L56-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n_, err = CreateBranch(repo, plan, nil, \"main\", tx)\nif err != nil {\n    return fmt.Errorf(\"error creating main branch: %v\", err)\n}\n// after (clean up stale repo dir before retrying creation)\nif err := os.RemoveAll(getPlanDir(orgId, plan.Id)); err != nil {\n    return fmt.Errorf(\"error cleaning stale plan dir: %w\", err)\n}\n_, err = CreateBranch(repo, plan, nil, \"main\", tx)\nif err != nil {\n    return fmt.Errorf(\"error creating main branch: %w\", err)\n}","handlingStrategy":"validation","validationCode":"// Go: check the plan storage root is writable and the stale repo doesn't exist before CreatePlan\nstorageRoot := os.Getenv(\"PLAN_STORAGE_ROOT\")\nif fi, err := os.Stat(storageRoot); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"plan storage root %s missing\", storageRoot)\n}\nprobe := filepath.Join(storageRoot, \".write-probe\")\nif err := os.WriteFile(probe, []byte(\"ok\"), 0o600); err != nil {\n    return fmt.Errorf(\"plan storage root not writable: %w\", err)\n}\nos.Remove(probe)\nif free, err := diskFreeBytes(storageRoot); err == nil && free < 100<<20 {\n    return fmt.Errorf(\"insufficient disk space for plan repo\")\n}","typeGuard":"func storageWritable(root string) bool {\n    probe := filepath.Join(root, \".probe\")\n    if err := os.WriteFile(probe, []byte(\"1\"), 0o600); err != nil {\n        return false\n    }\n    os.Remove(probe)\n    return true\n}","tryCatchPattern":"plan, err := db.CreatePlan(ctx, orgId, projectId, userId, name)\nif err != nil {\n    if strings.Contains(err.Error(), \"error creating main branch\") {\n        // remove partial repo dir so a retry starts clean\n        os.RemoveAll(filepath.Join(storageRoot, \"plans\", planIdHint))\n        return nil, fmt.Errorf(\"branch init failed, retry after cleanup: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["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"],"tags":["git","filesystem","database","plan-creation"],"backgroundTag":"git-branch-creation-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}