Files
hermes-agent/apps/desktop/scripts/perf
ghgoodreau f125187d6e feat(desktop): escalating profile-switch indicator with retryable failure
Replace the modal ChatSwapOverlay (absolute inset-0 z-50, aria-hidden) and
the separate ChatSyncBadge with one ChatSwitchIndicator, mounted in flow at
the top of the primary chat column so it never covers the transcript:

- 0-2 s: nothing (a fast switch must not flash chrome).
- 2-10 s: quiet corner pill "Switching to <agent>…", tinted with the target's
  profile colour (resolveProfileColor/profileColorSoft; neutral for default),
  shadow-nous + --stroke-nous, pointer-transparent.
- 10 s+: inline strip above the thread: "Still connecting. Messages you send
  now will wait and go to this agent."
- Paint-first hydration sync (#89843) renders as the same quiet pill.
- A rejected rail switch ends in a terminal failure strip (canonical
  ErrorIcon, Retry, dismiss). No spinner runs in that state.
Root is aria-live="polite"; the status is never aria-hidden. Exposes
data-switch-state (idle|pending|slow|stalled|syncing|failed) as the
deterministic readiness contract.

Failure state: a feature-owned nanostore (store/profile-switch-state.ts)
tracks the in-flight rail pick and the last failed one. selectProfile and
newSessionInProfile route through runRailSwitch. On rejection it sets the
failure, with a retry that re-runs only the activation (no second fresh
draft), and still shows the existing toast / remote-override reauth notice
(#91349). A generation guard stops a superseded attempt from clearing a
newer spinner or resurrecting a failure. The failure is cleared by the next
swap ($gatewaySwapTarget set), the next pick, success, or dismiss.
$gatewaySwapTarget keeps its behaviour (transcript suppression,
goneSessionVerdict, tile calm); only its presentation changed.

Rail: local named-profile squares and the home pill get the same pending
treatment (aria-busy + spinner) that rest squares already had. Squares also
get a failed mark (ErrorIcon plus the reason in the aria-label and tooltip).
Composer: a "Will send to <agent>" pill sits in the floating strip while a
switch is pending. Send semantics are unchanged: a send waits on
ensureGatewayProfile and lands on the target.

Paint-first option taken: today's clear is KEPT (option B). Keeping the
previous transcript painted until activation is not safe. The painted
transcript keeps its bound runtime (activeSessionId), so a send during the
swap would submit/steer the PREVIOUS profile's session on the previous
socket instead of creating one on the target. That breaks "send lands on
target" (#79005/#81094). The fresh draft also has to resolve its cwd off the
foreign project scope before the swap (#54990), and a re-homed project tree
would publish the outgoing profile's context. Instead, the target's identity
paints at once: the composer's send-target pill shows on the click frame, and
the rail square goes busy. The indicator escalates from there. No modal ever
covers content.

Perf: scripts/perf/scenarios/profile-switch.mjs no longer reads overlay
text. Removing that text would have made it silently report about 100 ms.
It now settles on data-switch-state leaving pending/slow/stalled AND the
clicked square's aria-busy clearing, and reports failed separately from a
timeout. e2e bot-screen-stale-status-reply waits on the same attribute.

i18n: composer.wakingProfile removed; composer.switchingProfile,
switchingProfileSlow, switchProfileFailed and willSendTo added in en, de,
es, fr, ja, ru, zh, ar, zh-hant. locales/_keys.desktop.json regenerated.
desktop.hydrationSyncing is still used, and its ru gap is still listed.
DESIGN.md documents the switch-indicator contract.
2026-11-20 14:42:54 -06:00
..
…
…

Desktop perf harness

One systematized way to measure desktop rendering/interaction performance, diff it against a committed baseline, and fail on regressions. It replaces the dozen one-off measure-* / profile-* scripts that each reinvented the CDP client, arg parsing, stats, and output (and never had a baseline).

Quick start

# Isolated instance (recommended) — no running app or LLM credits needed.
# Its own --user-data-dir + HERMES_HOME means it never collides with `hgui`.
pnpm run perf --spawn

# Or: launch an isolated instance once, attach repeatedly (faster iteration).
pnpm run perf:serve            # leaves an instance on :9222
pnpm run perf                  # attaches, runs the CI suite, gates on baseline

# One scenario, with a CPU profile:
pnpm run perf stream --cpuprofile --tokens 800

# Representative PRODUCTION numbers (minified React, not the ~3x-slower dev build):
pnpm run perf cold-start stream keystroke transcript --spawn --prod

# Re-capture the baseline on your reference device, then commit baseline.json:
pnpm run perf cold-start stream keystroke transcript --spawn --prod --update-baseline

Profiling an existing workspace

node scripts/perf/run.mjs live-window --seconds 15 --json ~/.hermes/cache/scratch/live-window.json
# Attribution is a separate pass, not an FPS comparison:
node scripts/perf/run.mjs live-window --seconds 10 --cpuprofile ~/.hermes/cache/scratch

live-window never opens/closes tabs, seeds messages, moves focus, or forces GC. It records frame intervals, long tasks, visible/mounted transcript counts, and heap/DOM counters. Keep the same panes and workload for before/after captures. Record restarts, HMR, and code updates separately: a fresh renderer is not a valid after measurement for a long-running renderer. Heap counters alone do not prove a leak. Heavy render/atom counters must be stopped before timing.

Dev vs prod

By default the harness measures the dev renderer (fast to spin up, good for relative regression checks). Pass --prod (with --spawn) to build a production renderer with the probe included (VITE_PERF_PROBE=1) and measure minified React — the representative shipped numbers. The committed baseline is captured with --prod.

Why isolation matters

The measurement this harness exists to run was historically blocked: a running hgui holds the Electron single-instance lock, so a second instance quit immediately. --spawn / perf:serve launch with their own --user-data-dir (separate lock scope), their own HERMES_HOME (separate backend + sessions), and their own --remote-debugging-port. Synthetic scenarios drive $messages directly via window.__PERF_DRIVE__, so no LLM credits are spent.

The isolated home is seeded from ~/.hermes (config.yaml, .env, auth.json) so it skips onboarding, with every messaging platform written back as enabled: false in canonical and overriding shorthand blocks (lib/seed-home.mjs), without changing unrelated YAML scalar values. Its gateway must never open a second Telegram/Discord/iMessage connection: a platform sidecar on a fixed port would reap the live gateway's and steal inbound messages. The first Electron spawn uses Desktop's normal display selector, including NVIDIA, X11 overrides and forwarded displays, so a platform-selection relaunch cannot contend for the CDP port.

Scenarios

scenario tier measures replaces
stream ci streaming longtasks, frame p95/p99, mutation cadence measure-synthetic-stream, profile-synth-stream, profile-long-stream
stream --real backend same, from a real LLM stream measure-real-stream, profile-real-stream
keystroke ci composer keystroke → paint latency measure-latency, profile-typing, leak-typing
transcript ci large-transcript mount + paint cost (new)
render-churn ci per-component render attribution + store churn while N tabs stream (new)
idle-cost report busy-but-silent tiles: idle commit rate, + fps while resizing / typing (new)
right-pane report file tree + persistent xterm tabs under chat/terminal output and split dragging (new)
cold-start cold launch → CDP → driver → first paint (fresh spawn/run) (new)
first-token backend Enter → first assistant token painted (TTFT) (new)
submit backend Enter → cleared → user msg painted, scroll jump measure-submit, measure-jump
session-switch backend route → first-paint → settle profile-session-switch
session-load backend how far a session's transcript moves after first paint (new)
profile-switch backend rail click → sidebar settled measure-profile-switch

ci + cold scenarios need no backend/credits and are gated against baseline.json (cold-start requires --spawn since it measures a fresh launch, and must be run in its own invocation). backend scenarios need a live backend (and --spawn or a real session/credits) and are report-only.

CPU profiling is a cross-cutting --cpuprofile flag on any scenario (it wraps the run in Profiler.start/stop and prints a top-self-time table), replacing every standalone profile-* script.

Adding a scenario

Create scenarios/<name>.mjs exporting { name, tier, description, run(cdp, opts) } where run returns { metrics, detail } (metrics = flat numbers, lower is better), then register it in scenarios/index.mjs. If it's ci, add a baseline.json entry (or run --update-baseline).

Layout

  • lib/cdp.mjs — the one CDP client + target discovery + typing + CPU-profile wrapper + DOM selectors.
  • lib/stats.mjs — percentiles, histograms, CPU-profile self-time ranking.
  • lib/baseline.mjs — load/compare/update the baseline + regression gate.
  • lib/launch.mjs — attach, or spawn a fully isolated instance.
  • scenarios/ — one module per measurement.
  • run.mjs — entrypoint. serve.mjs — standalone isolated launcher.

Not migrated (kept as dev utilities)

eval.mjs, reload.mjs, reload-renderer.mjs, probe-renderer.mjs, probe-thread.mjs, click-session.mjs, diag-*.mjs are interactive dev helpers, not benchmarks. They can adopt lib/cdp.mjs in a follow-up.