Skip to content

The agent that grows with you

fix(tui): dashboard Chat-tab TUIs never report startup latency

teknium1f5e0a521f46a
diff --git a/ui-tui/src/__tests__/startupLatencyDashboard.test.ts b/ui-tui/src/__tests__/startupLatencyDashboard.test.ts
new file mode 100644
index 00000000000..26b704dcd62
--- /dev/null
+++ b/ui-tui/src/__tests__/startupLatencyDashboard.test.ts
@@ -0,0 +1,41 @@
+import { describe, expect, it, vi } from 'vitest'
+
+import { createGatewayEventHandler } from '../app/createGatewayEventHandler.js'
+import type * as EnvModule from '../config/env.js'
+
+// Its own file: the launch latch is module state, so a dashboard TUI must be the first reporter
+// this module ever sees for the test to prove anything. DASHBOARD_TUI_MODE resolves at module
+// load from HERMES_TUI_DASHBOARD, so the export itself is mocked.
+vi.mock('../config/env.js', async importActual => ({
+ ...(await importActual<typeof EnvModule>()),
+ DASHBOARD_TUI_MODE: true
+}))
+
+const ref = <T>(current: T) => ({ current })
+
+describe('startup latency in a dashboard-embedded TUI', () => {
+ it('never reports: each Chat-tab terminal spawns a TUI, which is not a Hermes launch', () => {
+ const request = vi.fn(async () => ({ ok: true }))
+
+ const ctx = {
+ composer: { dequeue: () => undefined, queueEditRef: ref(null), sendQueued: vi.fn(), setInput: vi.fn() },
+ gateway: { gw: { request }, rpc: vi.fn(async () => null) },
+ session: {
+ STARTUP_RESUME_ID: '',
+ colsRef: ref(80),
+ newSession: vi.fn(),
+ resetSession: vi.fn(),
+ resumeById: vi.fn(),
+ setCatalog: vi.fn()
+ },
+ submission: { submitRef: { current: vi.fn() } },
+ system: { bellOnComplete: false, sys: vi.fn() },
+ transcript: { appendMessage: vi.fn(), panel: vi.fn(), setHistoryItems: vi.fn() },
+ voice: { setProcessing: vi.fn(), setRecording: vi.fn(), setVoiceEnabled: vi.fn() }
+ } as any
+
+ createGatewayEventHandler(ctx)({ payload: {}, type: 'gateway.ready' } as any)
+
+ expect(request.mock.calls.filter(([method]) => method === 'shared_metrics.startup_latency')).toEqual([])
+ })
+})
diff --git a/ui-tui/src/app/startupLatency.ts b/ui-tui/src/app/startupLatency.ts
index 74709480a4d..8dca2d728b3 100644
--- a/ui-tui/src/app/startupLatency.ts
+++ b/ui-tui/src/app/startupLatency.ts
@@ -1,3 +1,4 @@
+import { DASHBOARD_TUI_MODE } from '../config/env.js'
import type { GatewayClient } from '../gatewayClient.js'
// Module-level so a gateway reconnect/respawn (a fresh gateway.ready, or a remounted
@@ -6,9 +7,11 @@ let reported = false
/** Node process start is the earliest moment the TUI owns, so uptime at the first
* gateway.ready is the launch latency. The backend buckets it and drops it unless the
- * user opted in; older backends lack the method, so errors are swallowed. */
+ * user opted in; older backends lack the method, so errors are swallowed.
+ * A dashboard Chat tab spawns a TUI per terminal it opens: that is a tab opening, not a
+ * user launching Hermes, so it stays out of the startup distribution. */
export function reportStartupLatency(gw: Pick<GatewayClient, 'request'>): void {
- if (reported) {
+ if (reported || DASHBOARD_TUI_MODE) {
return
}
@@ -16,7 +19,5 @@ export function reportStartupLatency(gw: Pick<GatewayClient, 'request'>): void {
gw.request('shared_metrics.startup_latency', {
elapsed_ms: Math.round(process.uptime() * 1000),
surface: 'tui'
- }).catch(
- () => undefined
- )
+ }).catch(() => undefined)
}