[GH-ISSUE #2199] [Issue]: Lorebook regex safety no longer has a hard execution timeout #1098

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

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

Originally assigned to: @Promansis on GitHub.

Summary

The Batch 7 lorebook parityscan found that refactor no longer preserves legacy hard-timeout behavior for user-supplied lorebook regex keyword matching. Legacy ran regex tests in a VM with a timeout; refactor uses static safety heuristics and a scan-text length cap, but no interruptible execution timeout.

Expected behavior

Lorebook regex keyword matching should fail closed when a user-supplied regex becomes too expensive to execute, without hanging generation or preview scans. If the refactor intentionally replaces the legacy hard timeout with static checks plus a text cap, that divergence should be documented and backed by focused proof.

Actual behavior

Refactor rejects many risky patterns with isPatternSafe and skips regex execution for scan text over 100,000 characters, but accepted patterns still run through normal JavaScript RegExp.test without a hard execution timeout. Legacy had a second line of defense: VM execution with a per-call timeout.

Steps to reproduce

  1. Inspect the refactor regex executor used by lorebook keyword scanning.
  2. Observe that src/engine/generation-core/lorebooks/regex-timeout.ts returns false for unsafe patterns or oversized scan text, then runs new RegExp(regex.source, flags).test(text) directly for accepted patterns.
  3. Compare legacy main, where packages/server/src/services/lorebook/regex-timeout.ts ran RegExp.test through vm.runInContext with a timeout.
  4. Treat this as a parity/safety gap until either an interruptible timeout exists in the refactor runtime path or static+cap behavior is documented and proven sufficient.

Impact area

  • App shell, navigation, startup, or providers
  • Catalog resources
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • 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 / 577de008
  • Run mode: Tauri desktop / web shell / remote runtime, wherever lorebook keyword scanning uses shared engine regex matching
  • OS + version: not OS-specific
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: not provider-specific

Logs, screenshots, or video

Static trace:

  • Refactor static safety heuristic: src/engine/shared/regex/regex-safety.ts.
  • Refactor runtime regex executor: src/engine/generation-core/lorebooks/regex-timeout.ts.
  • Refactor keyword scanner passes vmRegexExecutor into regex matching: src/engine/generation-core/lorebooks/keyword-scanner.ts.
  • Legacy hard-timeout executor: packages/server/src/services/lorebook/regex-timeout.ts on main.

No live hang repro was run in this scan.

Regression notes

Legacy main used a hard VM timeout as a second line of defense after static regex safety checks. Refactor preserved static checks but does not preserve the hard timeout behavior.

Additional context

Parity target: #2181

Parity row: 07-LB-ERROR-regex-safety

Classification from Batch 7 scan: Legacy better / Current refactor risk.

Suggested next action: either add an interruptible regex execution strategy appropriate for the refactor runtime, or explicitly document/prove the static safety + scan-size cap as an intentional divergence.

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 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2199 Originally assigned to: @Promansis on GitHub. ## Summary The Batch 7 lorebook parityscan found that refactor no longer preserves legacy hard-timeout behavior for user-supplied lorebook regex keyword matching. Legacy ran regex tests in a VM with a timeout; refactor uses static safety heuristics and a scan-text length cap, but no interruptible execution timeout. ## Expected behavior Lorebook regex keyword matching should fail closed when a user-supplied regex becomes too expensive to execute, without hanging generation or preview scans. If the refactor intentionally replaces the legacy hard timeout with static checks plus a text cap, that divergence should be documented and backed by focused proof. ## Actual behavior Refactor rejects many risky patterns with `isPatternSafe` and skips regex execution for scan text over 100,000 characters, but accepted patterns still run through normal JavaScript `RegExp.test` without a hard execution timeout. Legacy had a second line of defense: VM execution with a per-call timeout. ## Steps to reproduce 1. Inspect the refactor regex executor used by lorebook keyword scanning. 2. Observe that `src/engine/generation-core/lorebooks/regex-timeout.ts` returns false for unsafe patterns or oversized scan text, then runs `new RegExp(regex.source, flags).test(text)` directly for accepted patterns. 3. Compare legacy `main`, where `packages/server/src/services/lorebook/regex-timeout.ts` ran `RegExp.test` through `vm.runInContext` with a timeout. 4. Treat this as a parity/safety gap until either an interruptible timeout exists in the refactor runtime path or static+cap behavior is documented and proven sufficient. ## Impact area - [ ] App shell, navigation, startup, or providers - [x] Catalog resources - [x] Chat mode - [x] Roleplay mode - [x] Game mode - [ ] Shared mode UI - [ ] 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` / `577de008` - Run mode: Tauri desktop / web shell / remote runtime, wherever lorebook keyword scanning uses shared engine regex matching - OS + version: not OS-specific - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: not provider-specific ## Logs, screenshots, or video Static trace: - Refactor static safety heuristic: `src/engine/shared/regex/regex-safety.ts`. - Refactor runtime regex executor: `src/engine/generation-core/lorebooks/regex-timeout.ts`. - Refactor keyword scanner passes `vmRegexExecutor` into regex matching: `src/engine/generation-core/lorebooks/keyword-scanner.ts`. - Legacy hard-timeout executor: `packages/server/src/services/lorebook/regex-timeout.ts` on `main`. No live hang repro was run in this scan. ## Regression notes Legacy `main` used a hard VM timeout as a second line of defense after static regex safety checks. Refactor preserved static checks but does not preserve the hard timeout behavior. ## Additional context Parity target: #2181 Parity row: `07-LB-ERROR-regex-safety` Classification from Batch 7 scan: `Legacy better` / `Current refactor risk`. Suggested next action: either add an interruptible regex execution strategy appropriate for the refactor runtime, or explicitly document/prove the static safety + scan-size cap as an intentional divergence. ## 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:26:39 +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#1098
No description provided.