[PR #5517] [CLOSED] feat(server): heap telemetry — health/diagnostics memory fields + near-limit warnings (#5506) #6794

Closed
opened 2026-10-23 04:13:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5517
Author: @kolacheee
Created: 8/25/2026
Status: ❌ Closed

Base: staging ← Head: feat/5506-heap-telemetry


📝 Commits (2)

  • 562f74e feat(server): heap telemetry for diagnosing memory-pressure unresponsiveness
  • 2eaf081 fix(heap-monitor): hysteresis, guarded tick, and monotonic clock (review round)

📊 Changes

9 files changed (+403 additions, -1 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/TROUBLESHOOTING.md (+8 -0)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+13 -1)
📝 packages/client/src/lib/support-diagnostics.ts (+17 -0)
📝 packages/server/src/app.ts (+4 -0)
📝 packages/server/src/index.ts (+3 -0)
➕ packages/server/src/services/heap-monitor.ts (+163 -0)
➕ scripts/regressions/heap-telemetry.regression.ts (+192 -0)
📝 scripts/regressions/open-issues.regression.ts (+2 -0)

📄 Description

Linked issue

Related to #5506 (the diagnosis-neutral observability arm; the issue stays open for the adaptive Termux heap-default work).

Why this change

The #5506 investigation found that large profiles are fully heap-resident in the file-backed store, so a server whose live set approaches --max-old-space-size degrades into a permanent full-GC regime long before V8 aborts — and today that state is completely invisible: Support Diagnostics and /api/health carry zero memory fields, there is no v8.getHeapStatistics call anywhere in the tree, and the persistent Termux session logs cannot distinguish "GC storm at the heap ceiling" from "process frozen or killed by Android". Every report in this class arrives undiagnosable.

What changed

  • New heap-monitor service (packages/server/src/services/heap-monitor.ts): logs the active Node heap limit at startup (so every Termux session log records which limit it ran under), and checks pressure once a minute — on crossing 85% of the limit it logs one actionable warning (how to raise NODE_OPTIONS), reminds at most every 10 minutes while pressure persists, and logs a recovery line on the way down. Never per-minute spam. The interval is unref'd; the pure state machine is freeze-safe (an Android process freeze at worst produces one late reminder).
  • /api/health now includes memory: { heapUsedMB, heapLimitMB, heapUsedPercent, rssMB } (a couple of cheap V8 calls; the payload grows ~70 bytes).
  • Support Diagnostics (Settings → Advanced → Copy Support Diagnostics) gains a Server memory: line, e.g. 842 MB / 1024 MB heap (82%), 1210 MB RSS. Old servers without the field show Unavailable instead of breaking.
  • docs/TROUBLESHOOTING.md: explains the [heap] Memory pressure warning and the explicit-heap override in the existing "Termux closes or restarts" section.
  • Regression (scripts/regressions/heap-telemetry.regression.ts): pins the warn-once/remind/recover state machine, snapshot sanity, the formatter (including old-server and malformed-input fall-throughs), and the wiring in app.ts/index.ts.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • pnpm lint (tsc + eslint, all packages) and the full production build are green locally; the new regression passes. pnpm check's format:check step fails on this Windows checkout repo-wide (autocrlf CRLF, pre-existing — same as CI-green PRs before this one); the touched package files were run through Prettier directly with zero content changes.
  • A two-lens adversarial review ran against the initial cut and confirmed three defects, all fixed in the second commit: missing hysteresis (a heap saw-toothing across 85% could emit a loud line every minute — now bounded to one pressure line + one recovery line per 10-minute window under any oscillation, pinned by two saw-tooth regression scenarios), an unguarded interval tick (an rss() throw could reach the process-fatal uncaughtException handler — the telemetry could kill the server it monitors), and wall-clock reminder spacing (a backward NTP step silenced reminders — now performance.now()).
  • The pre-existing formatSupportDiagnostics fixture in open-issues.regression.ts was updated for the new field, but that lane currently dies at import time on staging (the @/lib alias in local-notifications.ts, unrelated to this PR, reproduced with zero local changes) — filed as #5516, so the fixture edit is type-checked but not lane-executed; the same formatter line is executed by the new heap-telemetry regression.
  • /api/health is deliberately auth-exempt (it already reports version/commit/OS); the memory numbers ride the same tier — flagged for awareness, consistent with the existing surface.
  • Live smoke on the built server (isolated port + scratch data dir): /api/health returned {"heapUsedMB":76,"heapLimitMB":4288,"heapUsedPercent":2,"rssMB":194} with all pre-existing keys intact, and the startup line [heap] Node heap limit 4288MB (heap 68MB in use, RSS 193MB) was logged. (4288 = V8's default on a desktop; under the Termux launcher this records the configured limit.)
  • Please verify in the browser: Settings → Advanced → Copy Support Diagnostics includes the Server memory: line.
  • No new settings, no schema/storage changes, no version bump.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG entry added under [Unreleased] → Added. docs/TROUBLESHOOTING.md changed — per the batched-docs-i18n convention this should ride the next [docs-i18n] batch rather than a per-PR follow-up; flagging instead of opening a fresh issue.

UI evidence (if applicable)

The only UI-visible change is one new line in the Support Diagnostics clipboard text (screenshot-worthy during the manual pass).

Summary by CodeRabbit

  • New Features

    • Support Diagnostics now display server memory usage, including heap and overall memory details.
    • Health information refreshes automatically while Support Diagnostics is open.
    • Session logs provide warnings when memory usage is high and indicate when conditions recover.
  • Documentation

    • Added Android/Termux troubleshooting guidance for reducing memory pressure by configuring a 2048 MB heap limit.
  • Bug Fixes

    • Improved handling when memory information is unavailable or invalid, ensuring diagnostics remain usable.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5517 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/25/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `feat/5506-heap-telemetry` --- ### 📝 Commits (2) - [`562f74e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/562f74e30285a293dd01e793b13354765d99068f) feat(server): heap telemetry for diagnosing memory-pressure unresponsiveness - [`2eaf081`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2eaf081bcf3d851f4924334f1dfa2c6fb4530eca) fix(heap-monitor): hysteresis, guarded tick, and monotonic clock (review round) ### 📊 Changes **9 files changed** (+403 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/TROUBLESHOOTING.md` (+8 -0) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+13 -1) 📝 `packages/client/src/lib/support-diagnostics.ts` (+17 -0) 📝 `packages/server/src/app.ts` (+4 -0) 📝 `packages/server/src/index.ts` (+3 -0) ➕ `packages/server/src/services/heap-monitor.ts` (+163 -0) ➕ `scripts/regressions/heap-telemetry.regression.ts` (+192 -0) 📝 `scripts/regressions/open-issues.regression.ts` (+2 -0) </details> ### 📄 Description ## Linked issue Related to #5506 (the diagnosis-neutral observability arm; the issue stays open for the adaptive Termux heap-default work). ## Why this change The #5506 investigation found that large profiles are fully heap-resident in the file-backed store, so a server whose live set approaches `--max-old-space-size` degrades into a permanent full-GC regime long before V8 aborts — and today that state is completely invisible: Support Diagnostics and `/api/health` carry zero memory fields, there is no `v8.getHeapStatistics` call anywhere in the tree, and the persistent Termux session logs cannot distinguish "GC storm at the heap ceiling" from "process frozen or killed by Android". Every report in this class arrives undiagnosable. ## What changed - **New `heap-monitor` service** (`packages/server/src/services/heap-monitor.ts`): logs the active Node heap limit at startup (so every Termux session log records which limit it ran under), and checks pressure once a minute — on crossing 85% of the limit it logs one actionable warning (how to raise `NODE_OPTIONS`), reminds at most every 10 minutes while pressure persists, and logs a recovery line on the way down. Never per-minute spam. The interval is unref'd; the pure state machine is freeze-safe (an Android process freeze at worst produces one late reminder). - **`/api/health`** now includes `memory: { heapUsedMB, heapLimitMB, heapUsedPercent, rssMB }` (a couple of cheap V8 calls; the payload grows ~70 bytes). - **Support Diagnostics** (Settings → Advanced → Copy Support Diagnostics) gains a `Server memory:` line, e.g. `842 MB / 1024 MB heap (82%), 1210 MB RSS`. Old servers without the field show `Unavailable` instead of breaking. - **`docs/TROUBLESHOOTING.md`**: explains the `[heap] Memory pressure` warning and the explicit-heap override in the existing "Termux closes or restarts" section. - **Regression** (`scripts/regressions/heap-telemetry.regression.ts`): pins the warn-once/remind/recover state machine, snapshot sanity, the formatter (including old-server and malformed-input fall-throughs), and the wiring in `app.ts`/`index.ts`. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm lint` (tsc + eslint, all packages) and the full production build are green locally; the new regression passes. `pnpm check`'s `format:check` step fails on this Windows checkout repo-wide (autocrlf CRLF, pre-existing — same as CI-green PRs before this one); the touched package files were run through Prettier directly with zero content changes. - A two-lens adversarial review ran against the initial cut and confirmed three defects, all fixed in the second commit: missing hysteresis (a heap saw-toothing across 85% could emit a loud line every minute — now bounded to one pressure line + one recovery line per 10-minute window under any oscillation, pinned by two saw-tooth regression scenarios), an unguarded interval tick (an `rss()` throw could reach the process-fatal `uncaughtException` handler — the telemetry could kill the server it monitors), and wall-clock reminder spacing (a backward NTP step silenced reminders — now `performance.now()`). - The pre-existing `formatSupportDiagnostics` fixture in `open-issues.regression.ts` was updated for the new field, but that lane currently **dies at import time on staging** (the `@/lib` alias in `local-notifications.ts`, unrelated to this PR, reproduced with zero local changes) — filed as #5516, so the fixture edit is type-checked but not lane-executed; the same formatter line is executed by the new heap-telemetry regression. - `/api/health` is deliberately auth-exempt (it already reports version/commit/OS); the memory numbers ride the same tier — flagged for awareness, consistent with the existing surface. - **Live smoke on the built server** (isolated port + scratch data dir): `/api/health` returned `{"heapUsedMB":76,"heapLimitMB":4288,"heapUsedPercent":2,"rssMB":194}` with all pre-existing keys intact, and the startup line `[heap] Node heap limit 4288MB (heap 68MB in use, RSS 193MB)` was logged. (4288 = V8's default on a desktop; under the Termux launcher this records the configured limit.) - Please verify in the browser: Settings → Advanced → Copy Support Diagnostics includes the `Server memory:` line. - No new settings, no schema/storage changes, no version bump. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) CHANGELOG entry added under **[Unreleased] → Added**. `docs/TROUBLESHOOTING.md` changed — per the batched-docs-i18n convention this should ride the next `[docs-i18n]` batch rather than a per-PR follow-up; flagging instead of opening a fresh issue. ## UI evidence (if applicable) The only UI-visible change is one new line in the Support Diagnostics clipboard text (screenshot-worthy during the manual pass). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Support Diagnostics now display server memory usage, including heap and overall memory details. * Health information refreshes automatically while Support Diagnostics is open. * Session logs provide warnings when memory usage is high and indicate when conditions recover. * **Documentation** * Added Android/Termux troubleshooting guidance for reducing memory pressure by configuring a 2048 MB heap limit. * **Bug Fixes** * Improved handling when memory information is unavailable or invalid, ensuring diagnostics remain usable. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:13:47 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6794
No description provided.