[PR #1542] [MERGED] Fix roleplay background metadata sync #5120

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1542
Author: @Xelvanis
Created: 5/29/2026
Status: ✅ Merged
Merged: 5/29/2026
Merged by: @Xelvanis

Base: refactor ← Head: fix/issue-1508-roleplay-background-clear


📝 Commits (2)

  • b12d725 Fix chat background metadata sync
  • 8773d2c Harden background metadata debounce

📊 Changes

2 files changed (+223 additions, -17 deletions)

View changed files

➕ src/features/modes/shared/chat-ui/hooks/use-chat-metadata-sync.test.tsx (+183 -0)
📝 src/features/modes/shared/chat-ui/hooks/use-chat-metadata-sync.ts (+40 -17)

📄 Description

Linked issue

Closes #1508

Why this change

  • Roleplay could keep showing the previous chat background after switching to a chat or branch whose metadata has no background.
  • The live metadata restore path only ran on chat id changes, so delayed metadata hydration could leave the UI store stuck on the previous background until reload.

What changed

  • Restore chat background UI state when the active chat's background metadata safely changes, not only when the chat id changes.
  • Preserve local pending background changes when stale metadata refreshes arrive.
  • Track background persistence debounce timers per chat so one chat's pending write does not cancel another chat's write.
  • Added focused hook coverage for stale-null hydration, delayed background hydration, stale metadata refreshes, reverted changes, caught-up metadata, and two-chat debounce isolation.

Refactor impact

Primary owner:

  • Shared mode UI: src/features/modes/shared/chat-ui/hooks/use-chat-metadata-sync.ts

Impact areas reviewed:

  • Roleplay mode background restore path from issue #1508.
  • Shared hook consumers in Conversation, Roleplay, and Game mode routes.
  • UI-store background state and chat metadata persistence debounce behavior.

Boundary notes:

  • No engine, shared API, Tauri/Rust, storage schema, provider, or remote-runtime boundary changes.
  • The fix stays inside shared mode UI and uses the existing catalog metadata mutation hook.

Pressure points touched:

  • Shared mode UI metadata hook. No ModeSurface, GameSurface, src-tauri/src/lib.rs, or import module changes.

Validation

  • pnpm check passes locally
  • pnpm typecheck passes locally
  • pnpm build passes locally
  • pnpm check:architecture passes locally
  • pnpm check:docs passes locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace passes locally
  • Rust clippy/tests were run for Rust behavior changes
  • Browser or Tauri app manual verification completed
  • Playwright, screenshot, or recording evidence added for UI changes
  • Remote runtime smoke checked when relevant

Manual verification notes

Automated validation run locally:

  • pnpm vitest run src/features/modes/shared/chat-ui/hooks/use-chat-metadata-sync.test.tsx passed, 6 tests.
  • pnpm typecheck passed.
  • pnpm check:architecture passed.
  • git diff --check origin/refactor...HEAD -- . ':(exclude)graphify-out/**' passed.

Manual native Tauri branch-switch QA is still needed for the exact issue reproduction.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

Notes: no CHANGELOG.md exists on this checkout; no docs were changed because this is a narrow UI state bugfix.

UI evidence

No new screenshots attached. The original issue includes local repro screenshots; this PR adds focused hook regression coverage and still needs a native manual UI confirmation pass.

Summary by CodeRabbit

  • Tests

    • Added test coverage for chat background synchronization behaviors.
  • Bug Fixes

    • Improved chat background persistence to better handle metadata updates and prevent local changes from being lost during synchronization.

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/1542 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 5/29/2026 **Status:** ✅ Merged **Merged:** 5/29/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/issue-1508-roleplay-background-clear` --- ### 📝 Commits (2) - [`b12d725`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b12d725f088383c005c5916422851f92b42f3416) Fix chat background metadata sync - [`8773d2c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8773d2c8d2ddd1a8caa2a8712c990591521eab3e) Harden background metadata debounce ### 📊 Changes **2 files changed** (+223 additions, -17 deletions) <details> <summary>View changed files</summary> ➕ `src/features/modes/shared/chat-ui/hooks/use-chat-metadata-sync.test.tsx` (+183 -0) 📝 `src/features/modes/shared/chat-ui/hooks/use-chat-metadata-sync.ts` (+40 -17) </details> ### 📄 Description ## Linked issue Closes #1508 ## Why this change - Roleplay could keep showing the previous chat background after switching to a chat or branch whose metadata has no background. - The live metadata restore path only ran on chat id changes, so delayed metadata hydration could leave the UI store stuck on the previous background until reload. ## What changed - Restore chat background UI state when the active chat's background metadata safely changes, not only when the chat id changes. - Preserve local pending background changes when stale metadata refreshes arrive. - Track background persistence debounce timers per chat so one chat's pending write does not cancel another chat's write. - Added focused hook coverage for stale-null hydration, delayed background hydration, stale metadata refreshes, reverted changes, caught-up metadata, and two-chat debounce isolation. ## Refactor impact Primary owner: - Shared mode UI: `src/features/modes/shared/chat-ui/hooks/use-chat-metadata-sync.ts` Impact areas reviewed: - Roleplay mode background restore path from issue #1508. - Shared hook consumers in Conversation, Roleplay, and Game mode routes. - UI-store background state and chat metadata persistence debounce behavior. Boundary notes: - No engine, shared API, Tauri/Rust, storage schema, provider, or remote-runtime boundary changes. - The fix stays inside shared mode UI and uses the existing catalog metadata mutation hook. Pressure points touched: - Shared mode UI metadata hook. No `ModeSurface`, `GameSurface`, `src-tauri/src/lib.rs`, or import module changes. ## Validation - [ ] `pnpm check` passes locally - [ ] `pnpm typecheck` passes locally - [ ] `pnpm build` passes locally - [ ] `pnpm check:architecture` passes locally - [ ] `pnpm check:docs` passes locally - [ ] `cargo check --manifest-path src-tauri/Cargo.toml --workspace` passes locally - [ ] Rust clippy/tests were run for Rust behavior changes - [ ] Browser or Tauri app manual verification completed - [ ] Playwright, screenshot, or recording evidence added for UI changes - [ ] Remote runtime smoke checked when relevant ### Manual verification notes Automated validation run locally: - `pnpm vitest run src/features/modes/shared/chat-ui/hooks/use-chat-metadata-sync.test.tsx` passed, 6 tests. - `pnpm typecheck` passed. - `pnpm check:architecture` passed. - `git diff --check origin/refactor...HEAD -- . ':(exclude)graphify-out/**'` passed. Manual native Tauri branch-switch QA is still needed for the exact issue reproduction. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims Notes: no `CHANGELOG.md` exists on this checkout; no docs were changed because this is a narrow UI state bugfix. ## UI evidence No new screenshots attached. The original issue includes local repro screenshots; this PR adds focused hook regression coverage and still needs a native manual UI confirmation pass. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added test coverage for chat background synchronization behaviors. * **Bug Fixes** * Improved chat background persistence to better handle metadata updates and prevent local changes from being lost during synchronization. <!-- 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/1542?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- 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:13: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#5120
No description provided.