[PR #5281] [CLOSED] feat(agents): validate Beholder extractions before they reach state #6705

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5281
Author: @GetBeholder
Created: 8/19/2026
Status: ❌ Closed

Base: staging ← Head: feat/beholder-validator


📝 Commits (4)

  • ce94ca0 feat(agents): validate Beholder extractions before they reach state
  • 2a7485b style(agents): format the vendored validator tables
  • 11a4e7d Merge branch 'staging' into feat/beholder-validator
  • 5153a98 Merge branch 'staging' into feat/beholder-validator

📊 Changes

6 files changed (+4923 additions, -9 deletions)

View changed files

📝 packages/server/src/services/agents/agent-executor.ts (+31 -4)
📝 packages/server/src/services/agents/beholder-state.ts (+19 -5)
➕ packages/server/src/services/agents/beholder-validator-data.ts (+1251 -0)
➕ packages/server/src/services/agents/beholder-validator.ts (+760 -0)
➕ scripts/regressions/beholder-validator-cases.json (+2784 -0)
➕ scripts/regressions/beholder-validator-parity.regression.ts (+78 -0)

📄 Description

Linked issue

No separate issue — continues the Beholder parity work behind #5251 and #5280. Stacked on #5280; review that first, and this diff is validator-only once #5280 lands.

Why this change

Beholder has no runtime validation. Output is schema-clamped — unknown slots dropped, enums coerced — and then merged. So anything well-formed is accepted, and well-formed is not the same as possible:

  • a concussion recorded on a back
  • a boot worn on a left_hand
  • clothing on an amputated limb
  • "pureblood" stored as a species

All four survive schema clamping today. And they do not stay contained: tracked state is fed back into the next extraction and into the next roleplay response, so one impossible entry keeps being restated until a user hand-edits it.

This matters more here than for a typical agent because the extractor is deliberately small. The reference implementation treats runtime validation as mandatory for exactly that reason.

What changed

  • beholder-validator.ts (new) — port of the validator from the reference extractor, itself a mirror of the validator that produced Beholder's training labels. 25 rules across anatomy, species, multi-slot garments, mutually exclusive clothing, missing-limb dominance and cascade, plus prose-aware severity and damage checks. Error-severity findings strip the offending path (deepest first, then descending list index so same-list strips don't shift each other); warnings and suggestions are reported only.
  • beholder-validator-data.ts (new) — the constant tables, vendored verbatim from the generated source so they stay diffable and cannot drift by hand-editing.
  • agent-executor.ts — validation runs at resolveStructuredAgentResult, the single point every Beholder path already funnels through, so the single-prompt and per-lane shapes are both covered. Findings are logged at debug with rule and path.
  • beholder-state.ts — the persona-as-self keying is extracted so the prompt and the validator see the same shape (the validator compares a delta against prior state, so it must be keyed like the delta).

No schema, storage, API, or client change.

Validation

  • node scripts/validate-catalog.mjs passes locally
  • git diff --check passes locally
  • Rebuilt every affected manifest, payload, artifact, and catalog entry
  • Installed or updated the affected package through Marinara Engine
  • Checked supported modes, restart behavior, and uninstall cleanup
  • Read and followed CONTRIBUTING.md

Manual verification notes

Those boxes are the package template's and do not apply — this is Engine code, no package touched. pnpm install also 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:

  • Parity gated, not asserted. scripts/regressions/beholder-validator-parity.regression.ts (new) runs the port against the fixture generated from the source validator, vendored unchanged, and compares both the findings (rule id, path, severity) and the full stripped delta: 60/60 cases match. Comparison is scoped to the ported rule set, so a rule the port has not taken on shows as a gap rather than a false mismatch.
  • Typecheck clean: tsc -b ../shared && tsc --noEmit for packages/server → 0 errors. Prettier clean.
  • The existing beholder-normalizer, beholder-user-message, beholder-lane-passes and beholder-wound-merge regressions still pass.

Not verified: behaviour against a live model. The judgement worth a maintainer's eye is that error-severity findings strip silently (reported at debug level, not surfaced in the UI) — that is the reference behaviour, but a user seeing an item quietly not appear has no in-app explanation yet. Surfacing findings is a natural follow-up.

Summary by CodeRabbit

  • New Features

    • Added validation for generated character state, including anatomy, equipment, injuries, species, and consistency checks.
    • Invalid details are automatically removed while valid state is preserved.
    • Added support for character-specific prior state and locked equipment slots.
  • Bug Fixes

    • Prevented invalid findings from being persisted in tracked character state.
    • Improved handling of narration-derived state and conflicting equipment details.
  • Tests

    • Added comprehensive regression coverage for validation and state-cleanup scenarios.

🔄 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/5281 **Author:** [@GetBeholder](https://github.com/GetBeholder) **Created:** 8/19/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `feat/beholder-validator` --- ### 📝 Commits (4) - [`ce94ca0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ce94ca058da2a53d87ee812289fdad5b3154b72a) feat(agents): validate Beholder extractions before they reach state - [`2a7485b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2a7485b4951a44f74c93f5168ef0a25bc14b079b) style(agents): format the vendored validator tables - [`11a4e7d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/11a4e7dbcf876aa61d4527dad98fa9263351499d) Merge branch 'staging' into feat/beholder-validator - [`5153a98`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5153a983467f69deb9777ed183e54f9f62cbaf8b) Merge branch 'staging' into feat/beholder-validator ### 📊 Changes **6 files changed** (+4923 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/agents/agent-executor.ts` (+31 -4) 📝 `packages/server/src/services/agents/beholder-state.ts` (+19 -5) ➕ `packages/server/src/services/agents/beholder-validator-data.ts` (+1251 -0) ➕ `packages/server/src/services/agents/beholder-validator.ts` (+760 -0) ➕ `scripts/regressions/beholder-validator-cases.json` (+2784 -0) ➕ `scripts/regressions/beholder-validator-parity.regression.ts` (+78 -0) </details> ### 📄 Description ## Linked issue No separate issue — continues the Beholder parity work behind #5251 and #5280. **Stacked on #5280**; review that first, and this diff is validator-only once #5280 lands. ## Why this change Beholder has no runtime validation. Output is schema-clamped — unknown slots dropped, enums coerced — and then merged. So anything *well-formed* is accepted, and well-formed is not the same as *possible*: - a concussion recorded on a `back` - a boot worn on a `left_hand` - clothing on an amputated limb - `"pureblood"` stored as a species All four survive schema clamping today. And they do not stay contained: tracked state is fed back into the next extraction *and* into the next roleplay response, so one impossible entry keeps being restated until a user hand-edits it. This matters more here than for a typical agent because the extractor is deliberately small. The reference implementation treats runtime validation as mandatory for exactly that reason. ## What changed - **`beholder-validator.ts`** (new) — port of the validator from the reference extractor, itself a mirror of the validator that produced Beholder's training labels. 25 rules across anatomy, species, multi-slot garments, mutually exclusive clothing, missing-limb dominance and cascade, plus prose-aware severity and damage checks. Error-severity findings strip the offending path (deepest first, then descending list index so same-list strips don't shift each other); warnings and suggestions are reported only. - **`beholder-validator-data.ts`** (new) — the constant tables, **vendored verbatim** from the generated source so they stay diffable and cannot drift by hand-editing. - **`agent-executor.ts`** — validation runs at `resolveStructuredAgentResult`, the single point every Beholder path already funnels through, so the single-prompt and per-lane shapes are both covered. Findings are logged at debug with rule and path. - **`beholder-state.ts`** — the persona-as-`self` keying is extracted so the prompt and the validator see the same shape (the validator compares a delta against prior state, so it must be keyed like the delta). No schema, storage, API, or client change. ## Validation - [ ] `node scripts/validate-catalog.mjs` passes locally - [ ] `git diff --check` passes locally - [ ] Rebuilt every affected manifest, payload, artifact, and catalog entry - [ ] Installed or updated the affected package through Marinara Engine - [ ] Checked supported modes, restart behavior, and uninstall cleanup - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Those boxes are the package template's and do not apply — this is Engine code, no package touched. `pnpm install` also 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: - **Parity gated, not asserted.** `scripts/regressions/beholder-validator-parity.regression.ts` (new) runs the port against the fixture generated from the source validator, vendored unchanged, and compares **both** the findings (rule id, path, severity) and the **full stripped delta**: **60/60 cases match**. Comparison is scoped to the ported rule set, so a rule the port has not taken on shows as a gap rather than a false mismatch. - **Typecheck clean**: `tsc -b ../shared && tsc --noEmit` for `packages/server` → 0 errors. Prettier clean. - The existing `beholder-normalizer`, `beholder-user-message`, `beholder-lane-passes` and `beholder-wound-merge` regressions still pass. Not verified: behaviour against a live model. The judgement worth a maintainer's eye is that error-severity findings **strip silently** (reported at debug level, not surfaced in the UI) — that is the reference behaviour, but a user seeing an item quietly not appear has no in-app explanation yet. Surfacing findings is a natural follow-up. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added validation for generated character state, including anatomy, equipment, injuries, species, and consistency checks. * Invalid details are automatically removed while valid state is preserved. * Added support for character-specific prior state and locked equipment slots. * **Bug Fixes** * Prevented invalid findings from being persisted in tracked character state. * Improved handling of narration-derived state and conflicting equipment details. * **Tests** * Added comprehensive regression coverage for validation and state-cleanup scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <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:54 +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#6705
No description provided.