[GH-ISSUE #4703] [Issue]: Chat tab stuck fetching messages?limit=100 in an infinite loop, causing excessive network traffic #2578

Closed
opened 2026-10-21 05:50:33 +07:00 by bsakaguchi · 7 comments
Owner

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

Originally assigned to: @kolacheee on GitHub.

Summary

Opening a character chat causes the messages?limit=100 request to fire repeatedly in an infinite loop, transferring massive amounts of data (150+ requests, 150MB+ in a short window) while the tab is idle.

Expected behavior

This endpoint should only be called once when the chat is opened (or on actual new messages), not repeatedly while idle.

Actual behavior

The messages?limit=100 endpoint is called repeatedly without stopping. In one ~1 minute window, DevTools showed 150+ calls to this endpoint, with individual response sizes ranging from ~228KB to 4.4MB, totaling over 150MB transferred. This continues as long as the chat tab stays open, and only stops when navigating away (e.g. to the Presets menu) and refreshing.

Steps to reproduce

  1. Open a character chat conversation
  2. Leave the tab open/idle (no interaction)
  3. Open browser DevTools → Network tab and watch requests

Environment

  • Deployment: self-hosted on a Ubuntu VPS (not Docker), run via Node.js + systemd
  • Accessed remotely over Tailscale, from a mobile browser
  • Marinara version: 2.4.1

Logs, screenshots, or video

Before disabling Presence/Weather effects:
Image

After disabling Presence/Weather effects (traffic got worse, not better — so these settings are likely not the actual cause):
Image

Browser DevTools Network tab, filtered — showing the messages?limit=100 request firing repeatedly:
Image

Additional context

"Impact:" On mobile data, this used roughly 6GB of data in under an hour before I noticed and killed the process.

Note: the transfer rate actually increased after I disabled the Presence indicator and Weather effect features, ruling those out as the direct cause.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Lattete on GitHub (Aug 7, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4703 Originally assigned to: @kolacheee on GitHub. ## Summary Opening a character chat causes the `messages?limit=100` request to fire repeatedly in an infinite loop, transferring massive amounts of data (150+ requests, 150MB+ in a short window) while the tab is idle. ## Expected behavior This endpoint should only be called once when the chat is opened (or on actual new messages), not repeatedly while idle. ## Actual behavior The `messages?limit=100` endpoint is called repeatedly without stopping. In one ~1 minute window, DevTools showed 150+ calls to this endpoint, with individual response sizes ranging from ~228KB to 4.4MB, totaling over 150MB transferred. This continues as long as the chat tab stays open, and only stops when navigating away (e.g. to the Presets menu) and refreshing. ## Steps to reproduce 1. Open a character chat conversation 2. Leave the tab open/idle (no interaction) 3. Open browser DevTools → Network tab and watch requests ## Environment - Deployment: self-hosted on a Ubuntu VPS (not Docker), run via Node.js + systemd - Accessed remotely over Tailscale, from a mobile browser - Marinara version: 2.4.1 ## Logs, screenshots, or video Before disabling Presence/Weather effects: <img width="880" height="177" alt="Image" src="https://github.com/user-attachments/assets/e7585f32-3e7c-4f52-a534-054cce2be266" /> After disabling Presence/Weather effects (traffic got worse, not better — so these settings are likely not the actual cause): <img width="856" height="177" alt="Image" src="https://github.com/user-attachments/assets/770fc6ef-52f3-4acc-8d20-8b14ab8105b8" /> Browser DevTools Network tab, filtered — showing the `messages?limit=100` request firing repeatedly: <img width="762" height="654" alt="Image" src="https://github.com/user-attachments/assets/70cd9c40-3d79-4bc5-991c-79093d347223" /> ## Additional context "Impact:" On mobile data, this used roughly 6GB of data in under an hour before I noticed and killed the process. Note: the transfer rate actually increased after I disabled the Presence indicator and Weather effect features, ruling those out as the direct cause. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:50:33 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@kolacheee commented on GitHub (Aug 7, 2026):

@Lattete thank you for submitting this issue! I will take a look at it.

<!-- gh-comment-id:5216208415 --> @kolacheee commented on GitHub (Aug 7, 2026): @Lattete thank you for submitting this issue! I will take a look at it.
Author
Owner

@kolacheee commented on GitHub (Aug 7, 2026):

Triage note: this is mechanically distinct from #4704 (which covers the designed 30-second background-autonomous poll of the chat list). What you're seeing — messages?limit=100 at 150+/minute — matches no designed poll in the codebase (the messages query has no refetch interval; all its invalidations are event-driven), so this looks like a runaway invalidation/refetch feedback loop, likely response-latency-bound (~400ms period ≈ the round-trip time for MB-scale payloads over Tailscale). Root-cause investigation is underway; will follow up here with the mechanism and whether current staging is affected. The excellent evidence in this report (request rate, response sizes, the presence/weather rule-out) is what makes that tractable — thank you.

<!-- gh-comment-id:5216232629 --> @kolacheee commented on GitHub (Aug 7, 2026): Triage note: this is mechanically distinct from #4704 (which covers the *designed* 30-second background-autonomous poll of the chat list). What you're seeing — `messages?limit=100` at 150+/minute — matches no designed poll in the codebase (the messages query has no refetch interval; all its invalidations are event-driven), so this looks like a runaway invalidation/refetch feedback loop, likely response-latency-bound (~400ms period ≈ the round-trip time for MB-scale payloads over Tailscale). Root-cause investigation is underway; will follow up here with the mechanism and whether current staging is affected. The excellent evidence in this report (request rate, response sizes, the presence/weather rule-out) is what makes that tractable — thank you.
Author
Owner

@kolacheee commented on GitHub (Aug 7, 2026):

Root-cause investigation results (traced on both v2.4.1 and current staging; verified against the installed React Query source).

Confirmed: the amplifier that makes 150MB/min possible

The chat's message list is an infinite query (useChatMessages, use-chats.ts:269-293) that accumulates one cached page per "Load More". React Query v5 refetches an infinite query by re-fetching every accumulated page sequentially, each request issued the instant the previous response completes (verified in @tanstack/query-core@5.100.9 infiniteQueryBehavior.js — a zero-delay do/while over oldPages.length). So any single refetch trigger = N back-to-back messages?limit=100[&before=...] requests at wire speed — your ~400ms cadence is the network round-trip for MB payloads over Tailscale, not a timer. This also explains why only refreshing stopped it: a refresh resets the page cache to one page (and on mobile, navigating to another panel keeps the chat mounted underneath — AppShell overlay mode — so the query observer never unmounts). Mechanism unchanged between v2.4.1 and staging.

The sustained trigger: three real candidates, not yet proven

What re-triggers the storm continuously needs one data point from your setup to discriminate:

  1. Connectivity flaps + refetchOnReconnect — the messages query inherits React Query's default refetchOnReconnect: true (only window-focus refetch is globally disabled), with a 30s stale time. Mobile + VPN = frequent online events; each one after 30s = a full-pages storm.
  2. Autonomous-message cycles — if this chat has autonomous messages enabled: every 30s check → generation attempt → every termination path (including the silent generation_discarded case where you'd see nothing happen at all) ends in an authoritative refetch of all pages.
  3. Professor Mari workspace refresh fanout — a cache-wide refetchType: 'all' in the Mari workspace path can walk inactive per-chat message pages too.

Could you check: (a) is Messages-per-page set to 100 in your settings, and had you scrolled far back in that chat's history before it started (roughly how many "Load More"s)? (b) does the affected chat have autonomous messages enabled? (c) in the DevTools capture, do the repeated requests carry &before= cursors (a storm re-walking pages) or always the bare ?limit=100 (restarting storms)? A HAR of ~2 minutes would settle it completely.

Fix direction

The amplifier should be fixed regardless of which driver is live, because it converts any stray refetch into a megabyte storm: bound the page cache (maxPages) on the messages query, override refetchOnReconnect for it, and make the authoritative refreshes target 'active' + coalesce per chat. That turns the worst case from 150MB/min into a single cheap page fetch — then the surviving driver (if any) becomes visible and small enough to fix on its own.

<!-- gh-comment-id:5216761491 --> @kolacheee commented on GitHub (Aug 7, 2026): Root-cause investigation results (traced on both v2.4.1 and current staging; verified against the installed React Query source). ## Confirmed: the amplifier that makes 150MB/min possible The chat's message list is an **infinite query** (`useChatMessages`, `use-chats.ts:269-293`) that accumulates one cached page per "Load More". React Query v5 refetches an infinite query by **re-fetching every accumulated page sequentially, each request issued the instant the previous response completes** (verified in `@tanstack/query-core@5.100.9` `infiniteQueryBehavior.js` — a zero-delay `do/while` over `oldPages.length`). So *any single refetch trigger* = N back-to-back `messages?limit=100[&before=...]` requests at wire speed — your ~400ms cadence is the network round-trip for MB payloads over Tailscale, not a timer. This also explains why only **refreshing** stopped it: a refresh resets the page cache to one page (and on mobile, navigating to another panel keeps the chat mounted underneath — `AppShell` overlay mode — so the query observer never unmounts). Mechanism unchanged between v2.4.1 and staging. ## The sustained trigger: three real candidates, not yet proven What re-triggers the storm continuously needs one data point from your setup to discriminate: 1. **Connectivity flaps + `refetchOnReconnect`** — the messages query inherits React Query's default `refetchOnReconnect: true` (only window-focus refetch is globally disabled), with a 30s stale time. Mobile + VPN = frequent `online` events; each one after 30s = a full-pages storm. 2. **Autonomous-message cycles** — if this chat has autonomous messages enabled: every 30s check → generation attempt → *every* termination path (including the **silent** `generation_discarded` case where you'd see nothing happen at all) ends in an authoritative refetch of all pages. 3. **Professor Mari workspace refresh fanout** — a cache-wide `refetchType: 'all'` in the Mari workspace path can walk inactive per-chat message pages too. **Could you check:** (a) is Messages-per-page set to 100 in your settings, and had you scrolled far back in that chat's history before it started (roughly how many "Load More"s)? (b) does the affected chat have autonomous messages enabled? (c) in the DevTools capture, do the repeated requests carry `&before=` cursors (a storm re-walking pages) or always the bare `?limit=100` (restarting storms)? A HAR of ~2 minutes would settle it completely. ## Fix direction The amplifier should be fixed regardless of which driver is live, because it converts *any* stray refetch into a megabyte storm: bound the page cache (`maxPages`) on the messages query, override `refetchOnReconnect` for it, and make the authoritative refreshes target `'active'` + coalesce per chat. That turns the worst case from 150MB/min into a single cheap page fetch — then the surviving driver (if any) becomes visible and small enough to fix on its own.
Author
Owner

@Lattete commented on GitHub (Aug 7, 2026):

Here are the details regarding your questions:

(a) Messages-per-page & Scroll history:
The chatroom where this occurred was a Roleplay (RP) chat.
My Messages-per-page setting is currently set to 20.
I never clicked "Load More" and only viewed the already rendered messages (scrolled up at most 5–6 turns).

(b) Autonomous messages:
Yes, Autonomous messages are enabled (ON) for this chat.

(c) Request URL patterns:
Checking the repeated message request URLs, only '?limit=100' is repeating. There is no '&before='cursor present.

Since the HAR file is over 200MB and exceeds GitHub's file size limit, I'm sharing it via Google Drive instead:
https://drive.google.com/file/d/1c5NkqHRRdAOiDZGY0iD2mcPRplTp92_N/view?usp=drive_link

Hope this helps narrow down the cause!

<!-- gh-comment-id:5217680379 --> @Lattete commented on GitHub (Aug 7, 2026): Here are the details regarding your questions: (a) Messages-per-page & Scroll history: The chatroom where this occurred was a Roleplay (RP) chat. My Messages-per-page setting is currently set to 20. I never clicked "Load More" and only viewed the already rendered messages (scrolled up at most 5–6 turns). (b) Autonomous messages: Yes, Autonomous messages are enabled (ON) for this chat. (c) Request URL patterns: Checking the repeated message request URLs, only '?limit=100' is repeating. There is no '&before='cursor present. Since the HAR file is over 200MB and exceeds GitHub's file size limit, I'm sharing it via Google Drive instead: https://drive.google.com/file/d/1c5NkqHRRdAOiDZGY0iD2mcPRplTp92_N/view?usp=drive_link Hope this helps narrow down the cause!
Author
Owner

@kolacheee commented on GitHub (Aug 7, 2026):

Thank you for the HAR — it identified the source definitively, and it's not what any of us guessed. The requests are not coming from Marinara's own UI. They're coming from an installed personal extension.

What the HAR shows

Your capture spans 125.5 seconds and contains 448 requests, of which 426 are GET /api/chats/<id>/messages?limit=100 (≈204/min). The key detail: those 426 requests are not for one chat — they cycle through 18 distinct chat ids, round-robin. The traffic is organized into 24 complete sweeps:

  • each sweep fetches all 18 chats' messages back-to-back (~5s per sweep, one request every ~200ms — i.e., each next request fires as soon as the previous response lands),
  • the pause between sweeps is only 0.06–0.36 s, so the scan effectively never stops,
  • every ~20s the cycle is bracketed by GET /api/chats plus GET + PATCH /api/personal-extensions/taB-MN2qBdEec0hn827Va/storage.

That last endpoint is the smoking gun: personal-extensions/…/storage is the persistence API for user-installed personal extensions. Nothing in Marinara's core client ever enumerates every chat and downloads each one's messages — but an extension script running in your session is doing exactly that, continuously, with a hardcoded limit=100 (which is why the URL never matched your messages-per-page setting of 20, and why there's never a before= cursor).

The extension's storage payload structure (field names only — I did not read your data) is:

memoData { version, dataUpdatedAt, boards[ { id, name, notes } ] }

So it appears to be a memo / notes-board extension. It rescans the full message history of every chat on every pass, which on your instance moves roughly 1 MB per request — matching the multi-GB/hour traffic you measured. This would also account for a good share of the battery drain on the Termux host, since the server has to serve those ~200 reads/min.

What to do

  1. Open Settings → Personal Extensions and look for a memo/notes/board-style extension. Disable it (or all extensions, to bisect).
  2. Reload the tab and watch DevTools Network for ~a minute — the messages?limit=100 stream should be gone entirely.
  3. If you can share which extension it is (name/source), that would help a lot: the author can likely fix it cheaply (scan only the active chat, or only chats changed since the last sweep, and pause between sweeps), and other users of the same extension are almost certainly hitting this too.

Engine-side follow-ups

This also exposes real engine work, which I'm handling separately:

  • The refetch-amplification hardening I described in my earlier comment is still valid and coming as a PR — it fixes genuine cases where Marinara itself re-downloads message pages more than needed (network reconnects, workspace-wide invalidations, post-generation refreshes). It just isn't what produced your loop.
  • The personal-extension runtime currently gives extensions an unmetered pipeline to the local API — a single misbehaving script can saturate a phone-hosted instance exactly like this, silently. I'll propose rate limiting / per-extension request accounting so runaway extensions are visible and bounded.

RP mode and autonomous messages turned out to be coincidental — the sweep runs regardless of which chat is open.

<!-- gh-comment-id:5219132238 --> @kolacheee commented on GitHub (Aug 7, 2026): Thank you for the HAR — it identified the source definitively, and it's not what any of us guessed. **The requests are not coming from Marinara's own UI. They're coming from an installed personal extension.** ## What the HAR shows Your capture spans 125.5 seconds and contains 448 requests, of which **426 are `GET /api/chats/<id>/messages?limit=100`** (≈204/min). The key detail: those 426 requests are **not** for one chat — they cycle through **18 distinct chat ids, round-robin**. The traffic is organized into 24 complete sweeps: - each sweep fetches all 18 chats' messages back-to-back (~5s per sweep, one request every ~200ms — i.e., each next request fires as soon as the previous response lands), - the pause between sweeps is only **0.06–0.36 s**, so the scan effectively never stops, - every ~20s the cycle is bracketed by `GET /api/chats` plus `GET` + `PATCH /api/personal-extensions/taB-MN2qBdEec0hn827Va/storage`. That last endpoint is the smoking gun: `personal-extensions/…/storage` is the persistence API for **user-installed personal extensions**. Nothing in Marinara's core client ever enumerates every chat and downloads each one's messages — but an extension script running in your session is doing exactly that, continuously, with a hardcoded `limit=100` (which is why the URL never matched your messages-per-page setting of 20, and why there's never a `before=` cursor). The extension's storage payload structure (field names only — I did not read your data) is: ``` memoData { version, dataUpdatedAt, boards[ { id, name, notes } ] } ``` So it appears to be a **memo / notes-board extension**. It rescans the full message history of every chat on every pass, which on your instance moves roughly 1 MB per request — matching the multi-GB/hour traffic you measured. This would also account for a good share of the battery drain on the Termux host, since the server has to serve those ~200 reads/min. ## What to do 1. Open **Settings → Personal Extensions** and look for a memo/notes/board-style extension. Disable it (or all extensions, to bisect). 2. Reload the tab and watch DevTools Network for ~a minute — the `messages?limit=100` stream should be gone entirely. 3. If you can share which extension it is (name/source), that would help a lot: the author can likely fix it cheaply (scan only the active chat, or only chats changed since the last sweep, and pause between sweeps), and other users of the same extension are almost certainly hitting this too. ## Engine-side follow-ups This also exposes real engine work, which I'm handling separately: - The refetch-amplification hardening I described in my earlier comment is still valid and coming as a PR — it fixes genuine cases where Marinara itself re-downloads message pages more than needed (network reconnects, workspace-wide invalidations, post-generation refreshes). It just isn't what produced *your* loop. - The personal-extension runtime currently gives extensions an unmetered pipeline to the local API — a single misbehaving script can saturate a phone-hosted instance exactly like this, silently. I'll propose rate limiting / per-extension request accounting so runaway extensions are visible and bounded. RP mode and autonomous messages turned out to be coincidental — the sweep runs regardless of which chat is open.
Author
Owner

@Lattete commented on GitHub (Aug 7, 2026):

As you mentioned, I do use the memo extension.
Right after reading your message, I disabled it, but the issue persisted.
So I turned off all other extensions and tested them one by one to narrow it down.

It turns out the real culprit was a completely different extension.
It wasn't the memo extension, but a receipt extension that reads chat message tokens to calculate the total cost.
I'm not sure why it was logged as 'memoData' in the storage, but my tests confirmed this was the one causing the network spam.
Thanks to your advice, I was able to find the root cause. I've disabled the problem extension, and the issue has completely stopped.

The extension is called 'Marinara Token Cost Receipt v2.0.0' and is also available on GitHub.
I will try to reach out to the developer of that extension to let them know.

Thank you so much for reviewing my issue so quickly!

<!-- gh-comment-id:5220150488 --> @Lattete commented on GitHub (Aug 7, 2026): As you mentioned, I do use the memo extension. Right after reading your message, I disabled it, but the issue persisted. So I turned off all other extensions and tested them one by one to narrow it down. It turns out the real culprit was a completely different extension. It wasn't the memo extension, but a receipt extension that reads chat message tokens to calculate the total cost. I'm not sure why it was logged as 'memoData' in the storage, but my tests confirmed this was the one causing the network spam. Thanks to your advice, I was able to find the root cause. I've disabled the problem extension, and the issue has completely stopped. The extension is called 'Marinara Token Cost Receipt v2.0.0' and is also available on GitHub. I will try to reach out to the developer of that extension to let them know. Thank you so much for reviewing my issue so quickly!
Author
Owner

@kolacheee commented on GitHub (Aug 7, 2026):

@Lattete of course, thank you for the quick and comprehensive replies, it made troubleshooting the problem so much easier 🙂 I will be closing this Issue now.

<!-- gh-comment-id:5220241293 --> @kolacheee commented on GitHub (Aug 7, 2026): @Lattete of course, thank you for the quick and comprehensive replies, it made troubleshooting the problem so much easier 🙂 I will be closing this Issue now.
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#2578
No description provided.