[PR #6954] [MERGED] fix(chat): roll chat variables back with their reply, and ask before removing one #7400

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6954
Author: @SpicyMarinara
Created: 10/1/2026
Status: ✅ Merged
Merged: 10/2/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/variables-sweep


📝 Commits (9)

  • 0ba8243 fix(chat): roll chat variables back with the reply that changed them
  • e282969 fix(chat): ask before removing a chat variable
  • fd82e66 Merge remote-tracking branch 'origin/staging' into fix/variables-sweep
  • 3abd3b7 Merge remote-tracking branch 'origin/staging' into fix/variables-sweep
  • ec58ee7 fix(chat): undo only the visible swipe's variable changes on delete
  • 3006348 Merge remote-tracking branch 'origin/staging' into fix/variables-sweep
  • 6d351de fix(chat): re-apply variable changes from the restored visible swipe
  • fa6e100 Merge remote-tracking branch 'origin/staging' into fix/variables-sweep
  • ddf0053 Merge remote-tracking branch 'origin/staging' into fix/variables-sweep

📊 Changes

10 files changed (+556 additions, -29 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 e2e/chat-variables.e2e.ts (+63 -0)
📝 packages/client/src/features/chat-settings/sections/ChatVariablesSection.tsx (+20 -3)
📝 packages/client/src/localization/locales/en.json (+2 -0)
📝 packages/server/src/routes/generate.routes.ts (+42 -18)
📝 packages/server/src/services/prompt/macro-context.ts (+4 -0)
📝 packages/server/src/services/storage/chats.storage.ts (+91 -8)
📝 packages/server/src/services/storage/message-trash.storage.ts (+15 -0)
📝 packages/shared/src/utils/chat-variables.ts (+67 -0)
➕ scripts/regressions/chat-variable-history.regression.ts (+248 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6942
Closes #6923

Why this change

  • #6942: In Chat Settings → Variables, one stray tap on the trash button deleted a variable for good, which is easy to do on a phone.
  • #6923: Chat variables changed by macros ({{setvar}}, {{decvar}}, {{incvar}}…) didn't go back when you regenerated, swiped or deleted the reply that changed them. A lorebook entry that counts down once per turn kept counting down on every regenerate.

What changed

Removing a variable (#6942)

  • The trash button now asks "Remove "" from this chat?" using the app's existing confirm dialog, the same one the preset variable card uses.
  • Cancel, Escape or tapping outside keeps the variable. The section has no Save button, so confirming is what saves the removal.
  • A brand-new empty row is still removed without asking.

Variables follow their reply (#6923)

  • Each reply now remembers which variables its turn changed, as [before, after] pairs. That's nothing new to configure, and it sits in the reply's extra like other per-reply data.
  • Regenerate: starts from the values before the reply.
  • Delete: puts them back.
  • Restore from the trash: applies them again.
  • Switching swipes: switches to that swipe's values, the same way tracker values and the Game inventory follow swipes.
  • Your own edits win: an undo only happens if the variable still holds the value the reply left. If you changed it since, for example in Chat Settings, your value stays.
  • Old chats: replies saved before this change have no record, so they behave as before.
  • Code: small helpers in shared/utils/chat-variables.ts, a replayVariableChanges storage method, and the generate, delete, swipe and restore paths call them.

Not covered, as before this change: variable writes from "retry agents" after a reply, and generations that end without saving a reply.

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

What I ran (not a replacement for the checklist):

  • Checks: pnpm check and pnpm smoke:ui (7/7) pass.
  • e2e/chat-variables.e2e.ts: 20/20 on desktop and mobile Chromium, and 10/10 on mobile WebKit. The two new removal tests fail without the fix.
  • New regression chat-variable-history.regression.ts: runs the real routes in Roleplay, Conversation and Game. It covers:
    • regenerate and continue
    • user edits
    • delete and trash restore
    • old replies
    • switching swipes and deleting a swipe
      It fails on unmodified staging (turns came back 7 where 9 was expected).
  • Existing tests: 32 related regressions pass, covering swipes, deletes, trash, regenerate, memory and the Game inventory.
  • After merging the latest staging: I re-ran pnpm check, the new regression and the function-calling regression.
  • Local CodeRabbit: 1 finding, fixed. Deleting a reply undid the changes recorded on every swipe, so typing the value a hidden swipe once set could get reverted. Now only the visible swipe counts. The regression has a new case that failed before the fix.

To check by hand:

  • On a phone, tap a variable's trash button. Cancel once, then remove it.
  • In Roleplay, use a lorebook entry with {{decvar::turns}}. Regenerate a reply a few times and confirm the counter only drops once. Swipe back and forth, and delete the reply.
  • Change a variable by hand in Chat Settings, then regenerate, and confirm your value stays.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Two CHANGELOG entries. No docs under docs/ change.

UI evidence (if applicable)

The confirm dialog is the existing shared one; the e2e tests cover it on desktop, Android-sized and iPhone-sized screens.

Summary by CodeRabbit

  • New Features
    • Chat variable changes made by replies now follow the displayed reply: switching swipes, regenerating, deleting, or restoring a reply updates variables accordingly.
    • Changes made directly in Chat Settings are preserved when reply history is applied.
    • Removing a saved chat variable requires confirmation; cancelling leaves it unchanged. Unsaved or blank rows can still be removed without confirmation.

🔄 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/6954 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/1/2026 **Status:** ✅ Merged **Merged:** 10/2/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/variables-sweep` --- ### 📝 Commits (9) - [`0ba8243`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0ba8243616308d6c13e3ae76c925feba7c4394dc) fix(chat): roll chat variables back with the reply that changed them - [`e282969`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e282969de59b7ce34966a89ac35dc23c34e4297e) fix(chat): ask before removing a chat variable - [`fd82e66`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fd82e66f1e147a749772bcea84ac6f5105c64649) Merge remote-tracking branch 'origin/staging' into fix/variables-sweep - [`3abd3b7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3abd3b71e86e8a983d51b1f80a5d388f730d4d07) Merge remote-tracking branch 'origin/staging' into fix/variables-sweep - [`ec58ee7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ec58ee72326a661698ad14ce57ccf90fc61a243d) fix(chat): undo only the visible swipe's variable changes on delete - [`3006348`](https://github.com/Pasta-Devs/Marinara-Engine/commit/300634824ebdb88015e89776784135bfd368636b) Merge remote-tracking branch 'origin/staging' into fix/variables-sweep - [`6d351de`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6d351de6b8aae3b5ea1a74acdee546126a519006) fix(chat): re-apply variable changes from the restored visible swipe - [`fa6e100`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fa6e1003473bb7e891f0c8902d09bcfff1a18f75) Merge remote-tracking branch 'origin/staging' into fix/variables-sweep - [`ddf0053`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ddf0053e2b50c0780355a2bd487eb19856be808d) Merge remote-tracking branch 'origin/staging' into fix/variables-sweep ### 📊 Changes **10 files changed** (+556 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `e2e/chat-variables.e2e.ts` (+63 -0) 📝 `packages/client/src/features/chat-settings/sections/ChatVariablesSection.tsx` (+20 -3) 📝 `packages/client/src/localization/locales/en.json` (+2 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+42 -18) 📝 `packages/server/src/services/prompt/macro-context.ts` (+4 -0) 📝 `packages/server/src/services/storage/chats.storage.ts` (+91 -8) 📝 `packages/server/src/services/storage/message-trash.storage.ts` (+15 -0) 📝 `packages/shared/src/utils/chat-variables.ts` (+67 -0) ➕ `scripts/regressions/chat-variable-history.regression.ts` (+248 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #6942 Closes #6923 ## Why this change - **#6942:** In Chat Settings → Variables, one stray tap on the trash button deleted a variable for good, which is easy to do on a phone. - **#6923:** Chat variables changed by macros (`{{setvar}}`, `{{decvar}}`, `{{incvar}}`…) didn't go back when you regenerated, swiped or deleted the reply that changed them. A lorebook entry that counts down once per turn kept counting down on every regenerate. ## What changed **Removing a variable (#6942)** - The trash button now asks "Remove "<name>" from this chat?" using the app's existing confirm dialog, the same one the preset variable card uses. - Cancel, Escape or tapping outside keeps the variable. The section has no Save button, so confirming is what saves the removal. - A brand-new empty row is still removed without asking. **Variables follow their reply (#6923)** - Each reply now remembers which variables its turn changed, as `[before, after]` pairs. That's nothing new to configure, and it sits in the reply's `extra` like other per-reply data. - **Regenerate:** starts from the values before the reply. - **Delete:** puts them back. - **Restore from the trash:** applies them again. - **Switching swipes:** switches to that swipe's values, the same way tracker values and the Game inventory follow swipes. - **Your own edits win:** an undo only happens if the variable still holds the value the reply left. If you changed it since, for example in Chat Settings, your value stays. - **Old chats:** replies saved before this change have no record, so they behave as before. - **Code:** small helpers in `shared/utils/chat-variables.ts`, a `replayVariableChanges` storage method, and the generate, delete, swipe and restore paths call them. Not covered, as before this change: variable writes from "retry agents" after a reply, and generations that end without saving a reply. ## 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 What I ran (not a replacement for the checklist): - **Checks:** `pnpm check` and `pnpm smoke:ui` (7/7) pass. - **`e2e/chat-variables.e2e.ts`:** 20/20 on desktop and mobile Chromium, and 10/10 on mobile WebKit. The two new removal tests fail without the fix. - **New regression `chat-variable-history.regression.ts`:** runs the real routes in Roleplay, Conversation and Game. It covers: - regenerate and continue - user edits - delete and trash restore - old replies - switching swipes and deleting a swipe It fails on unmodified staging (`turns` came back `7` where `9` was expected). - **Existing tests:** 32 related regressions pass, covering swipes, deletes, trash, regenerate, memory and the Game inventory. - **After merging the latest staging:** I re-ran `pnpm check`, the new regression and the function-calling regression. - **Local CodeRabbit:** 1 finding, fixed. Deleting a reply undid the changes recorded on every swipe, so typing the value a hidden swipe once set could get reverted. Now only the visible swipe counts. The regression has a new case that failed before the fix. To check by hand: - On a phone, tap a variable's trash button. Cancel once, then remove it. - In Roleplay, use a lorebook entry with `{{decvar::turns}}`. Regenerate a reply a few times and confirm the counter only drops once. Swipe back and forth, and delete the reply. - Change a variable by hand in Chat Settings, then regenerate, and confirm your value stays. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Two CHANGELOG entries. No docs under `docs/` change. ## UI evidence (if applicable) The confirm dialog is the existing shared one; the e2e tests cover it on desktop, Android-sized and iPhone-sized screens. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Chat variable changes made by replies now follow the displayed reply: switching swipes, regenerating, deleting, or restoring a reply updates variables accordingly. * Changes made directly in Chat Settings are preserved when reply history is applied. * Removing a saved chat variable requires confirmation; cancelling leaves it unchanged. Unsaved or blank rows can still be removed without confirmation. <!-- 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:19:24 +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#7400
No description provided.