[GH-ISSUE #4629] [Issue]: Personal-extension runtime polled every 2s on every screen, in background tabs, even with zero extensions #2531

Closed
opened 2026-10-21 05:49:37 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @kolacheee on GitHub (Aug 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4629

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The personal-extension client runtime is polled over HTTP every 2 seconds, on every screen, for the whole app session — explicitly including hidden/background tabs — even when the user has zero extensions installed. On a phone this keeps the radio out of low-power state (~30 wakeups/minute); a Termux user pays the server side of every request too. Measured live on a built client: one GET /api/personal-extensions/runtime/client every 2.0s (158 requests in 5.4 minutes), 302 B each, from a fresh install with no extensions.

Expected behavior

Extension runtime freshness handled like the rest of the app's polling: visibility-gated, a modest interval (or none — mutation-driven invalidation already exists), and skipped entirely when there is nothing to poll for.

Actual behavior

usePersonalExtensionRuntime (packages/client/src/hooks/use-personal-extensions.ts:26-34) sets:

staleTime: 1_000,
refetchInterval: 2_000,
refetchIntervalInBackground: true,

with no enabled gate. Its only consumer is PersonalExtensionInjector (packages/client/src/components/layout/PersonalExtensionInjector.tsx:386), mounted unconditionally at the App root (packages/client/src/App.tsx:1019) — so the poll runs on all screens for the app's lifetime. usePersonalExtensionPolicy adds a second poll every 10s (use-personal-extensions.ts:36-43). Each hit runs getPersonalExtensionPolicy(db) + storage.list() server-side (packages/server/src/routes/personal-extensions.routes.ts:1153-1163).

Notably this is the only poller in the client that sets refetchIntervalInBackground: true — every other recurring poll is visibility-gated or background-disabled (ConversationPresenceCard.tsx:181, use-haptic.ts:16, use-noodle.ts:88), so backgrounded PWA tabs keep firing this one (subject only to browser timer throttling).

Steps to reproduce

  1. Open the app (any screen), no extensions installed.
  2. Watch the network tab: GET /api/personal-extensions/runtime/client every 2 seconds, indefinitely; GET /api/personal-extensions/policy every 10 seconds.
  3. Hide the tab: the 2s poll continues (per refetchIntervalInBackground: true), throttled only by the browser.

Environment

  • Marinara Engine version: 2.4.2 (staging, 93738d9b1)
  • Install type: source (production build, node packages/server/dist/index.js)
  • OS + version: measured on Windows/Chrome; reported as battery drain on Android (browser + Termux)
  • Browser or app shell: any

Logs, screenshots, or video

Live measurement on the built client: 158 polls / 324 s uptime (avg gap 2,040 ms; last gaps 2017/2018/2013/2019/2014 ms), 302 B transfer each; confirmed still polling on the Chats screen via an instrumented fetch counter (5 polls / 12 s).

Additional context

Part of a mobile-battery investigation prompted by two user reports (phone heat in the browser client; baseline drain in Termux). This poll is a baseline cost with the app merely open and matches both reports; it predates the recent folder-access feature.

Suggested fix (matching the app's own conventions): drop refetchIntervalInBackground: true; use a visibility-gated function-form interval (refetchInterval: () => (document.hidden ? false : 15_000) — the use-haptic.ts:16 pattern) or remove the interval and rely on the existing mutation invalidation (useInvalidatePersonalExtensions); optionally skip polling when the extension list is empty and external extensions are disabled.

Related (same subsystem, server side, affects Termux installs with server extensions): the personal server-extension host communicates with child processes via file polling at 25 ms plus ~1 s heartbeat writes, continuously from boot. Happy to split that into its own issue if preferred.

Filed alongside #4628 (assistant streaming) and #4630 (Noodler reconcile scans).

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Aug 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4629 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The personal-extension client runtime is polled over HTTP **every 2 seconds, on every screen, for the whole app session — explicitly including hidden/background tabs — even when the user has zero extensions installed**. On a phone this keeps the radio out of low-power state (~30 wakeups/minute); a Termux user pays the server side of every request too. Measured live on a built client: one `GET /api/personal-extensions/runtime/client` every 2.0s (158 requests in 5.4 minutes), 302 B each, from a fresh install with no extensions. ## Expected behavior Extension runtime freshness handled like the rest of the app's polling: visibility-gated, a modest interval (or none — mutation-driven invalidation already exists), and skipped entirely when there is nothing to poll for. ## Actual behavior `usePersonalExtensionRuntime` (`packages/client/src/hooks/use-personal-extensions.ts:26-34`) sets: ```ts staleTime: 1_000, refetchInterval: 2_000, refetchIntervalInBackground: true, ``` with no `enabled` gate. Its only consumer is `PersonalExtensionInjector` (`packages/client/src/components/layout/PersonalExtensionInjector.tsx:386`), mounted unconditionally at the App root (`packages/client/src/App.tsx:1019`) — so the poll runs on all screens for the app's lifetime. `usePersonalExtensionPolicy` adds a second poll every 10s (`use-personal-extensions.ts:36-43`). Each hit runs `getPersonalExtensionPolicy(db)` + `storage.list()` server-side (`packages/server/src/routes/personal-extensions.routes.ts:1153-1163`). Notably this is the **only** poller in the client that sets `refetchIntervalInBackground: true` — every other recurring poll is visibility-gated or background-disabled (`ConversationPresenceCard.tsx:181`, `use-haptic.ts:16`, `use-noodle.ts:88`), so backgrounded PWA tabs keep firing this one (subject only to browser timer throttling). ## Steps to reproduce 1. Open the app (any screen), no extensions installed. 2. Watch the network tab: `GET /api/personal-extensions/runtime/client` every 2 seconds, indefinitely; `GET /api/personal-extensions/policy` every 10 seconds. 3. Hide the tab: the 2s poll continues (per `refetchIntervalInBackground: true`), throttled only by the browser. ## Environment - Marinara Engine version: 2.4.2 (staging, 93738d9b1) - Install type: source (production build, `node packages/server/dist/index.js`) - OS + version: measured on Windows/Chrome; reported as battery drain on Android (browser + Termux) - Browser or app shell: any ## Logs, screenshots, or video Live measurement on the built client: 158 polls / 324 s uptime (avg gap 2,040 ms; last gaps 2017/2018/2013/2019/2014 ms), 302 B transfer each; confirmed still polling on the Chats screen via an instrumented fetch counter (5 polls / 12 s). ## Additional context Part of a mobile-battery investigation prompted by two user reports (phone heat in the browser client; baseline drain in Termux). This poll is a baseline cost with the app merely open and matches both reports; it predates the recent folder-access feature. Suggested fix (matching the app's own conventions): drop `refetchIntervalInBackground: true`; use a visibility-gated function-form interval (`refetchInterval: () => (document.hidden ? false : 15_000)` — the `use-haptic.ts:16` pattern) or remove the interval and rely on the existing mutation invalidation (`useInvalidatePersonalExtensions`); optionally skip polling when the extension list is empty and external extensions are disabled. Related (same subsystem, server side, affects Termux installs with *server* extensions): the personal server-extension host communicates with child processes via **file polling at 25 ms** plus ~1 s heartbeat writes, continuously from boot. Happy to split that into its own issue if preferred. Filed alongside #4628 (assistant streaming) and #4630 (Noodler reconcile scans). ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:49:37 +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#2531
No description provided.