Skip to content

feat(memory): add opt-in frontend lifecycle diagnostics - #1151

Open
kogekiplay wants to merge 7 commits into
spacering-net:mainfrom
kogekiplay:feat/memory-lifecycle-metrics
Open

kogekiplay wants to merge 7 commits into
spacering-net:mainfrom
kogekiplay:feat/memory-lifecycle-metrics

Conversation

@kogekiplay

@kogekiplay kogekiplay commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

WebContent physical footprint alone cannot distinguish active workload, bounded caches, or objects that remain after a conversation closes. This PR adds a default-off local diagnostics channel so process measurements can be correlated with renderer state and lifecycle observations.

The renderer schedules numeric aggregate reports on a 15-second interval, subject to WebKit background timer throttling, only when NEXT_PUBLIC_CODEG_MEMORY_DIAGNOSTICS=1 in a local Tauri desktop window. The Rust side requires the default-off memory-diagnostics Cargo feature. An authenticated /api/debug/frontend_memory endpoint exposes the latest report; storage is capped at 16 ephemeral reporter UUIDs with a five-minute TTL. Metric names are a closed vocabulary shared with Rust, and values are nonnegative JavaScript-safe integers. No prompts, titles, paths, session identifiers, tool payloads, DOM text, arbitrary evaluation, or heap snapshots are transmitted.

Counters cover Provider/surface lifecycle, connections, tabs, subscribers, live/tool text sizes, hydration/unmapped queues, streaming and tool batches, runtime sessions/turns/background overlays, HTML preview caches/pins, iframe count, and shared highlighting-cache estimates. Page visibility and focus are recorded as numeric flags to distinguish document state from an unclassified reporting delay.

Removed runtime sessions, representative latest local/persisted turns or live messages, and released message-view DOM wrappers are observed through bounded WeakRef trackers. Retired entries hold neither application callbacks nor strong target references. View reactivation supersedes obsolete cleanup, and late retirement after pagehide cannot start another reporter. Each target category is capped at 128; dropped observations are counted. Provider readers unregister on unmount. The reporter begins at the document root and accepts the complete workspace metric vocabulary, with deserialization coverage to prevent a mounted reporter silently losing reports at the schema boundary.

These measurements do not change conversation/cache ownership. Weak-reference survival is not retained-byte measurement, representative targets do not cover every object, and natural collection timing is uncontrolled. Highlighting bytes are estimates; visibility/focus do not describe every native window-occlusion state. This PR does not claim that a counter increase proves a leak or that the long-term WebContent growth is resolved. The independently confirmed lifecycle repair is already in #1157, which is merged.

This branch is rebased onto the current official main at bd88b9dac0417057342fca13234b9c19a8b8093d (v0.45.0). On this rebased diagnostic head (with only local version labels added for the candidate), 791 frontend files / 11,720 tests, TypeScript, changed-file ESLint and Prettier, the diagnostics-enabled production build, five Rust frontend-memory tests, 145 ACP manager tests, desktop-library Clippy with diagnostics enabled, and the release desktop build passed. A local ad-hoc signature was verified with deep/strict checks, and the official app was backed up and file-matched before replacement. The local candidate is installed and its new reporter keys and process identities were verified; CI for the rebased PR head is tracked separately.

An isolated native WKWebView/JavaScriptCore probe used this exact collector source with bounded allocation pressure and natural GC only. Session, representative turn, and detached DOM-wrapper targets were reclaimed while the view cleanup remained held. Explicitly held controls survived until release and were then reclaimed; all three retired-alive counters returned to zero. This validates diagnostic reachability mechanics, not the real desktop lifecycle or retained native bytes.

The official v0.45.0 ARM64 release was verified against the installed binary before replacement. One bounded 96-line visible native reply completed and its tab was normally closed on the official release. The same process recovered sharply, then its first 30-minute post-close interval had 120 samples, a median of about 414.8 MiB, and a maximum gap of 15.1 seconds. The official binary has no diagnostic endpoint, so that observation does not identify retained objects.

The corresponding diagnostic-candidate workload has now completed through normal tab close and a fixed 30-minute natural recovery interval. All 96 lines and END were verified in the native UI. Runtime sessions, tabs, subscribers, connections, live text and queues returned to baseline. The representative retired session, turn and DOM-wrapper counters remained 1/1/1 in fresh reports; highlighting was estimated at 183,448 bytes with no work in flight. The same WebContent process naturally fell from about 604 to 381 MiB during recovery, without restart or forced GC, while those three weak-reference counters remained unchanged. The interval contains 120 samples, a maximum gap of 15.1 seconds, and no gaps over 30 seconds; its last ten-minute median was 381.5 MiB versus the pre-workload five-minute median of 306.7 MiB. All 16 serial phase captures used frontend reports less than 30 seconds old.

This demonstrates why physical footprint and representative object survival must be interpreted separately. Weak-target survival does not prove strong retention, and the natural footprint recovery does not establish that all relevant objects were collected or that the original long-term growth is resolved. Natural GC timing is uncontrolled. The diagnostic candidate changes observation only; these official/candidate observations are not a repair A/B.

@kogekiplay
kogekiplay force-pushed the feat/memory-lifecycle-metrics branch 2 times, most recently from ebfe170 to 52e35e7 Compare November 13, 2026 15:53
@kogekiplay
kogekiplay force-pushed the feat/memory-lifecycle-metrics branch from 036a5be to 6b39835 Compare November 16, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant