[GH-ISSUE #2474] [Issue]: Prompt-only regex scripts are applied in storage order instead of the user-configured order #1217

Closed
opened 2026-10-21 05:29:11 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Low — correctness regression. Prompt-only regex scripts are applied to the outgoing prompt in storage/file order, not the user-configured sortOrder, so when multiple overlapping prompt-only scripts compose, the result differs from what the user arranged (and from main, which applies them in order).

Expected behavior

Apply prompt-only regex scripts in the user-defined order (sortOrder), matching main's orderBy(asc(order)) and the refactor's own runtime/display path which already sorts.

Actual behavior

Both prompt-assembly call sites list the scripts with no sort:

// src/engine/generation/prompt-assembly.ts:3614 (and second pass :3625)
const regexScripts = await storage.list<JsonRecord>("regex-scripts");   // no .sort(bySortOrder)
applyRegexScriptsToPromptMessages(messages, regexScripts, { ... });

applyRegexScriptsToPromptText (regex-application.ts) iterates scripts in array order and mutates the result cumulatively, so the composition of overlapping prompt-only scripts is order-dependent. The generic storage.list returns insertion/file order. This is inconsistent with the refactor's own runtime path regex-runtime.ts:27 ((await storage.list("regex-scripts")).sort(bySortOrder)) and with every sibling collection in prompt-assembly.ts (sections/groups/choiceBlocks all use .sort(bySortOrder)). bySortOrder is already imported in this file.

Steps to reproduce

  1. Define two or more enabled prompt-only regex scripts whose effects compose/overlap.
  2. Reorder them in the editor (writes sortOrder/order).
  3. The prompt sent to the LLM is transformed in storage order, not the configured order.

Impact area

  • React-free engine behavior, contracts, agents, or capability ports
  • Chat mode

Environment

  • Branch or commit: refactor @ 1fae2c42
  • Run mode: Tauri desktop / web shell
  • OS + version: found via static source audit (not runtime-reproduced)
  • Node + pnpm versions: n/a (static audit)
  • Rust version, if relevant: n/a (static audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: n/a

Logs, screenshots, or video

Static trace: prompt-assembly.ts:3614 and :3625 (no sort); regex-application.ts array-order apply; contrast regex-runtime.ts:27 which sorts.

Regression notes

Regression vs main, which applies regex scripts by asc(order). Note: #2454 ("Fix prompt regex coverage", closing #2449) recently touched this exact code to fix the prompt/injection coverage gap, but it added no sort — the ordering defect is separate and untouched. Distinct from #2449 (coverage) and #2450 (regenerate source prompt).

Additional context

Fix is a one-liner: const regexScripts = (await storage.list<JsonRecord>("regex-scripts")).sort(bySortOrder); at both call sites, matching regex-runtime.ts. Low severity: requires ≥2 overlapping prompt-only scripts plus a reorder that diverges from insertion order; non-destructive output drift.

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 @Romuromylus on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2474 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Low — correctness regression.** Prompt-only regex scripts are applied to the outgoing prompt in storage/file order, not the user-configured `sortOrder`, so when multiple overlapping prompt-only scripts compose, the result differs from what the user arranged (and from main, which applies them in order). ## Expected behavior Apply prompt-only regex scripts in the user-defined order (`sortOrder`), matching main's `orderBy(asc(order))` and the refactor's own runtime/display path which already sorts. ## Actual behavior Both prompt-assembly call sites list the scripts with no sort: ```ts // src/engine/generation/prompt-assembly.ts:3614 (and second pass :3625) const regexScripts = await storage.list<JsonRecord>("regex-scripts"); // no .sort(bySortOrder) applyRegexScriptsToPromptMessages(messages, regexScripts, { ... }); ``` `applyRegexScriptsToPromptText` (`regex-application.ts`) iterates `scripts` in array order and mutates the result cumulatively, so the composition of overlapping prompt-only scripts is order-dependent. The generic `storage.list` returns insertion/file order. This is inconsistent with the refactor's own runtime path `regex-runtime.ts:27` (`(await storage.list("regex-scripts")).sort(bySortOrder)`) and with every sibling collection in `prompt-assembly.ts` (sections/groups/choiceBlocks all use `.sort(bySortOrder)`). `bySortOrder` is already imported in this file. ## Steps to reproduce 1. Define two or more enabled prompt-only regex scripts whose effects compose/overlap. 2. Reorder them in the editor (writes `sortOrder`/`order`). 3. The prompt sent to the LLM is transformed in storage order, not the configured order. ## Impact area - [x] React-free engine behavior, contracts, agents, or capability ports - [x] Chat mode ## Environment - Branch or commit: refactor @ 1fae2c42 - Run mode: Tauri desktop / web shell - OS + version: found via static source audit (not runtime-reproduced) - Node + pnpm versions: n/a (static audit) - Rust version, if relevant: n/a (static audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: n/a ## Logs, screenshots, or video Static trace: `prompt-assembly.ts:3614` and `:3625` (no sort); `regex-application.ts` array-order apply; contrast `regex-runtime.ts:27` which sorts. ## Regression notes Regression vs main, which applies regex scripts by `asc(order)`. Note: #2454 ("Fix prompt regex coverage", closing #2449) recently touched this exact code to fix the prompt/injection *coverage* gap, but it added no sort — the ordering defect is separate and untouched. Distinct from #2449 (coverage) and #2450 (regenerate source prompt). ## Additional context Fix is a one-liner: `const regexScripts = (await storage.list<JsonRecord>("regex-scripts")).sort(bySortOrder);` at both call sites, matching `regex-runtime.ts`. Low severity: requires ≥2 overlapping prompt-only scripts plus a reorder that diverges from insertion order; non-destructive output drift. ## 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:11 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jun 6, 2026):

Fixed on refactor in 038b7220.

Prompt-only regex scripts are sorted by the configured sort order before prompt application.

Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.

<!-- gh-comment-id:4638719922 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. Prompt-only regex scripts are sorted by the configured sort order before prompt application. Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.
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#1217
No description provided.