[PR #4725] [MERGED] fix(client): move the secret-plot reader off the shared chat-messages query #6479

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4725
Author: @kolacheee
Created: 8/7/2026
Status: ✅ Merged
Merged: 8/7/2026
Merged by: @kolacheee

Base: staging ← Head: fix/4721-secret-plot-query-key


📝 Commits (1)

  • d4a1aca fix(client): move the secret-plot reader off the shared chat-messages query

📊 Changes

4 files changed (+59 additions, -6 deletions)

View changed files

📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+10 -4)
📝 packages/client/src/hooks/use-chats.ts (+13 -2)
📝 packages/client/src/hooks/use-generate.ts (+4 -0)
📝 scripts/regressions/open-issues.regression.ts (+32 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #4721

Why this change

  • The chat transcript's infinite query keys only by chat id — its page size lives in the query's option closures (queryFn, getNextPageParam), not in the key. React Query keeps one options set per key, and the last observer to render wins. The Chat Settings drawer's Director secret-plot reader mounted a second observer on that same key with a hardcoded pageSize: 100, so while the drawer was open (its enabled gate doesn't matter — observers write options regardless), transcript refetches fetched 100-row pages regardless of the user's messages-per-page, ChatArea's defensive trim then discarded the surplus rows, and hasNextPage mis-evaluated (lastPage.length < 100 for 20-row pages → undefined) — hiding Load More while older history still existed.

What changed

  • ChatSettingsDrawer.tsx: the secret-plot reader now uses useChatMessagePeek(chat.id, 100, …) — the existing limit-keyed, read-only newest-window hook (same endpoint and window, key includes the limit so different windows can never share options). No new machinery; the panel consumes the same newest-100 messages as before. A comment at the call site documents why the shared key is off-limits for feature readers.
  • use-chats.ts: the peek hook's doc comment now covers both directions of the trap — writing a short window into the shared key and merely observing it with a different page size.
  • open-issues.regression.ts: a source-scan pin — the drawer must not observe the shared messages query, the secret-plot reader must go through the limit-keyed peek, and the peek's key must keep including its limit.
  • Peek liveness (from this change's adversarial review): the peek caches were invalidated nowhere, so a message landing while a peek consumer stayed mounted (desktop generation continuing under the non-modal drawer) would leave the secret-plot panel one turn behind — and a Regenerate would then anchor forMessageId on the older assistant message, silently re-plotting against truncated history. The authoritative post-generation refresh and the message create/edit/delete mutations now invalidate chatKeys.messagePeek(chatId) alongside chatKeys.messages(chatId) (the sidebar hover peek benefits identically).

The review sweep also confirmed the tracker panel carries the same mis-share (hardcoded pageSize: 20 vs a non-default messages-per-page) — pre-existing and on a different surface, so it's filed separately as #4724 rather than expanded into this PR.

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

Verified on the production build with a 60-message chat at messages-per-page 20 and a fetch-wrapper request counter:

  • The exact defect vector: with Chat Settings open, a stale reconnect refetch of the transcript fires at limit=20 (previously the drawer's 100-closure could own the shared options) with zero limit=100 requests, and Load More stays visible.
  • Load More with the drawer open walks the correct 20-row cursor (before=…|41 → messages 21–40) with no gap.
  • Opening the drawer triggers no message fetches when the secret-plot gate is off.

Still to verify manually (contributor to-do):

  • Manually verify the Director secret-plot panel in a chat with the Director agent active and secret plot enabled: the panel lists recent messages and plot generation still works (the reader now goes through the peek query; same window, same order).

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)

No user-facing docs impact — internal query-wiring fix.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Chat Settings reliability when loading recent secret-plot messages.
    • Ensured newly created, deleted, or updated messages appear promptly in recent-message views.
    • Refreshed recent messages automatically after content generation.
  • Tests

    • Added regression coverage to verify recent-message loading and cache refresh behavior.

🔄 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/4725 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/7/2026 **Status:** ✅ Merged **Merged:** 8/7/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/4721-secret-plot-query-key` --- ### 📝 Commits (1) - [`d4a1aca`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d4a1aca57df0826e75eb51ddf69cee73f2e0dd39) fix(client): move the secret-plot reader off the shared chat-messages query ### 📊 Changes **4 files changed** (+59 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+10 -4) 📝 `packages/client/src/hooks/use-chats.ts` (+13 -2) 📝 `packages/client/src/hooks/use-generate.ts` (+4 -0) 📝 `scripts/regressions/open-issues.regression.ts` (+32 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #4721 ## Why this change - The chat transcript's infinite query keys only by chat id — its page size lives in the query's **option closures** (`queryFn`, `getNextPageParam`), not in the key. React Query keeps one options set per key, and the last observer to render wins. The Chat Settings drawer's Director secret-plot reader mounted a second observer on that same key with a hardcoded `pageSize: 100`, so while the drawer was open (its `enabled` gate doesn't matter — observers write options regardless), transcript refetches fetched 100-row pages regardless of the user's messages-per-page, `ChatArea`'s defensive trim then discarded the surplus rows, and `hasNextPage` mis-evaluated (`lastPage.length < 100` for 20-row pages → `undefined`) — hiding **Load More** while older history still existed. ## What changed - [`ChatSettingsDrawer.tsx`](packages/client/src/components/chat/ChatSettingsDrawer.tsx): the secret-plot reader now uses **`useChatMessagePeek(chat.id, 100, …)`** — the existing limit-keyed, read-only newest-window hook (same endpoint and window, key includes the limit so different windows can never share options). No new machinery; the panel consumes the same newest-100 messages as before. A comment at the call site documents why the shared key is off-limits for feature readers. - [`use-chats.ts`](packages/client/src/hooks/use-chats.ts): the peek hook's doc comment now covers both directions of the trap — writing a short window into the shared key *and* merely observing it with a different page size. - [`open-issues.regression.ts`](scripts/regressions/open-issues.regression.ts): a source-scan pin — the drawer must not observe the shared messages query, the secret-plot reader must go through the limit-keyed peek, and the peek's key must keep including its limit. - **Peek liveness** (from this change's adversarial review): the peek caches were invalidated nowhere, so a message landing while a peek consumer stayed mounted (desktop generation continuing under the non-modal drawer) would leave the secret-plot panel one turn behind — and a Regenerate would then anchor `forMessageId` on the older assistant message, silently re-plotting against truncated history. The authoritative post-generation refresh and the message create/edit/delete mutations now invalidate `chatKeys.messagePeek(chatId)` alongside `chatKeys.messages(chatId)` (the sidebar hover peek benefits identically). The review sweep also confirmed the **tracker panel** carries the same mis-share (hardcoded `pageSize: 20` vs a non-default messages-per-page) — pre-existing and on a different surface, so it's filed separately as #4724 rather than expanded into this PR. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Verified on the production build with a 60-message chat at messages-per-page 20 and a fetch-wrapper request counter: - The exact defect vector: with Chat Settings **open**, a stale reconnect refetch of the transcript fires at **`limit=20`** (previously the drawer's 100-closure could own the shared options) with zero `limit=100` requests, and **Load More stays visible**. - Load More with the drawer open walks the correct 20-row cursor (`before=…|41` → messages 21–40) with no gap. - Opening the drawer triggers no message fetches when the secret-plot gate is off. Still to verify manually (contributor to-do): - Manually verify the Director secret-plot panel in a chat with the Director agent active and secret plot enabled: the panel lists recent messages and plot generation still works (the reader now goes through the peek query; same window, same order). ## Docs and release impact - [x] 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) No user-facing docs impact — internal query-wiring fix. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved Chat Settings reliability when loading recent secret-plot messages. * Ensured newly created, deleted, or updated messages appear promptly in recent-message views. * Refreshed recent messages automatically after content generation. * **Tests** * Added regression coverage to verify recent-message loading and cache refresh behavior. <!-- 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:10:48 +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#6479
No description provided.