mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #4721] [Issue]: Chat Settings drawer's pageSize-100 observer hijacks the shared chat-messages query options while open #2592
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#2592
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Aug 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4721
Originally assigned to: @kolacheee on GitHub.
Summary
ChatSettingsDrawer's secret-plot reader mounts auseChatMessagesobserver with a hardcodedpageSize: 100on the same React Query key the chat transcript uses with the user'smessagesPerPage(and the tracker panel uses with 20). In React Query v5 the last observer to set options owns the shared query'squeryFnandgetNextPageParamclosures, so while the drawer is open the transcript's pagination runs with the wrong page size — fetching 100-row pages regardless of the user's setting and mis-evaluating the has-more-history check.Expected behavior
Opening Chat Settings has no effect on the transcript's message pagination: refetches fetch
messagesPerPage-sized pages, and "Load More" stays available whenever older history exists.Actual behavior
While the drawer is open (and briefly after closing, until a surviving observer re-renders and rewrites the shared options), the shared messages query's options belong to whichever observer rendered last — typically the drawer, which renders after
ChatAreain the tree:limit=100instead of the user's page size.ChatAreathen discards the surplus — its defensivetrimNewestLoadedMessagePageeffect cutspages[0]back down tomessagesPerPage, throwing away up to 80 fetched rows per refetch.getNextPageParamevaluateslastPage.length < pageSizewithpageSize = 100against pages that were fetched at 20 rows, returnsundefined, andhasNextPagegoes false — "Load More" disappears while older history still exists.enabledgate is false — React Query observers set options regardless ofenabled; the flag only gates fetching. So the mis-share applies whenever the drawer is open at all, not only when the Director secret-plot feature is active.Code locations (current staging):
packages/client/src/components/chat/ChatSettingsDrawer.tsx:1650—secretPlotMessagesQuery = useChatMessages(chat.id, 100, open && directorActive && supportsNarrativeDirectorSecretPlot && narrativeDirectorSecretPlotEnabled)packages/client/src/hooks/use-chats.ts:270—useChatMessageskeys onchatKeys.messages(chatId)only;pageSizelives in thequeryFn/getNextPageParamclosures, not the keypackages/client/src/components/chat/ChatArea.tsx:749— transcript observer atmessagesPerPage;packages/client/src/features/tracker-panel/hooks/use-tracker-panel-model.ts:74— third observer at 20Steps to reproduce
limit=100pages instead of 20, and "Load More" can vanish although older history exists. Close the drawer and force another refetch: behavior returns to 20 after the transcript re-renders.Environment
fcf26892d) — mechanics unchanged on currentmainLogs, screenshots, or video
Found by code analysis during the #4703 investigation (two independent review passes against the installed
@tanstack/query-core@5.100.9confirmed the last-observer-wins options behavior); the pagination consequences follow directly fromgetNextPageParam'slastPage.length < pageSizegate. To be explicit: this is not what caused the reporter's traffic in #4703 (that was a third-party personal extension issuing its own fetches) — it is a latent mis-share the investigation surfaced.Additional context
The codebase already documents the correct pattern for exactly this trap:
useChatMessagePeek(use-chats.ts:303-309) deliberately uses a separate query key including its limit, with a comment explaining that the shared messages key "ignores page size." The natural fix is to move the secret-plot reader onto its own key the same way (it only ever wants the newest ~100 messages as one page — it never paginates), leaving the shared infinite query with a single page-size owner per surface pair (transcript + tracker both derive from settings/20-row pages).Happy to take this one — it's adjacent to the #4703 amplifier work in PR #4719.
Template check