{"record":{"id":"4b74306485e18e29","repo":"plandex-ai/plandex","slug":"error-getting-contexts-v-4b7430","errorCode":null,"errorMessage":"error getting contexts: %v","messagePattern":"error getting contexts: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_context.go","lineNumber":386,"sourceCode":"\tremoveTokens := 0\n\tvar toRemoveApiContexts []*shared.Context\n\n\terr = db.ExecRepoOperation(db.ExecRepoOperationParams{\n\t\tOrgId:          auth.OrgId,\n\t\tUserId:         auth.User.Id,\n\t\tPlanId:         planId,\n\t\tBranch:         branchName,\n\t\tReason:         \"delete contexts\",\n\t\tScope:          db.LockScopeWrite,\n\t\tCtx:            ctx,\n\t\tCancelFn:       cancel,\n\t\tClearRepoOnErr: true,\n\t}, func(repo *db.GitRepo) error {\n\t\tvar err error\n\t\tdbContexts, err = db.GetPlanContexts(auth.OrgId, planId, false, false)\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error getting contexts: %v\", err)\n\t\t}\n\n\t\tfor _, dbContext := range dbContexts {\n\t\t\tif _, ok := requestBody.Ids[dbContext.Id]; ok {\n\t\t\t\ttoRemove = append(toRemove, dbContext)\n\t\t\t}\n\t\t}\n\n\t\terr = db.ContextRemove(auth.OrgId, planId, toRemove)\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error removing contexts: %v\", err)\n\t\t}\n\n\t\tfor _, dbContext := range toRemove {\n\t\t\ttoRemoveApiContexts = append(toRemoveApiContexts, dbContext.ToApi())\n\t\t\tremoveTokens += dbContext.NumTokens\n\t\t}","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_context.go#L368-L404","documentation":"Returned by DeleteContextHandler when db.GetPlanContexts(auth.OrgId, planId, false, false) fails at the start of the delete-contexts repo operation. The list of existing contexts could not be loaded, so the handler cannot determine which requested IDs exist; the wrapped %v carries the underlying DB error and the client receives HTTP 500 'Error deleting contexts'.","triggerScenarios":"Calling the delete-context endpoint when the contexts query fails: DB unreachable, plan has no contexts table entry / query error, or org-scoped query error for the planId.","commonSituations":"DB outage or connection-pool exhaustion; plan deleted concurrently; schema migration in progress; orgId/planId mismatch after auth changes.","solutions":["Check the wrapped DB error in the server logs","Verify DB connectivity and that the plan/org rows are intact","Confirm the planId in the URL belongs to the authenticated org","Retry after transient DB failures"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if planId == \"\" || orgId == \"\" {\n    return errors.New(\"orgId and planId are required to list plan contexts\")\n}\nif err := db.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"database unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"dbContexts, err = db.GetPlanContexts(auth.OrgId, planId, false, false)\nif err != nil {\n    return fmt.Errorf(\"error getting contexts: %w\", err)\n}\n// caller: retry with backoff on transient DB errors before returning 500\nif err != nil {\n    http.Error(w, \"contexts temporarily unavailable\", http.StatusServiceUnavailable)\n    return\n}","preventionTips":["Verify plan/org rows exist before delete operations","Add DB health checks and retry transient errors with backoff","Watch for plans deleted concurrently during context operations"],"tags":["go","database","http-500"],"backgroundTag":"plan-state-load-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}