[PR #818] [MERGED] Fix tracker custom edit persistence #4789

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

📋 Pull Request Information

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

Base: main ← Head: fix/tracker-custom-edits-persist


📝 Commits (7)

  • 5c57b22 Fix tracker custom edit persistence
  • 8f6fab6 Keep tracker saves bound to swipes
  • 9bd338a Fix tracker regen baseline state
  • f8b0581 Merge origin/main into tracker custom edits
  • 3c4f627 Fix tracker snapshot fallback races
  • 300050a Address tracker review findings
  • aed6574 Address tracker nitpick review

📊 Changes

16 files changed (+1792 additions, -259 deletions)

View changed files

📝 packages/client/src/components/chat/ChatArea.tsx (+107 -20)
📝 packages/client/src/components/chat/ChatInput.tsx (+1 -1)
📝 packages/client/src/components/chat/ConversationInput.tsx (+1 -1)
📝 packages/client/src/components/chat/RoleplayHUD.tsx (+3 -2)
📝 packages/client/src/components/layout/tracker-data-sidebar/TrackerDataSidebar.tsx (+6 -3)
📝 packages/client/src/hooks/use-game-state-patcher.ts (+153 -40)
📝 packages/client/src/hooks/use-generate.ts (+72 -24)
📝 packages/client/src/stores/game-state.store.ts (+23 -1)
📝 packages/server/src/routes/chats.routes.ts (+61 -44)
📝 packages/server/src/routes/generate.routes.ts (+74 -75)
📝 packages/server/src/routes/generate/dry-run-route.ts (+23 -24)
📝 packages/server/src/routes/generate/generate-route-utils.ts (+53 -0)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+45 -15)
📝 packages/server/src/services/storage/chats.storage.ts (+16 -0)
📝 packages/server/src/services/storage/game-state.storage.ts (+116 -9)
➕ packages/server/test/tracker-custom-edits-persist.test.ts (+1038 -0)

📄 Description

Linked issue

No linked issue; tracks a user-reported Tracker panel / GM HUD persistence bug.

Why this change

Custom tracker edits made during an active RP/GM session could appear saved in the HUD or Tracker panel, then fall back to an older generated tracker snapshot after reload, regenerate, rerun, or swipe changes. That made mid-playthrough tracker tuning unreliable, especially when inactive swipes had newer tracker rows than the currently visible assistant message.

What changed

  • Prefer the HUD-visible active-swipe tracker snapshot for no-user-turn flows such as continue/autonomous, impersonate, retry-agents, prompt preview fallback, and dry-run context.
  • Treat regenerate/swipe of an existing assistant as the exception: prompt context uses the previous assistant's active-swipe tracker snapshot, excluding the target assistant's own output snapshots, while the newly generated tracker data still saves onto the target message/swipe.
  • Keep committed tracker snapshots authoritative after real user turns, while avoiding chronological "latest row wins" when an inactive swipe is newer than the visible one.
  • Refresh roleplay tracker game state when assistant swipes change or are deleted, with an active-chat guard before writing the shared game-state store.
  • Flush pending Tracker panel / HUD game-state edits before tracker reruns, generation, swipe switches, and swipe deletion.
  • Bind debounced tracker saves to the message/swipe that was visible when the edit was queued, so a delayed save cannot land on a newly selected swipe.
  • Limit chat input message-cache subscriptions to real query updates so opening the Tracker panel does not trigger React render-time state update warnings.
  • Add server regression coverage for custom tracker edits, active visible snapshots, inactive-newer-swipe traps, queued saves that flush after a swipe change, and regenerate baseline context.

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

  • pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/tracker-custom-edits-persist.test.ts (8 tests)
  • pnpm --filter @marinara-engine/server test
  • pnpm check
  • Luka-style Chromium smoke on isolated temp data:
    • Edited a custom tracker value in the Tracker panel.
    • Confirmed the API saved the edited active-swipe value.
    • Reloaded the chat and confirmed the edited value persisted.
    • Switched to an inactive newer swipe and confirmed its separate tracker value displayed.
    • Switched back to the original swipe and confirmed the edited value returned.
    • Reopened the Tracker panel after the input subscription fix and confirmed there were no fresh browser console errors.
  • Follow-up Chromium smoke on isolated temp data:
    • Queued a custom tracker edit while the second swipe was visible.
    • Switched to the first swipe before the debounced save flushed.
    • Flushed the pending save and confirmed the first swipe kept its own tracker value.
    • Switched back to the second swipe and confirmed the queued edit persisted there.
  • Follow-up server regression:
    • Confirmed regenerate prompt/agent context uses the previous assistant tracker snapshot, not either existing target swipe snapshot.
    • Confirmed the new regenerated swipe clone fallback starts from the same previous-assistant baseline.
  • Bunny review follow-up fixes:
    • Serialized active-swipe mutations per message.
    • Scoped tracker refresh state to the active chat.
    • Cancelled/discarded matching in-flight tracker PATCHes and deduped post-generation refreshes.
    • Bounded regenerate fallback snapshots before the target assistant.
    • Reused one selected tracker snapshot for GM prompt, lorebook, tracker injection, and agent context.
    • Preserved manual override metadata when a targeted edit creates a fresh swipe snapshot.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Behavioral UI change verified in Chromium smoke testing; no visual styling change.


🔄 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/818 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 5/14/2026 **Status:** ✅ Merged **Merged:** 5/14/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `main` ← **Head:** `fix/tracker-custom-edits-persist` --- ### 📝 Commits (7) - [`5c57b22`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5c57b223b14dda9e793506037ff4a55a7d3a38fb) Fix tracker custom edit persistence - [`8f6fab6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8f6fab6bb965e445d9db54e61db734e8a2b2b03b) Keep tracker saves bound to swipes - [`9bd338a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9bd338a28bd3635239c9688a18d204402015b814) Fix tracker regen baseline state - [`f8b0581`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f8b05814e5b1bc41a24b4a4bd3fce0af57bdf686) Merge origin/main into tracker custom edits - [`3c4f627`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3c4f627997567fb59a0a6a43539ee40a3700b51e) Fix tracker snapshot fallback races - [`300050a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/300050a59c77776b5ae29bda3a52402b79c2284b) Address tracker review findings - [`aed6574`](https://github.com/Pasta-Devs/Marinara-Engine/commit/aed6574294eaf5d77c3d232b3cde9c8ad5f43dbe) Address tracker nitpick review ### 📊 Changes **16 files changed** (+1792 additions, -259 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatArea.tsx` (+107 -20) 📝 `packages/client/src/components/chat/ChatInput.tsx` (+1 -1) 📝 `packages/client/src/components/chat/ConversationInput.tsx` (+1 -1) 📝 `packages/client/src/components/chat/RoleplayHUD.tsx` (+3 -2) 📝 `packages/client/src/components/layout/tracker-data-sidebar/TrackerDataSidebar.tsx` (+6 -3) 📝 `packages/client/src/hooks/use-game-state-patcher.ts` (+153 -40) 📝 `packages/client/src/hooks/use-generate.ts` (+72 -24) 📝 `packages/client/src/stores/game-state.store.ts` (+23 -1) 📝 `packages/server/src/routes/chats.routes.ts` (+61 -44) 📝 `packages/server/src/routes/generate.routes.ts` (+74 -75) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+23 -24) 📝 `packages/server/src/routes/generate/generate-route-utils.ts` (+53 -0) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+45 -15) 📝 `packages/server/src/services/storage/chats.storage.ts` (+16 -0) 📝 `packages/server/src/services/storage/game-state.storage.ts` (+116 -9) ➕ `packages/server/test/tracker-custom-edits-persist.test.ts` (+1038 -0) </details> ### 📄 Description ## Linked issue No linked issue; tracks a user-reported Tracker panel / GM HUD persistence bug. ## Why this change Custom tracker edits made during an active RP/GM session could appear saved in the HUD or Tracker panel, then fall back to an older generated tracker snapshot after reload, regenerate, rerun, or swipe changes. That made mid-playthrough tracker tuning unreliable, especially when inactive swipes had newer tracker rows than the currently visible assistant message. ## What changed - Prefer the HUD-visible active-swipe tracker snapshot for no-user-turn flows such as continue/autonomous, impersonate, retry-agents, prompt preview fallback, and dry-run context. - Treat regenerate/swipe of an existing assistant as the exception: prompt context uses the previous assistant's active-swipe tracker snapshot, excluding the target assistant's own output snapshots, while the newly generated tracker data still saves onto the target message/swipe. - Keep committed tracker snapshots authoritative after real user turns, while avoiding chronological "latest row wins" when an inactive swipe is newer than the visible one. - Refresh roleplay tracker game state when assistant swipes change or are deleted, with an active-chat guard before writing the shared game-state store. - Flush pending Tracker panel / HUD game-state edits before tracker reruns, generation, swipe switches, and swipe deletion. - Bind debounced tracker saves to the message/swipe that was visible when the edit was queued, so a delayed save cannot land on a newly selected swipe. - Limit chat input message-cache subscriptions to real query updates so opening the Tracker panel does not trigger React render-time state update warnings. - Add server regression coverage for custom tracker edits, active visible snapshots, inactive-newer-swipe traps, queued saves that flush after a swipe change, and regenerate baseline context. ## Validation - [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 - `pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/tracker-custom-edits-persist.test.ts` (8 tests) - `pnpm --filter @marinara-engine/server test` - `pnpm check` - Luka-style Chromium smoke on isolated temp data: - Edited a custom tracker value in the Tracker panel. - Confirmed the API saved the edited active-swipe value. - Reloaded the chat and confirmed the edited value persisted. - Switched to an inactive newer swipe and confirmed its separate tracker value displayed. - Switched back to the original swipe and confirmed the edited value returned. - Reopened the Tracker panel after the input subscription fix and confirmed there were no fresh browser console errors. - Follow-up Chromium smoke on isolated temp data: - Queued a custom tracker edit while the second swipe was visible. - Switched to the first swipe before the debounced save flushed. - Flushed the pending save and confirmed the first swipe kept its own tracker value. - Switched back to the second swipe and confirmed the queued edit persisted there. - Follow-up server regression: - Confirmed regenerate prompt/agent context uses the previous assistant tracker snapshot, not either existing target swipe snapshot. - Confirmed the new regenerated swipe clone fallback starts from the same previous-assistant baseline. - Bunny review follow-up fixes: - Serialized active-swipe mutations per message. - Scoped tracker refresh state to the active chat. - Cancelled/discarded matching in-flight tracker PATCHes and deduped post-generation refreshes. - Bounded regenerate fallback snapshots before the target assistant. - Reused one selected tracker snapshot for GM prompt, lorebook, tracker injection, and agent context. - Preserved manual override metadata when a targeted edit creates a fresh swipe snapshot. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) Behavioral UI change verified in Chromium smoke testing; no visual styling change. --- <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:40 +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#4789
No description provided.