[PR #5280] [MERGED] feat(agents): give Beholder the reference extractor's exact input #6701

Closed
opened 2026-10-23 04:12:53 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5280
Author: @GetBeholder
Created: 8/19/2026
Status: ✅ Merged
Merged: 8/19/2026
Merged by: @GetBeholder

Base: staging ← Head: feat/beholder-normalize-prose


📝 Commits (3)

  • bfdd694 feat(agents): normalize prose and stop truncating it for Beholder
  • 3453961 feat(agents): give Beholder the reference extractor's exact input
  • 60c39f3 fix(agents): decode entities once and strip tags to a fixed point

📊 Changes

5 files changed (+371 additions, -3 deletions)

View changed files

📝 packages/server/src/services/agents/agent-executor.ts (+40 -3)
➕ packages/server/src/services/agents/beholder-normalizer.ts (+151 -0)
📝 packages/server/src/services/agents/beholder-state.ts (+40 -0)
➕ scripts/regressions/beholder-normalizer.regression.ts (+79 -0)
➕ scripts/regressions/beholder-user-message.regression.ts (+61 -0)

📄 Description

Linked issue

No separate issue — corrective follow-up to #5251 (merged), which added the Beholder execution path this feeds.

Why this change

Beholder was being handed an input that does not match what its extractor reads.

The Agent went through the shared scaffolding: the prompt wrapped in <role>/<lore>/<agents>, an output-format block and other context appended, the tracked state buried in the system message, and chat history passed as separate turns — each stripped of tags and cut at 2000 characters.

A strong general model reads past all of that. A small purpose-trained extractor cannot: it was fitted to one exact input shape and treats surrounding text as part of the task. Three concrete gaps:

  1. Markup instead of prose. Roleplay messages carry asterisk actions, markdown, BBCode, HTML, OOC notes, and labeled dialogue. The reference extractor normalizes all of it to canonical prose first, and its accuracy was measured on that form. *She tugs her coat tighter.* was reaching the model verbatim.
  2. Truncation. For other agents history is background context, so a 2000-character cap is sensible. For Beholder the message is the thing being extracted from — a longer turn silently loses whatever state its remainder described, with no error.
  3. Scaffolding and message shape. The reference sends the prompt as the raw system message plus a single user message: persona, tracked state, narration.

What changed

  • beholder-normalizer.ts (new) — port of the reference normalizer from GetBeholder/Beholder-ME (AGPL-3.0-only, same origin as the rest of the Agent). Step order preserved deliberately: it is a contract with the model, not a formatting preference.
  • buildBeholderUserMessage() — the exact training layout: Persona: / Current state: / Narration:, state keyed by character with the persona as self, serialized compactly, and omitted entirely when nothing is tracked yet rather than sent as {}.
  • buildBeholderMessages() — builds the two messages directly, bypassing the shared builder: raw prompt as system, one user message, narration normalized and not truncated. Used by both the single-prompt and per-lane paths.
  • Every other agent is untouched — the shared builder keeps its tag strip, its cap, and its scaffolding.

Also hardens the normalizer against a backtracking hazard inherited from the reference: two dialogue patterns had a character class containing a space followed by \s*, which is ambiguous and backtracks polynomially on long runs of spaces — reachable precisely because this PR removes the length cap. The class already absorbs those spaces and the captured name is trimmed, so the accepted language is unchanged.

No schema, storage, API, or client change.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Boxes left for a human — pnpm install fails in my environment at the onnxruntime-node postinstall (it rejects CUDA 13), so I cannot run the full pnpm check or the app.

What I did run:

  • Typecheck clean: tsc -b ../shared && tsc --noEmit for packages/server → 0 errors. Prettier clean.
  • Parity with the reference normalizer: ran this port and the reference implementation over the same 22 surface forms and diffed — 22/22 byte-identical, re-verified after the regex hardening. That is the whole point of the change, so it seemed worth proving rather than asserting.
  • Backtracking: a line of 40,000 spaces normalizes in under 1 ms (was the polynomial case).
  • beholder-normalizer.regression.ts (new) — asterisk actions, markdown emphasis, snake_case left alone, block markup, BBCode, HTML with <br> as a break, entity decoding, OOC removal, stage directions, labeled and ALLCAPS dialogue with terminal-punctuation fixes, whitespace collapse, empty input, and a mixed realistic turn. It also asserts already-canonical prose passes through byte-identical — the normalizer must never rewrite what the extractor was trained on.
  • beholder-user-message.regression.ts (new) — pins the layout byte-for-byte, plus self mapping, compact (never indented) state, the state block omitted on a cold start, no persona line when there is no persona, and verbatim narration.
  • The existing beholder-lane-passes and beholder-wound-merge regressions still pass.

Not verified: behaviour against a live model in the app. The judgement worth a maintainer's eye is letting one agent opt out of the shared scaffolding — the alternative keeps Beholder on a shape its extractor was not trained for.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5280 **Author:** [@GetBeholder](https://github.com/GetBeholder) **Created:** 8/19/2026 **Status:** ✅ Merged **Merged:** 8/19/2026 **Merged by:** [@GetBeholder](https://github.com/GetBeholder) **Base:** `staging` ← **Head:** `feat/beholder-normalize-prose` --- ### 📝 Commits (3) - [`bfdd694`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bfdd6946bf6051ac7ed295d390e9230d2cc6a935) feat(agents): normalize prose and stop truncating it for Beholder - [`3453961`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3453961b1375da91151b6e8108db84f17ed4eaa0) feat(agents): give Beholder the reference extractor's exact input - [`60c39f3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/60c39f31b0472fffc7f132bee37242c0386eca91) fix(agents): decode entities once and strip tags to a fixed point ### 📊 Changes **5 files changed** (+371 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/agents/agent-executor.ts` (+40 -3) ➕ `packages/server/src/services/agents/beholder-normalizer.ts` (+151 -0) 📝 `packages/server/src/services/agents/beholder-state.ts` (+40 -0) ➕ `scripts/regressions/beholder-normalizer.regression.ts` (+79 -0) ➕ `scripts/regressions/beholder-user-message.regression.ts` (+61 -0) </details> ### 📄 Description ## Linked issue No separate issue — corrective follow-up to #5251 (merged), which added the Beholder execution path this feeds. ## Why this change Beholder was being handed an input that does not match what its extractor reads. The Agent went through the shared scaffolding: the prompt wrapped in `<role>`/`<lore>`/`<agents>`, an output-format block and other context appended, the tracked state buried in the system message, and chat history passed as separate turns — each stripped of tags and **cut at 2000 characters**. A strong general model reads past all of that. A small purpose-trained extractor cannot: it was fitted to one exact input shape and treats surrounding text as part of the task. Three concrete gaps: 1. **Markup instead of prose.** Roleplay messages carry asterisk actions, markdown, BBCode, HTML, OOC notes, and labeled dialogue. The reference extractor normalizes all of it to canonical prose first, and its accuracy was measured on that form. `*She tugs her coat tighter.*` was reaching the model verbatim. 2. **Truncation.** For other agents history is background context, so a 2000-character cap is sensible. For Beholder the message **is** the thing being extracted from — a longer turn silently loses whatever state its remainder described, with no error. 3. **Scaffolding and message shape.** The reference sends the prompt as the raw system message plus a single user message: persona, tracked state, narration. ## What changed - **`beholder-normalizer.ts`** (new) — port of the reference normalizer from [GetBeholder/Beholder-ME](https://github.com/GetBeholder/Beholder-ME) (AGPL-3.0-only, same origin as the rest of the Agent). Step order preserved deliberately: it is a contract with the model, not a formatting preference. - **`buildBeholderUserMessage()`** — the exact training layout: `Persona:` / `Current state:` / `Narration:`, state keyed by character with the persona as `self`, serialized **compactly**, and **omitted entirely** when nothing is tracked yet rather than sent as `{}`. - **`buildBeholderMessages()`** — builds the two messages directly, bypassing the shared builder: raw prompt as system, one user message, narration normalized and **not truncated**. Used by both the single-prompt and per-lane paths. - **Every other agent is untouched** — the shared builder keeps its tag strip, its cap, and its scaffolding. Also hardens the normalizer against a backtracking hazard inherited from the reference: two dialogue patterns had a character class containing a space followed by `\s*`, which is ambiguous and backtracks polynomially on long runs of spaces — reachable precisely because this PR removes the length cap. The class already absorbs those spaces and the captured name is trimmed, so the accepted language is unchanged. No schema, storage, API, or client change. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Boxes left for a human — `pnpm install` fails in my environment at the `onnxruntime-node` postinstall (it rejects CUDA 13), so I cannot run the full `pnpm check` or the app. What I did run: - **Typecheck clean**: `tsc -b ../shared && tsc --noEmit` for `packages/server` → **0 errors**. Prettier clean. - **Parity with the reference normalizer**: ran this port and the reference implementation over the same 22 surface forms and diffed — **22/22 byte-identical**, re-verified after the regex hardening. That is the whole point of the change, so it seemed worth proving rather than asserting. - **Backtracking**: a line of 40,000 spaces normalizes in **under 1 ms** (was the polynomial case). - **`beholder-normalizer.regression.ts`** (new) — asterisk actions, markdown emphasis, `snake_case` left alone, block markup, BBCode, HTML with `<br>` as a break, entity decoding, OOC removal, stage directions, labeled and ALLCAPS dialogue with terminal-punctuation fixes, whitespace collapse, empty input, and a mixed realistic turn. It also asserts **already-canonical prose passes through byte-identical** — the normalizer must never rewrite what the extractor was trained on. - **`beholder-user-message.regression.ts`** (new) — pins the layout byte-for-byte, plus `self` mapping, compact (never indented) state, the state block omitted on a cold start, no persona line when there is no persona, and verbatim narration. - The existing `beholder-lane-passes` and `beholder-wound-merge` regressions still pass. Not verified: behaviour against a live model in the app. The judgement worth a maintainer's eye is letting one agent opt out of the shared scaffolding — the alternative keeps Beholder on a shape its extractor was not trained for. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:12:53 +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#6701
No description provided.