[GH-ISSUE #5158] [Issue]: Make local variable macros persist per chat like SillyTavern #2853

Closed
opened 2026-10-21 05:56:56 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @SpicyMarinara on GitHub (Aug 16, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5158

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Marinara Engine's local variable macros are not compatible with their SillyTavern equivalents. {{setvar}} and related mutations currently live only in the in-memory macro context for one reply, while SillyTavern stores local variables in the current chat's metadata. Our documentation is also internally contradictory: the main macro guide says variables reset every reply, while the lorebook guide calls them persistent across the chat.

Expected behavior

Match SillyTavern's semantics for Marinara's overlapping local-variable macros:

  • Store local variables in the current chat's metadata so values survive later turns and application reloads while remaining isolated between chats.
  • Seed each prompt build from the persisted chat variables and write mutations back to that same chat.
  • Make getvar, setvar, addvar, incvar, and decvar match the corresponding SillyTavern behavior, including return values and numeric-versus-string addition.
  • Preserve addnumvar as a Marinara extension if it is still useful, but document it as such.
  • Add regression coverage for setting and reading within one build, reading on a later turn, surviving reload, and isolation between two chats.
  • Update both docs/prompts/macros.md and docs/lorebooks/entries.md so they consistently describe chat-persistent behavior and note any intentional compatibility differences.

Reference: https://docs.sillytavern.app/usage/core-concepts/macros/

Actual behavior

resolveVariableOperationMacros mutates only MacroContext.variables. The generation route creates a new prompt macro context for each reply and never persists those mutations to chat metadata. Consequently, a value set during one reply is unavailable to a later reply.

The documentation currently disagrees with itself:

  • docs/prompts/macros.md says variables only live for one reply.
  • docs/lorebooks/entries.md says getvar / setvar are persistent across the chat.

There are also behavioral differences from SillyTavern in the overlapping operations: Marinara's addvar always concatenates text, and incvar / decvar currently resolve to an empty string instead of returning the updated value.

Steps to reproduce

  1. During one prompt build, set a variable with {{setvar::test::remembered}} and confirm {{getvar::test}} can read it later in that same build.
  2. Generate a later reply whose prompt reads {{getvar::test}} without setting it again.
  3. Observe that the value is empty because the next reply starts with a fresh variable map.
  4. Compare the behavior with SillyTavern, where local variables are saved to the current chat metadata.

Environment

  • Marinara Engine version: 2.4.3
  • Install type: source
  • OS + version: Not environment-specific
  • Browser or app shell: Not environment-specific

Logs, screenshots, or video

Not applicable. The mismatch is visible in packages/shared/src/utils/macro-engine.ts, packages/server/src/routes/generate.routes.ts, and the two documentation pages named above.

Additional context

Existing chats can start with an empty variable map; no data migration is required for values that Marinara never persisted. Care should be taken not to let one chat's variables leak into another chat, and prompt assembly paths that intentionally use variable snapshots should remain side-effect-safe.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @SpicyMarinara on GitHub (Aug 16, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5158 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Marinara Engine's local variable macros are not compatible with their SillyTavern equivalents. `{{setvar}}` and related mutations currently live only in the in-memory macro context for one reply, while SillyTavern stores local variables in the current chat's metadata. Our documentation is also internally contradictory: the main macro guide says variables reset every reply, while the lorebook guide calls them persistent across the chat. ## Expected behavior Match SillyTavern's semantics for Marinara's overlapping local-variable macros: - Store local variables in the current chat's metadata so values survive later turns and application reloads while remaining isolated between chats. - Seed each prompt build from the persisted chat variables and write mutations back to that same chat. - Make `getvar`, `setvar`, `addvar`, `incvar`, and `decvar` match the corresponding SillyTavern behavior, including return values and numeric-versus-string addition. - Preserve `addnumvar` as a Marinara extension if it is still useful, but document it as such. - Add regression coverage for setting and reading within one build, reading on a later turn, surviving reload, and isolation between two chats. - Update both `docs/prompts/macros.md` and `docs/lorebooks/entries.md` so they consistently describe chat-persistent behavior and note any intentional compatibility differences. Reference: https://docs.sillytavern.app/usage/core-concepts/macros/ ## Actual behavior `resolveVariableOperationMacros` mutates only `MacroContext.variables`. The generation route creates a new prompt macro context for each reply and never persists those mutations to chat metadata. Consequently, a value set during one reply is unavailable to a later reply. The documentation currently disagrees with itself: - `docs/prompts/macros.md` says variables only live for one reply. - `docs/lorebooks/entries.md` says `getvar` / `setvar` are persistent across the chat. There are also behavioral differences from SillyTavern in the overlapping operations: Marinara's `addvar` always concatenates text, and `incvar` / `decvar` currently resolve to an empty string instead of returning the updated value. ## Steps to reproduce 1. During one prompt build, set a variable with `{{setvar::test::remembered}}` and confirm `{{getvar::test}}` can read it later in that same build. 2. Generate a later reply whose prompt reads `{{getvar::test}}` without setting it again. 3. Observe that the value is empty because the next reply starts with a fresh variable map. 4. Compare the behavior with SillyTavern, where local variables are saved to the current chat metadata. ## Environment - Marinara Engine version: 2.4.3 - Install type: source - OS + version: Not environment-specific - Browser or app shell: Not environment-specific ## Logs, screenshots, or video Not applicable. The mismatch is visible in `packages/shared/src/utils/macro-engine.ts`, `packages/server/src/routes/generate.routes.ts`, and the two documentation pages named above. ## Additional context Existing chats can start with an empty variable map; no data migration is required for values that Marinara never persisted. Care should be taken not to let one chat's variables leak into another chat, and prompt assembly paths that intentionally use variable snapshots should remain side-effect-safe. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [x] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:56:56 +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#2853
No description provided.