🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(device): degrade a failed health-metrics read to an empty chart (#20475)
Arvin Xua9106395dd80
diff --git a/apps/server/src/services/deviceGateway/__tests__/index.test.ts b/apps/server/src/services/deviceGateway/__tests__/index.test.tsindex 5e922a9a752..765089aa20a 100644--- a/apps/server/src/services/deviceGateway/__tests__/index.test.ts+++ b/apps/server/src/services/deviceGateway/__tests__/index.test.ts@@ -13,6 +13,7 @@ const mockClient = vi.hoisted(() => ({executeMcpCall: vi.fn(),executeMessageApi: vi.fn(),executeToolCall: vi.fn(),+ getDeviceMetrics: vi.fn(),getDeviceSystemInfo: vi.fn(),invokeRpc: vi.fn(),queryDeviceList: vi.fn(),@@ -364,6 +365,44 @@ describe('DeviceGateway', () => {});});+ describe('queryDeviceMetrics', () => {+ const params = { deviceId: 'dev-1', since: 1000, userId: 'user-1', workspaceId: 'ws-1' };+ const configure = () => {+ mockEnv.DEVICE_GATEWAY_URL = 'https://gateway.example.com';+ mockEnv.DEVICE_GATEWAY_SERVICE_TOKEN = 'token';+ };++ it('returns the gateway samples', async () => {+ configure();+ const samples = [{ observedAt: 2000 }];+ mockClient.getDeviceMetrics.mockResolvedValue(samples);++ await expect(new DeviceGateway().queryDeviceMetrics(params)).resolves.toEqual(samples);+ expect(mockClient.getDeviceMetrics).toHaveBeenCalledWith('user-1', 'dev-1', {+ since: 1000,+ workspaceId: 'ws-1',+ });+ });++ it('degrades to no samples when the gateway read fails', async () => {+ configure();+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});+ mockClient.getDeviceMetrics.mockRejectedValue(+ new Error('device metrics read failed: HTTP 500'),+ );++ await expect(new DeviceGateway().queryDeviceMetrics(params)).resolves.toEqual([]);+ expect(warn).toHaveBeenCalledWith(+ expect.stringContaining('device metrics read failed'),+ expect.objectContaining({+ deviceId: 'dev-1',+ error: 'device metrics read failed: HTTP 500',+ }),+ );+ warn.mockRestore();+ });+ });+describe('executeToolCall', () => {const params = { deviceId: 'dev-1', userId: 'user-1' };const toolCall = { apiName: 'listFiles', arguments: '{}', identifier: 'file-manager' };diff --git a/apps/server/src/services/deviceGateway/index.ts b/apps/server/src/services/deviceGateway/index.tsindex 37dfea9324d..6f37f911ea6 100644--- a/apps/server/src/services/deviceGateway/index.ts+++ b/apps/server/src/services/deviceGateway/index.ts@@ -262,6 +262,10 @@ export class DeviceGateway {* The device's health samples held by the gateway (two days), observed at or* after `since`. Unlike the RPC reads this works while the device is* offline — the samples live in gateway storage, not on the device.+ *+ * A failed read degrades to no samples: the chart is a polled side panel,+ * and surfacing a gateway blip as a 500 only turns each poll (and its SWR+ * retries) into an error log. The next poll picks the history back up.*/async queryDeviceMetrics(params: {deviceId: string;@@ -271,10 +275,20 @@ export class DeviceGateway {}): Promise<DeviceMetricSample[]> {const client = this.getClient();if (!client) return [];- return client.getDeviceMetrics(params.userId, params.deviceId, {- since: params.since,- workspaceId: params.workspaceId,- });+ try {+ return await client.getDeviceMetrics(params.userId, params.deviceId, {+ since: params.since,+ workspaceId: params.workspaceId,+ });+ } catch (error) {+ console.warn('[DeviceGateway] device metrics read failed; returning no samples', {+ deviceId: params.deviceId,+ error: error instanceof Error ? error.message : String(error),+ userId: params.userId,+ workspaceId: params.workspaceId,+ });+ return [];+ }}/**