Skip to content

perf(diagnostics): default-off and off-thread the always-on diagnostic subsystems #767

Description

@Juliusolsson05

Symptom

The daily-driver dev profile runs every optional diagnostic at once (.env: AGENT_CODE_PERF=1, AGENT_CODE_DEV_DEBUG=1, AGENT_CODE_SESSION_RECORD=1; settings useProxyStreaming, aggressiveDebugPersistence), and several diagnostics have no gate at all:

  • feed-debug ring + persistence: no gate, on in packaged builds; 167–172 appends/min (20/s bursts), max 731 ms on main; 4 MiB ring × 39 sessions ≈ up to 156 MB renderer heap; 89 MB on disk (perf(feed-debug): persistence appends on every runtimes replacement instead of batching by time #748/perf(feed-debug): pace persistence appends by time instead of per runtimes replacement #750 paces it, does not gate it).
  • session recorder: every outbound message on 10 channels, ~1 MB/s stringify on main; 93% of bytes are screen frames; 1.6 GB on disk (86 recordings).
  • memoryInstrumentation sampler (useIpcSubscriptions.ts:335,624-625): every 30 s per session, stringifies 64 samples even when perf is off.
  • worktree activity index (WorktreeActivityIndex.ts:31,163-206, indexStore.ts:142-164): 51.8 MB JSON, stringified in full and temp/renamed on every change (0.3–0.5 s main-thread), no retention bucket (debugRetention.ts:354-396) → grows forever.
  • heap watchdog (heapWatchdog.ts:28,236): first crossing of min(1.5 GiB, 70%) runs a synchronous writeHeapSnapshot — a multi-second stop-the-world freeze with every session live; this IS the "2 GB watchdog freeze".
  • mitmproxy per session (claudeSession.ts:261,305-317; mitmAddon.py:438-535 open/append/close per SSE chunk): 3.7 GB on disk, 12 live processes, and 20 orphaned mitmdump processes (ppid 1, 2 days old) survived the previous run — not reaped on abnormal exit.
  • debug-bundle autosave: per pane per 60 s DOM outerHTML + sanitise; 654 MB.

Expected

  1. Gate feed-debug persistence behind dev-debug or a setting; a small sampled ring in packaged builds.
  2. Gate the memory sampler on perf-enabled.
  3. Worktree activity index: cap/TTL, per-project files or append-only, stringify off-thread.
  4. Heap watchdog: on trip, journal an incident and defer the snapshot to idle or a user action; never a synchronous snapshot on a live workspace.
  5. mitmproxy: batch addon writes; reap children on session stop and will-quit; kill stale _shared-conf mitmdump processes at startup; consider one shared proxy.
  6. Diagnostics sink (recorder, perf exporter, feed-debug, ghost/paste/dictation journals) in one utilityProcess/worker; main only postMessages.
  7. Document a "daily" profile: SESSION_RECORD, useProxyStreaming, aggressiveDebugPersistence off; DEV_DEBUG=1 kept for on-demand recording.

Refs #722, #748, #750, #733, #734.
Refs #103, #390. Source: architecture audit 2026-09-03 (scratchpad/arch-perf-audit.md).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions