**Version:** 2.8.1 (also affects the 2.8.x stats code path)
**Symptom:** the dashboard HWID page fails with "get HWIDs Devices Stats Request failed with status code 500". Panel log:
ERROR [HwidUserDevicesService] Cannot read properties of null (reading ‘startsWith’)
ERROR [HttpExceptionFilter] Get hwid devices stats error - { code: ‘A159’, path: ‘/api/hwid/devices/stats’ }
**Root cause:** in `src/modules/hwid-user-devices/repositories/hwid-user-devices.repository.ts`, the stats query selects `SPLIT_PART("user_agent", '/', 1) AS app`. For rows where `user_agent IS NULL`, `SPLIT_PART` returns `NULL`, so `row.app` is `null`, and the aggregation then calls:
```ts
if (!app.startsWith('https:')) {
which throws TypeError: Cannot read properties of null (reading 'startsWith') → the whole stats endpoint 500s.
Repro:
- Have at least one row in
hwid_user_deviceswithuser_agent IS NULL(e.g. a device registered viaPOST /api/hwid/deviceswithout the optionaluserAgentfield). GET /api/hwid/devices/stats→ 500, error code A159.
Suggested fix: null-guard the aggregation, e.g. const app = row.app ?? 'Unknown'; (or COALESCE("user_agent", 'Unknown') in the SQL). userAgent is optional in the create-device API, so NULL rows are a legal state.
Workaround for anyone hitting this: UPDATE hwid_user_devices SET user_agent = 'Unknown' WHERE user_agent IS NULL;