{"record":{"id":"b9ba045bd9a70146","repo":"Wei-Shaw/sub2api","slug":"failed-to-get-group-statistics","errorCode":null,"errorMessage":"failed to get group statistics","messagePattern":"failed to get group statistics","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"backend/internal/handler/admin/dashboard_snapshot_v2_handler.go","lineNumber":234,"sourceCode":"\t\tresp.Models = models\n\t}\n\n\tif includeGroups {\n\t\tgroups, _, err := h.getGroupStatsCached(\n\t\t\tctx,\n\t\t\tstartTime,\n\t\t\tendTime,\n\t\t\tfilters.UserID,\n\t\t\tfilters.APIKeyID,\n\t\t\tfilters.AccountID,\n\t\t\tfilters.GroupID,\n\t\t\tfilters.RequestType,\n\t\t\tfilters.Stream,\n\t\t\tfilters.BillingType,\n\t\t\tfilters.UpstreamModelMismatch,\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"failed to get group statistics\")\n\t\t}\n\t\tresp.Groups = groups\n\t}\n\n\tif includeUsersTrend {\n\t\tusersTrend, _, err := h.getUserUsageTrendCached(ctx, startTime, endTime, granularity, usersTrendLimit)\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"failed to get user usage trend\")\n\t\t}\n\t\tresp.UsersTrend = usersTrend\n\t}\n\n\treturn resp, nil\n}\n\nfunc parseDashboardSnapshotV2Filters(c *gin.Context) (*dashboardSnapshotV2Filters, error) {\n\tfilters := &dashboardSnapshotV2Filters{\n\t\tModel: strings.TrimSpace(c.Query(\"model\")),","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/Wei-Shaw/sub2api/blob/073e92d17178a1ccdb0a27017f572f10c9c7ab62/backend/internal/handler/admin/dashboard_snapshot_v2_handler.go#L216-L252","documentation":"Returned while assembling the v2 dashboard snapshot when includeGroups is true and h.getGroupStatsCached(...) fails. The group statistics aggregation over the window failed; the specific cause is lost because only the generic message is returned. Infrastructure-side failure.","triggerScenarios":"GET dashboard snapshot v2 with the groups section included while the group-stats query fails (DB outage, timeout, lock contention).","commonSituations":"Instances with very many groups making the aggregation large; concurrent snapshot requests; DB resource limits.","solutions":["Retry after a short backoff","Reduce the date range or apply user/key filters to shrink the aggregation","Check backend logs for the underlying group-stats error","Request the snapshot without the groups section as a workaround"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// TS\nlet groups;\ntry { groups = (await getSnapshotV2({ includeGroups: true, start, end })).groups; }\ncatch (e) {\n  if (e.message === 'failed to get group statistics') {\n    groups = (await withBackoff(() => getSnapshotV2({ includeGroups: true, start, end }))).groups;\n  } else throw e;\n}","preventionTips":["Retry group-stats snapshot failures with backoff","Keep group counts manageable and filter by user/key where possible","Fetch sections independently so one failure does not kill the whole dashboard"],"tags":["dashboard","group-stats","database","admin"],"backgroundTag":null,"analyzedSha":"073e92d17178a1ccdb0a27017f572f10c9c7ab62","analyzedAt":"2026-08-15T14:33:00.750Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}