mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2932] [Issue]: Regex scripts apply inconsistently in group chats, previews, idle-delay sends, and on user input #1509
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#1509
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?
Originally created by @kolacheee on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2932
Originally assigned to: @SpicyMarinara on GitHub.
The regex script engine applies find/replace transforms in several separate passes that don't line up. As a result, scoped (per-character) scripts and global scripts get skipped or double-counted in specific, reproducible situations: group chats, prompt previews, idle/away-delay sends, depth-gated display, and live user input. Each sub-bug below is independently confirmed against v2.0.6 with a concrete repro.
All of these were verified by tracing the code; please confirm the reproduction before fixing.
A. Idle/away "delayed" sends drop ALL prompt-side regex
What's wrong: When a character is idle/DND/offline and the response is delayed (the "will respond in a moment" path), every prompt-side regex script is silently skipped. A non-delayed send to the same character applies them normally.
How to reproduce:
ai_output, promptOnly = true, find\bfoo\b, replacebar. Make sure assistant history contains the wordfoo.bar.You'll see: the delayed prompt still contains
foo.Expected: it should contain
bar, same as the non-delayed send.Where it is:
generate.routes.ts, the delay branch around lines 2516-2530. After the delay it re-reads the DB and rebuildsfinalMessagesfrom rawconversationPromptHistoryContent, then runs macro resolution only (2530) — no regex call follows.What's happening: The only global-regex pass is the iteration-0 pass at line 2043, which runs on
mappedMessages. In the normal pathfinalMessagesis derived from that already-rewritten array. But the delay branch overwritesfinalMessageswith fresh raw content and never re-applies regex. The downstream per-character pass (6117) istargetedOnly:true, so it skips globals. Result: regex is lost only when the character is away.Suggested fix: After rebuilding
finalMessagesin the delay branch, re-runapplyRegexScriptsToPromptMessageswith the same options used at line 2043 before macro resolution.(This one is harder to trigger on demand — it depends on the character status and the 1-5 minute delay window — but the code path is unambiguous.)
B. Character-scoped depth is measured against the trailing instruction, not the last chat message
What's wrong: For a per-character (scoped) script,
maxDepth:0is supposed to mean "the most recent chat message." Instead it points at the trailing "Respond ONLY as X" system instruction that gets appended last, so the script never hits the real last message. A globalmaxDepth:0script works correctly, which proves the divergence.How to reproduce:
targetCharacterIds=[charB], placementai_output,maxDepth:0, find text on charB's last line.targetCharacterIds) and it matches the last message correctly.Where it is: depth is
totalMessages - 1 - index(regex-application.ts:142). The scoped/targeted pass runs atgenerate.routes.ts:6117over an array that by then includes unshifted leading system/context blocks (3472) and the trailing "Respond ONLY as X" instruction pushed at 7239. So depth 0 = that trailing instruction.What's happening: The global iteration-0 pass (2043) measured depth on a history-only array, so depth 0 was the last real message there. The scoped per-character pass measures depth on the fully-assembled prompt, shifting every depth by the number of leading/trailing blocks. The two passes disagree about what "depth 0" means.
Suggested fix: Compute regex depth from the original chat-history index, independent of injected leading/trailing prompt blocks, so scoped and global passes agree.
C. Merged group chats apply scoped regex only for the first character
What's wrong: In a merged group reply, character-scoped scripts only ever run for the first character in the group. Scripts scoped to any other member never apply.
How to reproduce:
targetCharacterIds=[charB], promptOnly = true, findX, replaceY, withXpresent in history.You'll see: the merged prompt keeps
X.Expected: charB's scoped script should rewrite it to
Y, since charB participates.Where it is: merged mode sets
targetCharId = characterIds[0](generate.routes.ts:7273), then the per-character targeted pass (6116-6121) runs with that first id only. For a group send withoutforCharacterId,promptTargetCharacterIdis null (1974-1977), so the iteration-0 pass also skips scoped scripts (regex-application.ts:100-102).Suggested fix: In merged mode, run the targeted scoped pass for every participating character id, not just
characterIds[0].D. Individual group loop never applies globals to earlier characters' in-turn replies
What's wrong: In an individual-mode group, when character A replies and then B's prompt is assembled, A's just-generated reply is inserted raw — global regex scripts never run over it. So B sees A's untransformed text.
How to reproduce:
Voldemort, replace[REDACTED].Voldemort.You'll see: B's prompt still contains
Voldemort.Expected: it should be
[REDACTED].Where it is:
generate.routes.ts:7263pushesgenResult.responseraw intorunningMessages. The next character'sgenerateForCharacteronly runs thetargetedOnly:truepass (6116-6121), which skips globals. Contrast the Professor Mari follow-up at 10957, which deliberately runs a global (non-targeted) regex pass on the freshly-appended turn — with a comment (10946-10949) explaining exactly this gap. The group loop is the unprotected sibling.Suggested fix: Apply the same global regex pass to each character's response before it's appended to
runningMessages, mirroring the Mari follow-up at 10957.E. Prompt depth and on-screen display depth are computed over different arrays
What's wrong: A depth-gated display script (e.g.
maxDepth:3) can apply in the prompt but be skipped on screen (or vice-versa) when there's a hidden-from-AI message in the chat, because the server and client count depth over different message lists.How to reproduce:
ai_outputdisplay script (promptOnly = false) withmaxDepth:3.You'll see: that message is transformed in the prompt but not on screen (depths disagree by 1+).
Expected: prompt and display agree on the message's depth.
Where it is: server depth is over
chatMessages, which filters hiddenFromAI (generate.routes.ts:1607-1609) and appliescontextMessageLimit(1657-1658), thendepth = totalMessages-1-index. Client depth is(messages?.length ?? 0) - 1 - sourceIndexover the FULL transcript (ChatRoleplaySurface.tsx:1793), passed intoapplyToAIOutput(ChatMessage.tsx:1455). For any message older than a hidden-from-AI message, client depth = server depth + 1.Suggested fix: Compute client display depth over the same AI-visible (hidden-filtered, context-limited) message set the server uses, so depth gates line up.
F. Send-time user_input regex ignores minDepth/maxDepth and bakes the result into the stored message
What's wrong: A
user_inputscript with depth limits is applied to the message you just typed regardless of its depth, and the rewritten text is what gets saved and sent — there's no way to scope it by depth on the live turn.How to reproduce:
user_inputscript: promptOnly = false,minDepth:1, find\bteh\b, replacethe.tehand send.You'll see: the stored/sent message is
the.Expected: depth 0 (the live turn) is below
minDepth:1, so it should have been left asteh.Where it is:
applyToUserInputis called with only{resolveMacros, scopedMode}and nodepth(ChatInput.tsx:723-726and908-911;ConversationInput.tsx:769-772). The depth gate isif (options?.depth != null)(use-apply-regex.ts:98), so it's skipped entirely. The rewritten message is what gets persisted (createMessage content,ChatInput.tsx:757) and sent (userMessage, 778). Because the server applies promptOnly scripts only (regex-application.ts:95) and display renders user messages raw (ChatMessage.tsx:1452-1453), this send-time path is the ONLY application path for a non-promptOnly user_input script.Suggested fix: Pass
depth: 0toapplyToUserInputso depth gates apply to the live turn, or document that non-promptOnly user_input scripts intentionally ignore depth on send.G. Character-scoped user_input scripts can never apply correctly on send
What's wrong: A
user_inputscript scoped to a specific character either never runs (exclusive mode) or runs on every user message regardless of target (chat mode) — it can never apply per-character the way the equivalent ai_output path does.How to reproduce:
user_inputscript:targetCharacterIds=[X], promptOnly = false.exclusive→ the script never runs on any user message.chat→ the script runs on all user messages, ignoring the target.(Default mode
disabledsuppresses it entirely, so this only shows under a non-default scoped mode.)Where it is:
applyToUserInputnever passescharacterId(ChatInput.tsx:723/908,ConversationInput.tsx:769). In exclusive mode the gateif (!charId || !script.targetCharacterIds.includes(charId)) continue(use-apply-regex.ts:90-92) always skips becausecharIdis undefined; chat mode (87-89) has no target test, so it runs on everything. ContrastChatMessage.tsx:1458, which DOES passcharacterIdfor ai_output.Suggested fix: Either pass a meaningful character context into
applyToUserInput, or explicitly disallow target-scoping for user_input scripts so the behavior is predictable.H. Dry-run and peek previews drop character-scoped scripts that the real send applies
What's wrong: The prompt preview (peek / dry-run) for a group chat omits character-scoped regex transforms that the actual send does perform, so the preview doesn't match what's really sent.
How to reproduce:
targetCharacterIds=[charA], findX, replaceY.X.Y.Where it is:
dry-run-route.ts:872-875applies regex once withtargetCharacterId = promptTargetCharacterIdand no targeted pass; whenforCharacterIdis absent, that id is null (754-757), so scoped scripts skip (regex-application.ts:100-102). The peek fallback (chats.routes.ts:2137-2139, in the explicit "no generation has happened yet" branch at 2015) passes neithertargetCharacterIdnortargetedOnly, dropping all scoped scripts. The real group send applies them via the per-character targeted pass (generate.routes.ts:6116-6121).Suggested fix: Make the preview paths run the same per-character targeted scoped pass the real send uses, so previews reflect scoped scripts.
AI-investigated against v2.0.6; verify the reproduction before fixing.
@kolacheee commented on GitHub (Jun 28, 2026):
Re-verified this against v2.0.6 (read the code + reproduced each part) and rewrote the description in plain language with concrete, try-it-yourself reproduction steps. Any original claims I could not actually reproduce were dropped (and called out at the end where relevant). Should be much easier to follow and confirm now — sorry the first version was so dense.