[PR #5621] [MERGED] feat(client): send the owning chatId on the id-only endpoints #6851

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

📋 Pull Request Information

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

Base: staging ← Head: feat/5615-client-chatid-hints


📝 Commits (1)

  • dabfd67 feat(client): send the owning chatId on the id-only endpoints

📊 Changes

6 files changed (+43 additions, -19 deletions)

View changed files

📝 packages/client/src/components/chat/AgentSuiteModal.tsx (+1 -1)
📝 packages/client/src/components/chat/ChatGallery.tsx (+15 -9)
📝 packages/client/src/components/chat/MariContextViewer.tsx (+1 -1)
📝 packages/client/src/hooks/use-agents.ts (+4 -2)
📝 packages/client/src/hooks/use-gallery.ts (+17 -4)
📝 packages/client/src/hooks/use-mari-workspace-context.ts (+5 -2)

📄 Description

Closes #5615. The client half of the #5592 close-out: #5614 taught the id-only endpoints to accept an optional owning-chat hint; this makes the client send it, closing the last cold paths that could convert a lazy table to permanently fully-resident.

What changed

Three of the four endpoints get their hint (all pure packages/client/ changes; the server treats a missing value exactly as before, so this is safe to ship independently):

  • DELETE /gallery/:id now carries ?chatId= — and the value is the image row's own chatId, not the open chat. That distinction is load-bearing: a Game-mode gallery aggregates images from sibling game sessions into one list, so the open chat is the wrong owner for those rows, and a wrong hint 404s the delete. The useDeleteGalleryImage mutation widened from a bare id to { imageId, chatId }; the hook's ambient chatId stays as-is for the react-query cache keys (that's what the list queries are keyed on — the two ids serve different purposes and legitimately differ).
  • DELETE /professor-mari-workspace/context/:id now carries ?chatId= from the context item row's own chatId (the owning workspace chat — deliberately not sourceChatId, which is the chat the slice was copied from). Same mutation-widening pattern.
  • PATCH /agents/runs/:runId now sends chatId in the body. The mutation variables already carried it (for cache invalidation) — it was just never put on the wire. Also switched AgentSuiteModal's call from the ambient chat.id to the row's own run.chatId, matching the pattern RoleplayHUDActionsMenu already used; they're equal today (the runs list is chat-scoped), but the row's own field survives any future cross-chat runs view.

The fourth endpoint (DELETE /game/checkpoint/:id) has no client caller at all — verified by exhaustive search, there is no checkpoint-management UI yet. The server-side hint is already wired (#5614); whenever a checkpoint UI is built, its delete call should pass the checkpoint row's chatId from day one. Nothing to change here.

One adjacent (pre-existing) gap fixed alongside, because this PR makes the path it affects explicit: deleting a sibling session's image only invalidated the open chat's gallery caches, so the sibling's own cached list kept showing the deleted image for up to its 5-minute stale window. onSettled now also invalidates the owner chat's keys when they differ.

Why wrong-owner matters (and why this is still just a perf change)

The server uses the hint purely to scope the storage lookup to one chat's shard instead of loading every chat's — it is not an authorization check. Sending it wrong yields a 404 (nothing acts); omitting it falls back to today's unscoped lookup. So every threaded value here is taken from the resource row itself wherever the surface can display cross-chat rows.

Validation done

  • Full pnpm check ✅ (guard, localization, prettier, client+server lint/type checks, production build)
  • Verified no regression-lane or e2e source-pattern pins reference the changed call sites (the lanes that read these files pin unrelated things)
  • An independent verification pass reviewed the diff for owner-identity mistakes across every reachable render path — all clean, including an empirical Fastify query-string round-trip test for exotic ids, confirmation that the agents PATCH schema accepts the new field (no .strict()), and confirmation these three are the complete set of client-reachable hint-bearing routes. It also corrected one of my own audit notes: the pinImage({ ...image, chatId }) pattern is deliberate (pinned-media chatId means "pinned to this chat", filtered by the active chat), so no follow-up issue is warranted there.

Manually verify

  • Delete a gallery image from a normal chat and from a Game-mode chat whose gallery shows sibling-session images (both should delete; watch the request for ?chatId=)
  • Remove an attached context item in the Professor Mari Context Viewer
  • Edit a custom agent run's output in the Agent Suite panel and in the Roleplay HUD agents menu
  • On a MARINARA_MAX_RESIDENT_CHATS install, confirm none of these actions logs Lazy table … is now fully resident

Summary by CodeRabbit

  • Bug Fixes
    • Edited agent responses are now saved to the correct conversation.
    • Deleting images from the gallery now consistently removes them from their owning conversation, including batch deletions.
    • Removing workspace context items now targets the correct conversation.
    • Improved synchronization of galleries, assets, and context after changes across conversations.

🔄 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/5621 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/29/2026 **Status:** ✅ Merged **Merged:** 8/29/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/5615-client-chatid-hints` --- ### 📝 Commits (1) - [`dabfd67`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dabfd67e6cf11144213a4e1673be2dc16cded67d) feat(client): send the owning chatId on the id-only endpoints ### 📊 Changes **6 files changed** (+43 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/AgentSuiteModal.tsx` (+1 -1) 📝 `packages/client/src/components/chat/ChatGallery.tsx` (+15 -9) 📝 `packages/client/src/components/chat/MariContextViewer.tsx` (+1 -1) 📝 `packages/client/src/hooks/use-agents.ts` (+4 -2) 📝 `packages/client/src/hooks/use-gallery.ts` (+17 -4) 📝 `packages/client/src/hooks/use-mari-workspace-context.ts` (+5 -2) </details> ### 📄 Description Closes #5615. The client half of the #5592 close-out: #5614 taught the id-only endpoints to accept an optional owning-chat hint; this makes the client send it, closing the last cold paths that could convert a lazy table to permanently fully-resident. ## What changed Three of the four endpoints get their hint (all pure `packages/client/` changes; the server treats a missing value exactly as before, so this is safe to ship independently): - **`DELETE /gallery/:id`** now carries `?chatId=` — and the value is the **image row's own `chatId`**, not the open chat. That distinction is load-bearing: a Game-mode gallery aggregates images from sibling game sessions into one list, so the open chat is the *wrong* owner for those rows, and a wrong hint 404s the delete. The `useDeleteGalleryImage` mutation widened from a bare id to `{ imageId, chatId }`; the hook's ambient chatId stays as-is for the react-query cache keys (that's what the list queries are keyed on — the two ids serve different purposes and legitimately differ). - **`DELETE /professor-mari-workspace/context/:id`** now carries `?chatId=` from the context item row's own `chatId` (the owning workspace chat — deliberately *not* `sourceChatId`, which is the chat the slice was copied from). Same mutation-widening pattern. - **`PATCH /agents/runs/:runId`** now sends `chatId` in the body. The mutation variables already carried it (for cache invalidation) — it was just never put on the wire. Also switched `AgentSuiteModal`'s call from the ambient `chat.id` to the row's own `run.chatId`, matching the pattern `RoleplayHUDActionsMenu` already used; they're equal today (the runs list is chat-scoped), but the row's own field survives any future cross-chat runs view. **The fourth endpoint (`DELETE /game/checkpoint/:id`) has no client caller at all** — verified by exhaustive search, there is no checkpoint-management UI yet. The server-side hint is already wired (#5614); whenever a checkpoint UI is built, its delete call should pass the checkpoint row's `chatId` from day one. Nothing to change here. One adjacent (pre-existing) gap fixed alongside, because this PR makes the path it affects explicit: deleting a sibling session's image only invalidated the *open* chat's gallery caches, so the sibling's own cached list kept showing the deleted image for up to its 5-minute stale window. `onSettled` now also invalidates the owner chat's keys when they differ. ## Why wrong-owner matters (and why this is still just a perf change) The server uses the hint purely to scope the storage lookup to one chat's shard instead of loading every chat's — it is **not** an authorization check. Sending it wrong yields a 404 (nothing acts); omitting it falls back to today's unscoped lookup. So every threaded value here is taken from the resource row itself wherever the surface can display cross-chat rows. ## Validation done - Full `pnpm check` ✅ (guard, localization, prettier, client+server lint/type checks, production build) - Verified no regression-lane or e2e source-pattern pins reference the changed call sites (the lanes that read these files pin unrelated things) - An independent verification pass reviewed the diff for owner-identity mistakes across every reachable render path — all clean, including an empirical Fastify query-string round-trip test for exotic ids, confirmation that the agents PATCH schema accepts the new field (no `.strict()`), and confirmation these three are the complete set of client-reachable hint-bearing routes. It also corrected one of my own audit notes: the `pinImage({ ...image, chatId })` pattern is *deliberate* (pinned-media `chatId` means "pinned to this chat", filtered by the active chat), so no follow-up issue is warranted there. ## Manually verify - [ ] Delete a gallery image from a normal chat and from a Game-mode chat whose gallery shows sibling-session images (both should delete; watch the request for `?chatId=`) - [ ] Remove an attached context item in the Professor Mari Context Viewer - [ ] Edit a custom agent run's output in the Agent Suite panel and in the Roleplay HUD agents menu - [ ] On a `MARINARA_MAX_RESIDENT_CHATS` install, confirm none of these actions logs `Lazy table … is now fully resident` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Edited agent responses are now saved to the correct conversation. * Deleting images from the gallery now consistently removes them from their owning conversation, including batch deletions. * Removing workspace context items now targets the correct conversation. * Improved synchronization of galleries, assets, and context after changes across conversations. <!-- 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:14:18 +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#6851
No description provided.