[PR #772] [CLOSED] Prevent inconsistent connected chat state #4768

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/772
Author: @aidanbrocklebank
Created: 5/13/2026
Status: ❌ Closed

Base: staging ← Head: aidanbrocklebank/583-fix-inconsistent-connected-chat-state


📝 Commits (10+)

  • 99de5c2 First pass at logic fix
  • ad60a3c Improve comments
  • 3b1d155 Allow manual repair
  • 4d8277c Ensure severed connections are never made in the first place
  • 1c18f65 Merge branch 'main' into aidanbrocklebank/583-fix-inconsistent-connected-chat-state
  • 786354f Add backwards compatibility for legacy scenes
  • 3df2c0f Coderabbit suggestion
  • 0262fef Wrap DB updates in a transaction
  • c538b4d Implement suggestions from Promansis
  • bed46b4 Fix typo

📊 Changes

4 files changed (+73 additions, -28 deletions)

View changed files

📝 packages/client/src/components/chat/ChatRoleplaySurface.tsx (+14 -8)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+6 -2)
📝 packages/server/src/routes/scene.routes.ts (+7 -6)
📝 packages/server/src/services/storage/chats.storage.ts (+46 -12)

📄 Description

Linked issue

Closes #773
References #583

Why this change

  • It is currently possible to get into an inconsistent state, where two chats disagree on whether they are connected or not. Most obviously this happens when a conversation with a connected RP creates a scene, which replaces the convo->RP link but leaves the RP->convo link, thus creating an inconsistency.

What changed

Change to chats.storage.ts

This PR prevents chat connections from accidentally ending up in an inconsistent state. That is, the function connectChats now first calls disconnectChat on both of the given chats, so we don't end up with any one-way connections. The disconnectChat function is also adjusted to ensure it never accidentally creates an unreciprocated connection by deleting only one side.

Note that connectChats now also wipes notes and OOC influences for both sides, before creating the new link.

Change to ChatRoleplaySurface.tsx and scene.routes.ts

To prevent scenes from (trying to) create such a severed relationship between the conversation that created the scene, and the original RP chat it was connected to, I've adjusted the scene RP chat to use chatMeta.sceneOriginChatId instead of chat.connectedChatId to identify the linked conversation. This preserves the UI functionality for the scene (e.g. the switcher button in the scene takes you to the conversation) while fixing it for the conversation (e.g. the convo doesn't lose it's switcher button pointing to the original RP chat).

Change in ChatSettingsDrawer.tsx

This change allows users to manually fix any chat connections which had become inconsistent, by showing the RP chat which points at the current conversation as a valid target for said conversation's connection.

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

  • I created a new conversation linked to an RP.
  • I prompted that conversation to create a scene.
  • The scene no longer replaced the existing connection, meaning the convo was still linked to the original RP.
  • The scene's chat page still referenced the convo chat.
  • I was also able to re-point a convo to the RP which it had been originally connected to, but had (before writing this change) been severed from by the creation of a scene.

Docs and release impact

  • No docs changes needed

UI evidence (if applicable)

Summary by CodeRabbit

  • Bug Fixes

    • Safer reconnects: disconnects are now conditional to avoid accidentally severing unrelated links and preserve linked chat data.
    • Settings pickers now allow repairing chats that already point back to the current chat.
  • New Features

    • Linked-chat toolbar button appears only when a linked chat exists, shows its name, and navigates to it across layouts.
    • Scene creation/navigation now relies on scene metadata to avoid overwriting existing roleplay links.

Review Change Stack


🔄 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/772 **Author:** [@aidanbrocklebank](https://github.com/aidanbrocklebank) **Created:** 5/13/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `aidanbrocklebank/583-fix-inconsistent-connected-chat-state` --- ### 📝 Commits (10+) - [`99de5c2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/99de5c22ebc41f54faca3d584a18f91ef106d110) First pass at logic fix - [`ad60a3c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ad60a3c6e158fcc8d1fcf3d07fd46bc868d3779b) Improve comments - [`3b1d155`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3b1d155a3fe778506d8c83cf3a65164f286bf80f) Allow manual repair - [`4d8277c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4d8277c164027b9c8526148df1d81d26e3548dfc) Ensure severed connections are never made in the first place - [`1c18f65`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1c18f6519b7b903a88c783ff04b7082f1ac99142) Merge branch 'main' into aidanbrocklebank/583-fix-inconsistent-connected-chat-state - [`786354f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/786354fd9593a65524207466902a13472b1a6e01) Add backwards compatibility for legacy scenes - [`3df2c0f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3df2c0f26d298a49dbdc5c192a883d14cacc41a5) Coderabbit suggestion - [`0262fef`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0262fef9de9c428f9d74dba9c7004630ab6cba78) Wrap DB updates in a transaction - [`c538b4d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c538b4d3937711ba4e2f3f739c098949e2627119) Implement suggestions from Promansis - [`bed46b4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bed46b46ad87437657c04c841403b750b9f86fe1) Fix typo ### 📊 Changes **4 files changed** (+73 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatRoleplaySurface.tsx` (+14 -8) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+6 -2) 📝 `packages/server/src/routes/scene.routes.ts` (+7 -6) 📝 `packages/server/src/services/storage/chats.storage.ts` (+46 -12) </details> ### 📄 Description ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> Closes #773 References #583 ## Why this change <!-- What user problem, bug, or goal does this solve? --> - It is currently possible to get into an inconsistent state, where two chats disagree on whether they are connected or not. Most obviously this happens when a conversation with a connected RP creates a scene, which replaces the convo->RP link but leaves the RP->convo link, thus creating an inconsistency. ## What changed ### Change to `chats.storage.ts` This PR prevents chat connections from accidentally ending up in an inconsistent state. That is, the function `connectChats` now first calls `disconnectChat` on both of the given chats, so we don't end up with any one-way connections. The `disconnectChat` function is also adjusted to ensure it never accidentally creates an unreciprocated connection by deleting only one side. Note that `connectChats` now also wipes notes and OOC influences for both sides, before creating the new link. ### Change to `ChatRoleplaySurface.tsx` and `scene.routes.ts` To prevent scenes from (trying to) create such a severed relationship between the conversation that created the scene, and the original RP chat it was connected to, I've adjusted the scene RP chat to use `chatMeta.sceneOriginChatId` instead of `chat.connectedChatId` to identify the linked conversation. This preserves the UI functionality for the scene (e.g. the switcher button in the scene takes you to the conversation) while fixing it for the conversation (e.g. the convo doesn't lose it's switcher button pointing to the original RP chat). ### Change in `ChatSettingsDrawer.tsx` This change allows users to manually fix any chat connections which had become inconsistent, by showing the RP chat which points at the current conversation as a valid target for said conversation's connection. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [x] `pnpm check` passes locally - [ ] 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 <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ⚠️ If an AI agent filled out or ticked these boxes for you, treat them --> <!-- as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> - I created a new conversation linked to an RP. - I prompted that conversation to create a scene. - The scene no longer replaced the existing connection, meaning the convo was still linked to the original RP. - The scene's chat page still referenced the convo chat. - I was also able to re-point a convo to the RP which it had been originally connected to, but had (before writing this change) been severed from by the creation of a scene. ## Docs and release impact - [x] No docs changes needed ## UI evidence (if applicable) <!-- Add before/after screenshots or recordings for UI changes --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Safer reconnects: disconnects are now conditional to avoid accidentally severing unrelated links and preserve linked chat data. * Settings pickers now allow repairing chats that already point back to the current chat. * **New Features** * Linked-chat toolbar button appears only when a linked chat exists, shows its name, and navigates to it across layouts. * Scene creation/navigation now relies on scene metadata to avoid overwriting existing roleplay links. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/772) <!-- review_stack_entry_end --> <!-- 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-22 04:10:29 +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#4768
No description provided.