Repository navigation
feat(memory): add opt-in frontend lifecycle diagnostics - #1151
Open
kogekiplay wants to merge 7 commits into
Open
kogekiplay wants to merge 7 commits into
kogekiplay wants to merge 7 commits into
Conversation
kogekiplay
force-pushed
the
feat/memory-lifecycle-metrics
branch
2 times, most recently
from
November 13, 2026 15:53
ebfe170 to
52e35e7
Compare
kogekiplay
force-pushed
the
feat/memory-lifecycle-metrics
branch
from
November 16, 2026 01:59
036a5be to
6b39835
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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=1in a local Tauri desktop window. The Rust side requires the default-offmemory-diagnosticsCargo feature. An authenticated/api/debug/frontend_memoryendpoint 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
WeakReftrackers. Retired entries hold neither application callbacks nor strong target references. View reactivation supersedes obsolete cleanup, and late retirement afterpagehidecannot 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
mainatbd88b9dac0417057342fca13234b9c19a8b8093d(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.