{"record":{"id":"34b422b35725a581","repo":"plandex-ai/plandex","slug":"error-getting-plan-modelcontext-v","errorCode":null,"errorMessage":"error getting plan modelContext: %v","messagePattern":"error getting plan modelContext: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/model/plan/build_load.go","lineNumber":53,"sourceCode":"\tvar orgUserConfig *shared.OrgUserConfig\n\n\terr = db.ExecRepoOperation(db.ExecRepoOperationParams{\n\t\tOrgId:    auth.OrgId,\n\t\tUserId:   auth.User.Id,\n\t\tPlanId:   plan.Id,\n\t\tBranch:   branch,\n\t\tScope:    db.LockScopeRead,\n\t\tCtx:      active.Ctx,\n\t\tCancelFn: active.CancelFn,\n\t\tReason:   \"load pending builds\",\n\t}, func(repo *db.GitRepo) error {\n\t\terrCh := make(chan error, 4)\n\n\t\tgo func() {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tlog.Printf(\"panic in getPlanContexts: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\terrCh <- fmt.Errorf(\"error getting plan modelContext: %v\", r)\n\t\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t\t}\n\t\t\t}()\n\t\t\tres, err := db.GetPlanContexts(auth.OrgId, plan.Id, true, false)\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"Error getting plan modelContext: %v\\n\", err)\n\t\t\t\terrCh <- fmt.Errorf(\"error getting plan modelContext: %v\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tmodelContext = res\n\n\t\t\terrCh <- nil\n\t\t}()\n\n\t\tgo func() {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tlog.Printf(\"panic in getPlanSettings: %v\\n%s\", r, debug.Stack())","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/model/plan/build_load.go#L35-L71","documentation":"During loadPendingBuilds, Plandex fetches plan contexts (including the plan modelContext) in a background goroutine inside a repo read lock. If db.GetPlanContexts returns an error, or the goroutine panics, the failure is formatted as \"error getting plan modelContext: %v\" and sent to errCh, aborting the load. A panic-origin message (via the recover block) indicates a runtime crash inside the context fetch; otherwise it's the raw database error.","triggerScenarios":"db.GetPlanContexts(auth.OrgId, plan.Id, true, false) failing — DB connection error, missing/corrupt context rows for the plan, or a panic inside the goroutine caught by the recover() in build_load.go:50-55.","commonSituations":"Postgres unavailable or connection pool exhausted at plan load time; a nil-pointer panic in the context-loading code path (check for the \"panic in getPlanContexts\" log with a stack trace); org/plan IDs inconsistent after a failed migration or manual DB edit; network partition between server and database.","solutions":["Check the server log for the companion line \"Error getting plan modelContext: ...\" or \"panic in getPlanContexts\" with its stack trace to separate DB errors from panics","Verify database connectivity and that the plan's context rows exist and are uncorrupted","If a panic occurred, use the printed debug.Stack() to identify and fix the offending code or report it upstream","Retry the plan load if the DB error was transient (restart, failover, network blip)","Confirm org/plan IDs are valid and consistent — manual DB modifications or failed migrations can leave contexts unreadable"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before loading pending builds, confirm plan/org exist and DB is reachable\nif _, err := db.GetPlan(auth.OrgId, plan.Id); err != nil {\n\treturn fmt.Errorf(\"plan not loadable before pending-build fetch: %v\", err)\n}\nif err := db.Ping(); err != nil {\n\treturn fmt.Errorf(\"database unreachable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"// collect the error from errCh (buffered, 4 slots) and inspect\nerr := <-errCh\nif err != nil {\n\tif strings.Contains(err.Error(), \"panic\") || strings.Contains(err.Error(), \"runtime error\") {\n\t\tlog.Printf(\"panic-driven context load failure: %v\", err) // stack is in server logs\n\t} else {\n\t\tlog.Printf(\"db failure loading plan context: %v\", err) // retry on transient errors\n\t}\n\treturn err\n}","preventionTips":["Monitor database connectivity from the server before and during plan operations","Keep the panic-recover logging (debug.Stack) enabled so panics in these goroutines are diagnosable","Don't hand-edit plan/context rows in the DB; use migrations only","Add health checks that exercise db.GetPlanContexts so corruption is caught early"],"tags":["plandex","server","database","panic-recovery","plan-context"],"backgroundTag":"plan-context-load-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"}