[PR #5251] [MERGED] feat(agents): run Beholder as five narrow passes for per-lane extractors #6692

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

📋 Pull Request Information

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

Base: staging ← Head: feat/beholder-local-5pass


📝 Commits (5)

  • 82b024c feat(agents): run Beholder as five narrow passes for per-lane extractors
  • 2cad5e5 fix(agents): harden the Beholder lane path after review
  • eb40044 fix(agents): require lane replies to match the extraction contract
  • 6fc7ad8 Merge branch 'staging' into feat/beholder-local-5pass
  • 8da270f Merge branch 'staging' into feat/beholder-local-5pass

📊 Changes

3 files changed (+446 additions, -1 deletions)

View changed files

📝 packages/server/src/services/agents/agent-executor.ts (+155 -1)
📝 packages/server/src/services/agents/beholder-state.ts (+134 -0)
➕ scripts/regressions/beholder-lane-passes.regression.ts (+157 -0)

📄 Description

Linked issue

Follow-up to #5204 (the delta protocol) — extends it so a locally hosted per-lane Beholder extractor can be used as well as a SOTA model. Stacked on #5241; review that first (this branch contains its commits).

Why this change

Beholder currently issues one call asking for the whole physical state, which is right for a SOTA model. A locally hosted Beholder model is trained per lane — it answers about worn items, wounds, held items, species, or bare/missing flags one at a time. Handing it a single whole-state prompt is off-distribution for it, and it returns partial or malformed JSON.

This adds a second, opt-in execution shape so both kinds of model work behind the same agent, chosen by which prompt template the user picks.

What changed

  • parseBeholderLanePrompts() splits a prompt template that marks each lane with a [worn], [wounds], [holding], [species], or [flags] heading on its own line. It returns null unless all five lanes are present with non-empty bodies, so any ordinary single-prompt template falls through to the existing one-call path untouched.
  • executeBeholderLanePasses() runs one call per lane with the same user message, then mergeBeholderLaneDeltas() unions the five narrow deltas into one {changed, delta} payload. The lanes own disjoint slot fields, so the union is field-level and conflict-free. The merged delta then goes through the existing resolveBeholderStateResponse path — nothing downstream changes.
  • A lane that fails is logged and skipped rather than failing the turn; only an all-lane failure errors.
  • worn_remove is now honoured in mergeSlotDelta: the worn lane emits it for partial takeoff (the single-prompt path only ever clears a slot with worn: []). Named garments are subtracted by the same identity mergeWornItems uses.
  • The species lane's empty exotic-slot stubs ({"tail": {}}) are anatomy hints, not state, so they no longer mark a turn as changed.

No schema, storage, API, or client change. No new settings: the switch is the existing per-agent prompt-template selector, so a package can offer "single prompt" and "five passes" as two options.

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

Rather than tick boxes I did not earn: I have not exercised this against a live model in the app. pnpm install fails in my environment at the onnxruntime-node postinstall, so I could not run the full pnpm check or launch the app. A maintainer should confirm a real end-to-end turn before merge.

What I did verify locally, working around the broken install:

  • Typecheck is clean. Ran tsc -b ../shared && tsc --noEmit for packages/server against this branch's own packages/shared: 0 errors.
  • Prettier is clean on both changed source files.
  • Added scripts/regressions/beholder-lane-passes.regression.ts and ran it (exit 0). It covers: a single-prompt template and a partial template both parsing to null (i.e. the existing path is preserved); a full five-lane template parsing into its five prompts; whitespace-tolerant headings; an empty lane body rejected; all-lanes-quiet producing a no-op; the five deltas unioning across the same and different slots; empty anatomy stubs not counting as a change; the unioned delta resolving against prior state with self mapped back to the persona; and worn_remove dropping a named garment while keeping the others.
  • The existing beholder-wound-merge.regression.ts from #5241 still passes.

Note that pull-request-checks.yml does not run the regression suite (only regression:launcher-update and regression:android-local-auth), so neither regression file executes in CI as things stand.

Sequencing note

A package that offers a five-pass template must require an Engine version containing this change — otherwise the whole multi-lane template is sent as one system prompt. Happy to follow up in Marinara-Agents once this lands and the minimum version is known.

Summary by CodeRabbit

  • New Features
    • Improved Beholder state extraction across equipment, wounds, inventory, species, and flags.
    • Multiple state sections can now be processed concurrently and combined into one result.
    • Selective removal of individual worn items is supported without clearing other equipment.
  • Bug Fixes
    • Partial processing failures no longer discard successful state updates; errors occur only when all sections fail.
    • Empty, duplicate, invalid, or unchanged state sections are handled more reliably.

🔄 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/5251 **Author:** [@GetBeholder](https://github.com/GetBeholder) **Created:** 8/19/2026 **Status:** ✅ Merged **Merged:** 8/19/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/beholder-local-5pass` --- ### 📝 Commits (5) - [`82b024c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/82b024ccaf53671c22a7654abdb1de141559628b) feat(agents): run Beholder as five narrow passes for per-lane extractors - [`2cad5e5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2cad5e58a0588086c850579c297812348efbf6a2) fix(agents): harden the Beholder lane path after review - [`eb40044`](https://github.com/Pasta-Devs/Marinara-Engine/commit/eb40044f7a2c583ac6227a406d94518ac6c1c26a) fix(agents): require lane replies to match the extraction contract - [`6fc7ad8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6fc7ad8ee84dfdb1ef3b0d5d541589f300d56daf) Merge branch 'staging' into feat/beholder-local-5pass - [`8da270f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8da270f02c75c158dc1d7f25ce9456a095110f73) Merge branch 'staging' into feat/beholder-local-5pass ### 📊 Changes **3 files changed** (+446 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/agents/agent-executor.ts` (+155 -1) 📝 `packages/server/src/services/agents/beholder-state.ts` (+134 -0) ➕ `scripts/regressions/beholder-lane-passes.regression.ts` (+157 -0) </details> ### 📄 Description ## Linked issue Follow-up to #5204 (the delta protocol) — extends it so a locally hosted per-lane Beholder extractor can be used as well as a SOTA model. Stacked on #5241; review that first (this branch contains its commits). ## Why this change Beholder currently issues one call asking for the whole physical state, which is right for a SOTA model. A **locally hosted Beholder model is trained per lane** — it answers about worn items, wounds, held items, species, or bare/missing flags one at a time. Handing it a single whole-state prompt is off-distribution for it, and it returns partial or malformed JSON. This adds a second, opt-in execution shape so both kinds of model work behind the same agent, chosen by which prompt template the user picks. ## What changed - `parseBeholderLanePrompts()` splits a prompt template that marks each lane with a `[worn]`, `[wounds]`, `[holding]`, `[species]`, or `[flags]` heading on its own line. **It returns `null` unless all five lanes are present with non-empty bodies**, so any ordinary single-prompt template falls through to the existing one-call path untouched. - `executeBeholderLanePasses()` runs one call per lane with the same user message, then `mergeBeholderLaneDeltas()` unions the five narrow deltas into one `{changed, delta}` payload. The lanes own disjoint slot fields, so the union is field-level and conflict-free. The merged delta then goes through the **existing** `resolveBeholderStateResponse` path — nothing downstream changes. - A lane that fails is logged and skipped rather than failing the turn; only an all-lane failure errors. - `worn_remove` is now honoured in `mergeSlotDelta`: the worn lane emits it for partial takeoff (the single-prompt path only ever clears a slot with `worn: []`). Named garments are subtracted by the same identity `mergeWornItems` uses. - The species lane's empty exotic-slot stubs (`{"tail": {}}`) are anatomy hints, not state, so they no longer mark a turn as changed. No schema, storage, API, or client change. No new settings: the switch is the existing per-agent prompt-template selector, so a package can offer "single prompt" and "five passes" as two options. ## 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 Rather than tick boxes I did not earn: **I have not exercised this against a live model in the app.** `pnpm install` fails in my environment at the `onnxruntime-node` postinstall, so I could not run the full `pnpm check` or launch the app. A maintainer should confirm a real end-to-end turn before merge. What I did verify locally, working around the broken install: - **Typecheck is clean.** Ran `tsc -b ../shared && tsc --noEmit` for `packages/server` against this branch's own `packages/shared`: **0 errors**. - **Prettier is clean** on both changed source files. - **Added `scripts/regressions/beholder-lane-passes.regression.ts`** and ran it (exit 0). It covers: a single-prompt template and a partial template both parsing to `null` (i.e. the existing path is preserved); a full five-lane template parsing into its five prompts; whitespace-tolerant headings; an empty lane body rejected; all-lanes-quiet producing a no-op; the five deltas unioning across the same and different slots; empty anatomy stubs not counting as a change; the unioned delta resolving against prior state with `self` mapped back to the persona; and `worn_remove` dropping a named garment while keeping the others. - The existing `beholder-wound-merge.regression.ts` from #5241 still passes. Note that `pull-request-checks.yml` does not run the regression suite (only `regression:launcher-update` and `regression:android-local-auth`), so neither regression file executes in CI as things stand. ### Sequencing note A package that offers a five-pass template must require an Engine version containing this change — otherwise the whole multi-lane template is sent as one system prompt. Happy to follow up in `Marinara-Agents` once this lands and the minimum version is known. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Improved Beholder state extraction across equipment, wounds, inventory, species, and flags. * Multiple state sections can now be processed concurrently and combined into one result. * Selective removal of individual worn items is supported without clearing other equipment. * **Bug Fixes** * Partial processing failures no longer discard successful state updates; errors occur only when all sections fail. * Empty, duplicate, invalid, or unchanged state sections are handled more reliably. <!-- 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:47 +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#6692
No description provided.