Skip to content

The agent that grows with you

fix(telemetry): Desktop closes action/setting ids locally and records first-run steps after a yes

teknium1bfa3b84c9f7a
diff --git a/apps/desktop/src/app/contrib/hooks/use-desktop-metrics.ts b/apps/desktop/src/app/contrib/hooks/use-desktop-metrics.ts
index c4c6e03d185..ed264ce2daf 100644
--- a/apps/desktop/src/app/contrib/hooks/use-desktop-metrics.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-desktop-metrics.ts
@@ -127,7 +127,7 @@ export function useDesktopMetrics({
void readSharedMetricsConsent(request).then(consent => {
// An unreadable answer (older backend, flap) keeps the last known gate.
if (!cancelled && consent) {
- setDesktopMetricsGate(gateFor(consent))
+ setDesktopMetricsGate(gateFor(consent), consent.decided)
}
})
@@ -149,7 +149,7 @@ export function useDesktopMetrics({
return $sharedMetricsConsent.listen(consent => {
if (consent) {
- setDesktopMetricsGate(gateFor(consent))
+ setDesktopMetricsGate(gateFor(consent), consent.decided)
}
})
}, [enabled])
diff --git a/apps/desktop/src/app/settings/config-settings.tsx b/apps/desktop/src/app/settings/config-settings.tsx
index b264cc88fce..39f5e643061 100644
--- a/apps/desktop/src/app/settings/config-settings.tsx
+++ b/apps/desktop/src/app/settings/config-settings.tsx
@@ -235,7 +235,7 @@ function ConfigSettingsInner({
writeConfigCache(snapshot)
const savedScope = writeScope ?? scopeProfile
- recordSettingsSaved(patch, typeof savedScope === 'string' ? savedScope : savedScope?.profile)
+ recordSettingsSaved(patch, schema ?? {}, typeof savedScope === 'string' ? savedScope : savedScope?.profile)
if (saveVersionRef.current === v) {
// The repo-discovery scan reads the ACTIVE profile's workspace
diff --git a/apps/desktop/src/store/desktop-metrics.test.ts b/apps/desktop/src/store/desktop-metrics.test.ts
index 916b4b4b064..82acbdbf1a5 100644
--- a/apps/desktop/src/store/desktop-metrics.test.ts
+++ b/apps/desktop/src/store/desktop-metrics.test.ts
@@ -55,6 +55,8 @@ const stored = () => {
return key ? window.localStorage.getItem(key) : null
}
+const SCHEMA = { 'display.show_reasoning': {}, 'display.skin': {} }
+
const methods = (calls: Call[]) => calls.map(([method]) => method)
const flush = () => new Promise(resolve => setTimeout(resolve, 0))
@@ -94,7 +96,7 @@ function exerciseEverything() {
recordAction('composer.send', 'click')
recordAction('composer.send', 'click')
recordDislike('feature_disabled', 'tips')
- recordSettingsSaved({ display: { show_reasoning: false } })
+ recordSettingsSaved({ display: { show_reasoning: false } }, SCHEMA)
recordFeatureToggle('tips', true, false)
trackFlow('command_palette', true)
trackFlow('command_palette', false)
@@ -396,7 +398,11 @@ describe('dislike signals', () => {
setDesktopMetricsGate('on')
bindDesktopMetrics(request)
- recordSettingsSaved({ display: { show_reasoning: false, skin: 'secret-skin-name' } }, 'work')
+ recordSettingsSaved(
+ { display: { show_reasoning: false, skin: 'secret-skin-name' }, providers: { 'acme-internal': { api_key: 'k' } } },
+ SCHEMA,
+ 'work'
+ )
recordFeatureToggle('tips', false, true)
recordFeatureToggle('tips', true, false)
await flush()
@@ -407,6 +413,7 @@ describe('dislike signals', () => {
{ signal: 'feature_disabled', target: 'tips' }
])
expect(JSON.stringify(calls)).not.toContain('secret-skin-name')
+ expect(JSON.stringify(calls)).not.toContain('acme-internal')
expect(configPatchKeys({ a: { b: [1, 2], c: { d: null } } })).toEqual(['a.b', 'a.c.d'])
})
@@ -474,4 +481,50 @@ describe('per profile, per window', () => {
expect(JSON.parse(stored()!).today.actions).toEqual({ 'composer.send|shortcut': 3, 'session.new|shortcut': 1 })
w2.resetDesktopMetricsForTests()
})
+
+ it('never keeps a plugin action id: unknown presses and rage-click targets are `other`', async () => {
+ const { calls, request } = requester()
+
+ setDesktopMetricsGate('on')
+ bindDesktopMetrics(request)
+
+ for (const at of [0, 100, 200]) {
+ recordAction('acme-plugin.secretCommand', 'click', DAY1 + at)
+ }
+
+ await flush()
+ expect(stored()).not.toContain('acme')
+ expect(JSON.parse(stored()!).today.actions).toEqual({ 'other|click': 3 })
+ expect(calls.map(([, p]) => p)).toEqual([{ signal: 'rage_click', target: 'other' }])
+ })
+
+ it('onboarding before the consent answer is held in memory, sent on a yes and dropped on a no', async () => {
+ const { calls, request } = requester()
+
+ bindDesktopMetrics(request)
+ setDesktopMetricsGate('off', false) // first-run offer not answered yet
+ recordOnboarding('intro', 'reached')
+ recordOnboarding('intro', 'completed')
+ recordOnboarding('provider_oauth', 'reached')
+ closeOnboardingStep('provider_oauth')
+ await flush()
+ expect(calls).toEqual([])
+ expect(stored()).toBeNull()
+
+ setDesktopMetricsGate('on')
+ await flush()
+ expect(calls.map(([, p]) => `${p.step}:${p.event}`)).toEqual(['intro:reached', 'intro:completed', 'provider_oauth:reached'])
+ expect(JSON.parse(stored()!).onboarding.open).toEqual({})
+
+ setDesktopMetricsGate('off')
+ resetDesktopMetricsForTests()
+ const later = requester()
+
+ bindDesktopMetrics(later.request)
+ setDesktopMetricsGate('off') // a decided no
+ recordOnboarding('guide', 'reached')
+ setDesktopMetricsGate('on')
+ await flush()
+ expect(later.calls).toEqual([])
+ })
})
diff --git a/apps/desktop/src/store/desktop-metrics.ts b/apps/desktop/src/store/desktop-metrics.ts
index 1a84c319f40..398c433bc0d 100644
--- a/apps/desktop/src/store/desktop-metrics.ts
+++ b/apps/desktop/src/store/desktop-metrics.ts
@@ -12,6 +12,10 @@
* another (connection, profile) forgets the gate until that profile's switch is
* read, so nothing of one profile is ever kept or sent under another's.
*
+ * Before the first-run consent answer, onboarding transitions are held in memory
+ * only (never persisted or sent) and replayed if the user opts in during that
+ * app session; a known "no" drops them.
+ *
* Every value is a code-defined id from the closed sets below (mirrored by
* hermes_cli/observability/shared_metrics_contract.py, which collapses any
* stranger to `other`). Never a session id, path, message, bot name or setting
@@ -28,6 +32,7 @@
import { atom } from 'nanostores'
import { $workspaceMode } from '@/components/pane-shell/workspace-scope'
+import { KEYBIND_ACTION_IDS, KEYBIND_READONLY } from '@/lib/keybinds/actions'
import { readJson, writeJson } from '@/lib/storage'
import type { SharedMetricsRequester } from './shared-metrics'
@@ -271,6 +276,14 @@ export const DESKTOP_BUTTON_ACTIONS = {
export type DesktopActionVia = 'click' | 'menu' | 'palette' | 'shortcut'
+/** Built-in action ids (DESKTOP_ACTION_IDS on the backend); anything else — a plugin's palette
+ * command or keybinding, a numbered slot (`profile.switch.3`) — is `other`. */
+const ACTION_IDS: ReadonlySet<string> = new Set(
+ [...KEYBIND_ACTION_IDS, ...KEYBIND_READONLY.map(action => action.id), ...Object.values(DESKTOP_BUTTON_ACTIONS)].filter(
+ id => !/\.\d+$/.test(id)
+ )
+)
+
export type DesktopDislikeSignal =
| 'cancelled'
| 'feature_disabled'
@@ -320,6 +333,7 @@ const RAGE_CLICK_COUNT = 3
export const ACTIVE_IDLE_GAP_MS = 5 * 60_000
const PENDING_DAYS_MAX = 7
const QUEUE_MAX = 50
+const PRE_CONSENT_MAX = 100
const DROP_SETTLE_MS = 3000
// ── state ─────────────────────────────────────────────────────────────────────
@@ -358,6 +372,8 @@ let scope = scopeKey('|default')
let request: SharedMetricsRequester | null = null
let queue: [string, Record<string, unknown>][] = []
let flushingDays = false
+/** Onboarding transitions before the consent answer (memory only); null once the answer is known. */
+let preConsent: (() => void)[] | null = []
let botCount = 0
let lastInteractionAt = 0
const areaOpenedAt = new Map<string, number>()
@@ -649,10 +665,13 @@ export function configPatchKeys(patch: unknown, prefix = ''): string[] {
)
}
-/** A Settings autosave landed. Only the keys go out; the backend reads the saved
- * values itself and records whether each moved to or away from its default. */
-export function recordSettingsSaved(patch: unknown, profile?: null | string): void {
- for (const key of configPatchKeys(patch).slice(0, MAX_SETTING_KEYS_PER_SAVE)) {
+/** A Settings autosave landed. Only keys the config schema publishes go out (never a key below a
+ * user-named container such as `providers.<name>`); the backend reads the saved values itself and
+ * records whether each moved to or away from its default. */
+export function recordSettingsSaved(patch: unknown, published: Readonly<Record<string, unknown>>, profile?: null | string): void {
+ const keys = configPatchKeys(patch).filter(key => Object.hasOwn(published, key))
+
+ for (const key of keys.slice(0, MAX_SETTING_KEYS_PER_SAVE)) {
recordDislike('setting_off_default', 'setting', key, profile)
}
}
@@ -665,7 +684,9 @@ export function recordFeatureToggle(toggle: DesktopFeatureToggle, wasOn: boolean
}
/** A button/shortcut/palette/menu press, aggregated per day and reported once in the daily report. */
-export function recordAction(action: string, via: DesktopActionVia, now = Date.now()): void {
+export function recordAction(rawAction: string, via: DesktopActionVia, now = Date.now()): void {
+ const action = ACTION_IDS.has(rawAction) ? rawAction : 'other'
+
withState(current => {
const key = `${action}|${via}`
@@ -725,10 +746,27 @@ export function setDesktopBotCount(count: number): void {
})
}
+/** Hold a first-run transition until the consent answer: true when held (or dropped: no is known). */
+function heldForConsent(replay: () => void): boolean {
+ if ($desktopMetricsGate.get() === 'on') {
+ return false
+ }
+
+ if (preConsent && preConsent.length < PRE_CONSENT_MAX) {
+ preConsent.push(replay)
+ }
+
+ return true
+}
+
/** One first-run step transition, once per (step, event) per profile. A step
* reached but not completed is remembered; if it is still open on a later
* load, it was abandoned. */
export function recordOnboarding(step: DesktopOnboardingStep, event: DesktopOnboardingEvent): void {
+ if (heldForConsent(() => recordOnboarding(step, event))) {
+ return
+ }
+
withState(current => {
const open = { ...current.onboarding.open }
@@ -755,6 +793,10 @@ export function recordOnboarding(step: DesktopOnboardingStep, event: DesktopOnbo
/** A step ended without an event of its own (skipped past, cancelled): no
* longer open, so the next launch does not call it abandoned. */
export function closeOnboardingStep(step: DesktopOnboardingStep): void {
+ if (heldForConsent(() => closeOnboardingStep(step))) {
+ return
+ }
+
withState(current => {
const open = { ...current.onboarding.open }
@@ -882,8 +924,13 @@ function forgetInMemory(): void {
cancelPendingBackendDrop()
}
-/** Apply the focused profile's collection switch. Off purges everything local. */
-export function setDesktopMetricsGate(next: DesktopMetricsGate): void {
+/** Apply the focused profile's collection switch. Off purges everything local. `decided` false
+ * (first-run offer unanswered) keeps the pre-consent onboarding transitions for a later yes. */
+export function setDesktopMetricsGate(next: DesktopMetricsGate, decided = true): void {
+ if (next === 'off' && decided) {
+ preConsent = null
+ }
+
if (next === $desktopMetricsGate.get()) {
return
}
@@ -899,8 +946,12 @@ export function setDesktopMetricsGate(next: DesktopMetricsGate): void {
}
if (next === 'on') {
+ const held = preConsent ?? []
+
+ preConsent = null
tellMain(true)
flushDesktopMetrics()
+ held.forEach(replay => replay())
}
}
@@ -913,6 +964,7 @@ export function bindDesktopMetrics(next: SharedMetricsRequester | null, profileS
if (nextScope !== scope) {
forgetInMemory()
scope = nextScope
+ preConsent = []
$desktopMetricsGate.set(null)
}
@@ -929,6 +981,7 @@ export function tickDesktopMetrics(now = Date.now()): void {
/** Test-only: forget in-memory state (localStorage is the test's to clear). */
export function resetDesktopMetricsForTests(): void {
scope = scopeKey('|default')
+ preConsent = []
request = null
queue = []
flushingDays = false
diff --git a/hermes_cli/observability/shared_metrics_desktop.py b/hermes_cli/observability/shared_metrics_desktop.py
index a5ab6d32ca8..6c0683f5705 100644
--- a/hermes_cli/observability/shared_metrics_desktop.py
+++ b/hermes_cli/observability/shared_metrics_desktop.py
@@ -31,7 +31,8 @@ logger = logging.getLogger(__name__)
# up as "a lot", but cannot flood the store.
FRICTION_DAILY_CAP = 50
ONBOARDING_LATCH_DIRNAME = "desktop_onboarding"
-DAILY_ACTION_ROWS_MAX = 200
+# Room for every distinct (action, via) the renderer can send once it collapses unknown ids to `other`.
+DAILY_ACTION_ROWS_MAX = len(contract.DESKTOP_ACTION_IDS) * len(contract.DESKTOP_ACTION_VIAS)
DAILY_REPORT_STATE_KEY = "desktop_daily_reported"
# The renderer holds a finished day for at most 7 days; anything older (or in the future) is settled
# unrecorded, which keeps the durable per-day latch bounded.
diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.md
index 5b0fda43faf..d3d2447d7cb 100644
--- a/website/docs/developer-guide/relay-shared-metrics.md
+++ b/website/docs/developer-guide/relay-shared-metrics.md
@@ -342,11 +342,11 @@ session/bot/profile names, paths and setting values never leave.
| Metric | Dimensions | Question it answers |
|---|---|---|
| `hermes.desktop.feature_use` | area (panes, command palette, model/session pickers, voice, Bot Mode, skins, projects, each settings page, full pages, `other`) | Which Desktop areas are used at all, counted at most once per area per UTC day per profile (latched in the profile's local database, so a second window or a backend restart never re-counts). |
-| `hermes.desktop.action_use` | action (the app's command/keybinding ids plus a few named buttons, else `other`), via (`click`/`shortcut`/`palette`/`menu`), count bucket | Which buttons and commands people press, and how: aggregated in the app per profile and reported once per finished day (no per-press rows). The row lands in the period of the day it describes, not the day it was sent; each day is recorded once per profile however many windows or backend restarts report it, and a day older than 8 days is dropped. |
+| `hermes.desktop.action_use` | action (the app's built-in command/keybinding ids plus a few named buttons; plugin commands and numbered slot shortcuts are `other`, collapsed in the app before anything is kept), via (`click`/`shortcut`/`palette`/`menu`), count bucket | Which buttons and commands people press, and how: aggregated in the app per profile and reported once per finished day (no per-press rows). The row lands in the period of the day it describes, not the day it was sent; each day is recorded once per profile however many windows or backend restarts report it, and a day older than 8 days is dropped. |
| `hermes.desktop.mode_use` | mode (`sessions`/`bots`), active-minutes bucket, messages-sent bucket, bot-count bucket | How Desktop time splits between Bot Mode and regular Sessions. One row per mode used that day, in that day's period (same once-per-profile-per-day latch as `action_use`); active time sums gaps between interactions of up to 5 minutes. |
| `hermes.desktop.friction` | kind (`notice_dismissed`, `error_toast`, `renderer_crash`, `backend_disconnect`, `slow_frame`), detail (notice id, error category, crash reason, drop reason, frame-duration bucket) | What gets in the way. Error toasts carry only their code-defined category; renderer crashes are recorded by the app shell only when the crashed window's own profile collects, and reported by a window of that profile after it comes back; slow frames are long frames while the window is visible, capped per day. |
| `hermes.desktop.dislike` | signal (`quick_close`, `cancelled`, `setting_off_default`, `rage_click`, `undo`, `feature_disabled`), target, setting, direction | Signals that a feature is unwanted: a pane closed within 5s of opening, a dialog/flow backed out of, a setting moved to or away from its default (the key only; the backend compares the saved value to the default itself), three clicks on one control within a second, an undo, a shipped feature switched off. Capped per signal per day. |
-| `hermes.desktop.onboarding` | step (first-run steps: provider picker, sign-in, API key, local endpoint, model pick, choose later, free-tier screen, guided setup cards, consent, first message), event (`reached`/`completed`/`abandoned`) | Where first run stops. Each step event once per profile (latched in a small per-profile file); `abandoned` is a step still open when the app next starts. Switching collection off in the Desktop deletes those latches with the app's own copy. |
+| `hermes.desktop.onboarding` | step (first-run steps: provider picker, sign-in, API key, local endpoint, model pick, choose later, free-tier screen, guided setup cards, consent, first message), event (`reached`/`completed`/`abandoned`) | Where first run stops. Each step event once per profile (latched in a small per-profile file); `abandoned` is a step still open when the app next starts. First run happens before the consent question, so until it is answered the app holds the step events in memory only (never on disk, never sent) and records them if the user opts in during that app session; a "no" or quitting first discards them. Switching collection off in the Desktop deletes those latches with the app's own copy. |
Sessions are summarized when they close (finalize, reset or process exit);
delegated child sessions are not counted separately. Milestones latch in the