[PR #5284] [CLOSED] feat(agents): match the reference extractor's merge semantics and guards #6708

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

📋 Pull Request Information

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

Base: staging ← Head: feat/beholder-merge-parity


📝 Commits (6)

  • ab4fc54 feat(agents): validate Beholder extractions before they reach state
  • d33a65b style(agents): format the vendored validator tables
  • af7f6c4 feat(agents): match the reference extractor's merge semantics
  • 77fef32 feat(agents): discard characters the extractor invented
  • 60e5160 Merge branch 'staging' into feat/beholder-merge-parity
  • aaee151 fix(agents): stop the normalizer overwriting fields a delta omitted

📊 Changes

7 files changed (+5342 additions, -30 deletions)

View changed files

📝 packages/server/src/services/agents/agent-executor.ts (+52 -4)
📝 packages/server/src/services/agents/beholder-state.ts (+161 -26)
➕ packages/server/src/services/agents/beholder-validator-data.ts (+1251 -0)
➕ packages/server/src/services/agents/beholder-validator.ts (+806 -0)
➕ scripts/regressions/beholder-merge-parity.regression.ts (+193 -0)
➕ scripts/regressions/beholder-validator-cases.json (+2784 -0)
➕ scripts/regressions/beholder-validator-parity.regression.ts (+95 -0)

📄 Description

Linked issue

No separate issue — continues the Beholder parity work behind #5251, #5280 and #5281. Stacked on #5281; review that first.

Why this change

Five ways tracked state drifted from what the story actually said. Each survives schema validation, so none of them errors — the state just quietly stops matching the fiction, and because it is fed back into the next extraction and the next response, it stays wrong.

  1. An update erased what was already known. A delta re-describing a garment replaced the stored entry outright, so {"item":"blazer","damage":"damaged"} — "the blazer is torn" — dropped the navy the blazer was already known to be. Same class as the wounds bug in #5241, on the other field.
  2. Plurals stacked. Garment identity was the raw name, so "boots" appended a second entry beside a stored "boot" and the character was wearing two.
  3. A slot could be bare and clothed, with nothing to resolve the contradiction.
  4. missing was trusted. Amputation is the field the extractor misfires on most, and a wrong one cascades and keeps being restated.
  5. Characters could be invented. On a cold start or a first-person turn the extractor can attribute state to a name appearing nowhere in the story, and once written it persists.
  6. The validator ate takeoffs. An empty worn list is how "took it all off" is expressed; pruning removed it along with lists that were only emptied by stripping an invalid item.

What changed

  • Worn and wounds update in place — incoming fields win, fields the delta did not re-emit are kept, and the first-seen surface form is kept so a label does not flicker between "boot" and "boots".
  • Canonical garment identity, so singular and plural are one garment. worn_remove matches canonically too: removing "boots" clears a stored "boot".
  • Bare/worn reconciliation — a delta asserting bare empties the stack; a garment added clears a stale bare. Slots the delta did not touch are left alone, because only a fresh assertion resolves the contradiction.
  • stripModelMissing — model-emitted missing is dropped before anything else sees it, matching the reference, which makes it manual-only. The slot editor and directives still set it.
  • dropHallucinatedCharacters — a character is kept when it is the persona, already tracked, or named in the narration; anything else is dropped and logged. A tracked character survives a turn that never names it, since a pronoun-only sentence attributes by context.
  • keepOriginallyEmpty in the validator — the model's own clears survive pruning, while a list emptied by stripping still collapses to a no-op so a bad emission cannot wipe a stack.

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:

  • scripts/regressions/beholder-merge-parity.regression.ts (new, passing) — covers all five: colour surviving a damage update, co-located garments surviving, plural folding onto the stored singular with the surface form kept, canonical worn_remove, bare emptying the stack and a garment clearing a stale bare, missing stripped with the rest of the slot intact, an explicit clear surviving the validator, a strip-emptied list not surviving, and the invented-character guard (whole-word matching, regex-significant names, persona and tracked names kept).
  • Each assertion was checked against the old behaviour, not just the new: reverting the field-merge fails with an update keeps fields the delta did not re-emit; reverting canonical identity fails with "boots" updates the stored "boot" instead of stacking; removing the reconciliation fails with going bare empties the worn stack.
  • The validator parity fixture still passes 60/60 — keepOriginallyEmpty changes pruning without moving any oracle case.
  • Typecheck clean (tsc -b ../shared && tsc --noEmit → 0 errors), prettier clean, and the four existing Beholder regressions still pass.

Not verified: behaviour against a live model. The judgement worth a maintainer's eye is stripModelMissing — it is a deliberate capability removal (the model can no longer report amputation at all), taken from the reference because the false-positive rate there is worse than the missing feature.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of extracted character state by filtering hallucinated characters and invalid fields.
    • Preserved garment, wound, and clothing details more consistently during updates and removals.
    • Prevented invalid anatomy, item placement, severity, and holding-state changes from corrupting saved state.
    • Preserved intentional empty-list updates while removing unsupported model-generated values.
    • Improved handling of conflicting worn and bare clothing states.
  • Tests

    • Added comprehensive regression coverage for state merging, validation, filtering, and cleanup across 38 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/5284 **Author:** [@GetBeholder](https://github.com/GetBeholder) **Created:** 8/19/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `feat/beholder-merge-parity` --- ### 📝 Commits (6) - [`ab4fc54`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ab4fc54a4c8cf426b193354f026195b30a6b14a9) feat(agents): validate Beholder extractions before they reach state - [`d33a65b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d33a65b008737f3f915bbe4cb603f7e211bfae5d) style(agents): format the vendored validator tables - [`af7f6c4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/af7f6c41c4e1dfa28554b8695c0bcd2c2c76816e) feat(agents): match the reference extractor's merge semantics - [`77fef32`](https://github.com/Pasta-Devs/Marinara-Engine/commit/77fef32bb793cb3e1a8316a84de2d1a8653a8d46) feat(agents): discard characters the extractor invented - [`60e5160`](https://github.com/Pasta-Devs/Marinara-Engine/commit/60e5160b07cc970982d12c7b9fa7590898e60e95) Merge branch 'staging' into feat/beholder-merge-parity - [`aaee151`](https://github.com/Pasta-Devs/Marinara-Engine/commit/aaee1516ab3f6685d2c794fdf5b4df252497bd94) fix(agents): stop the normalizer overwriting fields a delta omitted ### 📊 Changes **7 files changed** (+5342 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/agents/agent-executor.ts` (+52 -4) 📝 `packages/server/src/services/agents/beholder-state.ts` (+161 -26) ➕ `packages/server/src/services/agents/beholder-validator-data.ts` (+1251 -0) ➕ `packages/server/src/services/agents/beholder-validator.ts` (+806 -0) ➕ `scripts/regressions/beholder-merge-parity.regression.ts` (+193 -0) ➕ `scripts/regressions/beholder-validator-cases.json` (+2784 -0) ➕ `scripts/regressions/beholder-validator-parity.regression.ts` (+95 -0) </details> ### 📄 Description ## Linked issue No separate issue — continues the Beholder parity work behind #5251, #5280 and #5281. **Stacked on #5281**; review that first. ## Why this change Five ways tracked state drifted from what the story actually said. Each survives schema validation, so none of them errors — the state just quietly stops matching the fiction, and because it is fed back into the next extraction and the next response, it stays wrong. 1. **An update erased what was already known.** A delta re-describing a garment replaced the stored entry outright, so `{"item":"blazer","damage":"damaged"}` — "the blazer is torn" — dropped the navy the blazer was already known to be. Same class as the wounds bug in #5241, on the other field. 2. **Plurals stacked.** Garment identity was the raw name, so `"boots"` appended a second entry beside a stored `"boot"` and the character was wearing two. 3. **A slot could be bare *and* clothed**, with nothing to resolve the contradiction. 4. **`missing` was trusted.** Amputation is the field the extractor misfires on most, and a wrong one cascades and keeps being restated. 5. **Characters could be invented.** On a cold start or a first-person turn the extractor can attribute state to a name appearing nowhere in the story, and once written it persists. 6. **The validator ate takeoffs.** An empty `worn` list is how "took it all off" is expressed; pruning removed it along with lists that were only emptied by stripping an invalid item. ## What changed - **Worn and wounds update in place** — incoming fields win, fields the delta did not re-emit are kept, and the first-seen surface form is kept so a label does not flicker between "boot" and "boots". - **Canonical garment identity**, so singular and plural are one garment. `worn_remove` matches canonically too: removing "boots" clears a stored "boot". - **Bare/worn reconciliation** — a delta asserting `bare` empties the stack; a garment added clears a stale `bare`. Slots the delta did not touch are left alone, because only a fresh assertion resolves the contradiction. - **`stripModelMissing`** — model-emitted `missing` is dropped before anything else sees it, matching the reference, which makes it manual-only. The slot editor and directives still set it. - **`dropHallucinatedCharacters`** — a character is kept when it is the persona, already tracked, or named in the narration; anything else is dropped and logged. A tracked character survives a turn that never names it, since a pronoun-only sentence attributes by context. - **`keepOriginallyEmpty`** in the validator — the model's own clears survive pruning, while a list emptied by *stripping* still collapses to a no-op so a bad emission cannot wipe a stack. 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: - **`scripts/regressions/beholder-merge-parity.regression.ts`** (new, passing) — covers all five: colour surviving a damage update, co-located garments surviving, plural folding onto the stored singular with the surface form kept, canonical `worn_remove`, bare emptying the stack and a garment clearing a stale bare, `missing` stripped with the rest of the slot intact, an explicit clear surviving the validator, a strip-emptied list *not* surviving, and the invented-character guard (whole-word matching, regex-significant names, persona and tracked names kept). - **Each assertion was checked against the old behaviour**, not just the new: reverting the field-merge fails with `an update keeps fields the delta did not re-emit`; reverting canonical identity fails with `"boots" updates the stored "boot" instead of stacking`; removing the reconciliation fails with `going bare empties the worn stack`. - **The validator parity fixture still passes 60/60** — `keepOriginallyEmpty` changes pruning without moving any oracle case. - Typecheck clean (`tsc -b ../shared && tsc --noEmit` → 0 errors), prettier clean, and the four existing Beholder regressions still pass. Not verified: behaviour against a live model. The judgement worth a maintainer's eye is `stripModelMissing` — it is a deliberate capability *removal* (the model can no longer report amputation at all), taken from the reference because the false-positive rate there is worse than the missing feature. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved reliability of extracted character state by filtering hallucinated characters and invalid fields. * Preserved garment, wound, and clothing details more consistently during updates and removals. * Prevented invalid anatomy, item placement, severity, and holding-state changes from corrupting saved state. * Preserved intentional empty-list updates while removing unsupported model-generated values. * Improved handling of conflicting worn and bare clothing states. * **Tests** * Added comprehensive regression coverage for state merging, validation, filtering, and cleanup across 38 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:56 +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#6708
No description provided.