mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5650] [MERGED] fix(client): stop stale server snapshots reverting newer chat metadata edits #6865
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#6865
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5650
Author: @kolacheee
Created: 8/29/2026
Status: ✅ Merged
Merged: 8/29/2026
Merged by: @kolacheee
Base:
staging← Head:fix/5641-guarded-cache-writers📝 Commits (5)
e9738bdfix(client): stop stale server snapshots reverting newer chat metadata edits1763a3ctest(e2e): make the stale-echo pin robust and add the changelog entry0f60d13fix(client): address the verification findings on the snapshot guard5b77ae8fix(client): mirror guarded game snapshots into the active-chat store9cd9ac2fix(client): only fall back to activeChat when no chat is selected📊 Changes
9 files changed (+274 additions, -27 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
e2e/core-flows.e2e.ts(+152 -0)📝
packages/client/src/components/chat/HomeProfessorMariChat.tsx(+4 -0)📝
packages/client/src/components/game/GameSurface.tsx(+10 -2)📝
packages/client/src/hooks/use-background-autonomous.ts(+6 -2)📝
packages/client/src/hooks/use-chat-presets.ts(+4 -3)📝
packages/client/src/hooks/use-chats.ts(+60 -11)📝
packages/client/src/hooks/use-connections.ts(+3 -2)📝
packages/client/src/hooks/use-game.ts(+34 -7)📄 Description
Closes #5641
Why
The per-field metadata version guard lived only inside
useUpdateChatMetadata. Every other mutation wrote its response chat back into the caches raw — so a response produced before a metadata edit but consumed after it replaced the whole cached chat, flipping the just-edited field back and unmounting the settings section it gates. With a refetch pending the flicker was brief; without one, the revert stuck until reload. The auto-fired autonomous-unread clear makes this reachable with completely ordinary behavior: open a chat with unread residue, toggle a setting while the clear round trip is in flight, and the toggle silently reverts. (Found during the #5636/#5640 verification pass.)The fix
guardServerChatSnapshot(qc, chat, versionAtRequest)prepares any server snapshot for a cache write: metadata merges through the same per-field version guarduseUpdateChatMetadatauses, keyed on a version captured when the request was issued — fields the user edited after that moment keep their local values; non-metadata fields stay server-authoritative; each writer keeps its original write target.Converted writers: the chat PATCH (
useUpdateChat, including its group-cache branch-selector patch), summary entries, the autonomous-unread clear, preset apply, the connection-delete chat detach, the background autonomous-unread mark, and the three per-chat game mutations (campaign progression, recruit, remove). The JSON-repair apply callback guards at version 0 (its request is issued by the shared repair flow, no pre-request snapshot exists) and relies on its existing immediate invalidation. Deliberately left raw, documented in place: game session-start and the Professor Mari load/switch writes — they target chats whose ids are unknown before the request, with no concurrent edits to protect.One deletion-semantics case needed special handling (caught by the adversarial pass): the server clears unread state by deleting the metadata keys, so its response omits them and a merge would keep the cached residue forever — leaving a phantom unread count that refired a no-op clear on every switch back to the chat. That writer explicitly drops the three
autonomousUnread*keys from the guarded result; nothing client-side ever patches them, so no field version can legitimately outrank their deletion.The e2e pin
New test:
chat settings survive a stale autonomous-unread echo. It seeds unread residue, lets the app's auto-clear fire, forwards the DELETE to the server immediately but holds its response, toggles Secret Plot on through the UI, confirms the server saved it, releases the stale echo, and asserts the toggle and its gated section survive — with the ordering pinned at every step (server-processed-before-toggle via the route state, browser-side response event before asserting, and a re-assert after a beat so a late-consumed echo can't slip past).A/B on the final code: with the client fix reverted the test fails at the post-echo toggle assertion (
Expected: checked, Received: unchecked— the revert, reproduced deterministically); with the fix, green 3/3 (--retries=0).Getting the pin deterministic surfaced two reusable e2e lessons, both now encoded in the test: the sr-only switch inputs pass
toBeCheckedbut hangcheck()forever (toggle through the visible label), and a test that times out with a route handler parked on a held promise hangs teardown and wedges every subsequent local run (thefinallyreleases the hold andunrouteAll({ behavior: "ignoreErrors" })).Verification
useUpdateChatthat undid the guarded write (both fixed), and had the dead context fallbacks aligned to the conservative direction (?? 0).pnpm checkgreen (includes the e2e type lane).Notes
Summary by CodeRabbit
Bug Fixes
Tests
Documentation
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.