[GH-ISSUE #2494] 13-REGEX-RUNTIME-message-application: non-prompt regex can apply twice #1238

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

Originally created by @Promansis on GitHub (Jun 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2494

Summary

13-REGEX-RUNTIME-message-application: refactor applies non-prompt regex scripts in both the UI path and the generation runtime, so non-idempotent user-input or AI-output regex scripts can run twice.

Linked target: #2482

Expected behavior

Legacy applies prompt-only regex server-side to prompt messages, and applies non-prompt regex client-side on user input before send and AI output at display time. Each applicable message gets one non-prompt pass.

Actual behavior

Refactor still applies regex in the UI send/display paths, but also applies non-prompt regex in start-generation.ts before persistence. A replacement such as a -> aa can be transformed again and become aaaa.

Steps to reproduce

  1. On the refactor branch, create an enabled regex script for user_input or ai_output with a non-idempotent replacement such as a -> aa.
  2. Send or generate a message containing a.
  3. Observe the message pass through both the UI regex hook and the generation runtime regex path.

Impact area

  • App shell, navigation, startup, or providers
  • Catalog resources
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Environment

  • Branch or commit: refactor static trace
  • Run mode: not runtime-tested
  • OS + version: not relevant
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: not relevant

Logs, screenshots, or video

Proof:

  • Legacy prompt-only path: packages/server/src/services/regex/regex-application.ts; packages/server/src/routes/generate.routes.ts:2334-2352
  • Legacy UI regex path: packages/client/src/hooks/use-apply-regex.ts; packages/client/src/components/chat/ChatMessage.tsx:1094-1154
  • Refactor UI regex path: src/features/catalog/agents/regex-application.ts:48-75, 100-126; src/features/modes/shared/chat-ui/components/ChatInput.tsx:176, 603-606, 850-853; src/features/modes/shared/chat-ui/components/ChatMessage.tsx:1370-1443
  • Refactor extra runtime regex path: src/engine/generation/regex-runtime.ts:27-43; src/engine/generation/start-generation.ts:261-270, 3411-3419, 3666-3668
  • Refactor prompt-only path: src/engine/generation-core/regex/regex-application.ts:69-116; src/engine/generation/prompt-assembly.ts:3636-3639

Regression notes

Legacy main keeps non-prompt regex to the UI send/display paths while server generation applies prompt-only regex to prompt messages.

Additional context

Acceptance criteria:

  • Non-prompt regex scripts apply exactly once for user input and AI output.
  • Prompt-only regex scripts continue to apply in prompt assembly with placement, macros, trim strings, order, and depth.
  • Out-of-scope messages remain unchanged.
  • Add or run focused proof for a non-idempotent replacement row and a prompt-only depth row.

Follow-up noted but not chased in this batch: both legacy and refactor appear to lack timeout/static safety for regex-script replacement itself; the confirmed parity gap here is the double application path.

Template check

Please uncheck 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 @Promansis on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2494 ## Summary `13-REGEX-RUNTIME-message-application`: refactor applies non-prompt regex scripts in both the UI path and the generation runtime, so non-idempotent user-input or AI-output regex scripts can run twice. Linked target: #2482 ## Expected behavior Legacy applies prompt-only regex server-side to prompt messages, and applies non-prompt regex client-side on user input before send and AI output at display time. Each applicable message gets one non-prompt pass. ## Actual behavior Refactor still applies regex in the UI send/display paths, but also applies non-prompt regex in `start-generation.ts` before persistence. A replacement such as `a -> aa` can be transformed again and become `aaaa`. ## Steps to reproduce 1. On the refactor branch, create an enabled regex script for `user_input` or `ai_output` with a non-idempotent replacement such as `a` -> `aa`. 2. Send or generate a message containing `a`. 3. Observe the message pass through both the UI regex hook and the generation runtime regex path. ## Impact area - [ ] App shell, navigation, startup, or providers - [ ] Catalog resources - [x] Chat mode - [x] Roleplay mode - [ ] Game mode - [x] Shared mode UI - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [x] React-free engine behavior, contracts, agents, or capability ports - [ ] Shared API wrapper or remote runtime routing - [ ] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Environment - Branch or commit: `refactor` static trace - Run mode: not runtime-tested - OS + version: not relevant - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: not relevant ## Logs, screenshots, or video Proof: - Legacy prompt-only path: `packages/server/src/services/regex/regex-application.ts`; `packages/server/src/routes/generate.routes.ts:2334-2352` - Legacy UI regex path: `packages/client/src/hooks/use-apply-regex.ts`; `packages/client/src/components/chat/ChatMessage.tsx:1094-1154` - Refactor UI regex path: `src/features/catalog/agents/regex-application.ts:48-75`, `100-126`; `src/features/modes/shared/chat-ui/components/ChatInput.tsx:176`, `603-606`, `850-853`; `src/features/modes/shared/chat-ui/components/ChatMessage.tsx:1370-1443` - Refactor extra runtime regex path: `src/engine/generation/regex-runtime.ts:27-43`; `src/engine/generation/start-generation.ts:261-270`, `3411-3419`, `3666-3668` - Refactor prompt-only path: `src/engine/generation-core/regex/regex-application.ts:69-116`; `src/engine/generation/prompt-assembly.ts:3636-3639` ## Regression notes Legacy `main` keeps non-prompt regex to the UI send/display paths while server generation applies prompt-only regex to prompt messages. ## Additional context Acceptance criteria: - Non-prompt regex scripts apply exactly once for user input and AI output. - Prompt-only regex scripts continue to apply in prompt assembly with placement, macros, trim strings, order, and depth. - Out-of-scope messages remain unchanged. - Add or run focused proof for a non-idempotent replacement row and a prompt-only depth row. Follow-up noted but not chased in this batch: both legacy and refactor appear to lack timeout/static safety for regex-script replacement itself; the confirmed parity gap here is the double application path. ## Template check Please uncheck 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.
bsakaguchi 2026-10-21 05:29:34 +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#1238
No description provided.