[PR #5677] [MERGED] feat(agents): let an operator correct Beholder's physical state #6879

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

📋 Pull Request Information

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

Base: staging ← Head: fix/beholder-state-write


📝 Commits (4)

  • 5274983 feat(agents): let an operator correct Beholder's physical state
  • a7a6a03 fix(agents): guard the Beholder state write and report a lost run
  • f9f1400 Merge branch 'staging' into fix/beholder-state-write
  • 1150493 fix(agents): rate-limit the Beholder state write

📊 Changes

2 files changed (+43 additions, -0 deletions)

View changed files

📝 packages/server/src/middleware/rate-limit.ts (+11 -0)
📝 packages/server/src/routes/agents.routes.ts (+32 -0)

📄 Description

Pull request

Linked issue

Closes #

Why this change

Beholder shows what the extractor believes about each character. When it is wrong there is currently no way to fix it.

The state a chat carries forward is the resultData of the agent's last successful run, and loadPriorBeholderState builds the next prompt from that same record. So a correction has to land there or it means nothing — anything stored elsewhere would look right in the panel and then be narrated away on the following turn.

The existing PATCH /runs/:runId cannot serve this. Both the listing and the patch reach runs through an inner join on agentConfigs, which a package agent's runs do not satisfy, so the client cannot discover the run id in the first place. Verified against a running Engine: GET /runs/:chatId/custom returns zero rows for a chat with Beholder state.

What changed

One route, beside the GET that already reads this state:

  • PUT /api/agents/beholder-state/:chatId — normalizes the submitted state, refuses it with 400 if it does not survive normalization, 404s when there is no run to correct yet, and otherwise updates the last successful Beholder run's resultData.

Nothing else is touched, and nothing outside the Beholder agent's own area of the routes file.

Package and security impact

  • Affected package IDs: beholder
  • Engine compatibility impact: additive route; no schema or contract change
  • New or changed permissions/entrypoints: none
  • Restart, storage, update, or uninstall impact: none. It writes the same record the agent already writes, through the same storage call the existing run-patch route uses.

The body is normalized with normalizeBeholderState before storage, so a malformed or hostile payload is rejected rather than written into the state the prompt is built from.

Validation

  • tsc --noEmit -p packages/server/tsconfig.json clean
  • Exercised against a running Engine: PUT returns 200 and the following GET reflects the change
  • Driven end to end from the package UI — 29/29 UI checks pass, including "the edit is written to the stored state" and the edited garment then appearing in the panel
  • Installed or updated the affected package through Marinara Engine
  • Checked supported modes, restart behavior, and uninstall cleanup

Manual verification notes

Tested by pointing an isolated Engine (own port, own DATA_DIR) at a build of this branch with the Beholder package installed, then driving the panel in a browser: open a slot, edit it, Apply, and confirm both that GET /beholder-state/:chatId returns the edit and that the panel redraws with it. Also confirmed the 400 path by submitting a state that does not normalize.

Documentation impact

  • No documentation changes needed

UI evidence (if applicable)

The consuming UI ships in the Beholder package, not the Engine; screenshots belong with that change.

Summary by CodeRabbit

  • New Features
    • Added a privileged endpoint for operators to update a conversation’s Beholder state.
    • Validates and normalizes submitted state before applying changes.
    • Requires a latest successful Beholder run and returns the corrected state with run metadata.
    • Applies rate limiting to state updates.
    • Provides clear errors for invalid state, missing runs, or conflicting updates.

🔄 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/5677 **Author:** [@GetBeholder](https://github.com/GetBeholder) **Created:** 8/30/2026 **Status:** ✅ Merged **Merged:** 8/30/2026 **Merged by:** [@GetBeholder](https://github.com/GetBeholder) **Base:** `staging` ← **Head:** `fix/beholder-state-write` --- ### 📝 Commits (4) - [`5274983`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5274983957c8eae005b6874a381bdbcf24410318) feat(agents): let an operator correct Beholder's physical state - [`a7a6a03`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a7a6a03411b90629f693a8b9decd1c559db1239a) fix(agents): guard the Beholder state write and report a lost run - [`f9f1400`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f9f1400c60ce03df1c627b001b20a14fd760c84d) Merge branch 'staging' into fix/beholder-state-write - [`1150493`](https://github.com/Pasta-Devs/Marinara-Engine/commit/11504930e4b581199c7e35d891423856795def44) fix(agents): rate-limit the Beholder state write ### 📊 Changes **2 files changed** (+43 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/middleware/rate-limit.ts` (+11 -0) 📝 `packages/server/src/routes/agents.routes.ts` (+32 -0) </details> ### 📄 Description # Pull request ## Linked issue Closes # ## Why this change Beholder shows what the extractor believes about each character. When it is wrong there is currently no way to fix it. The state a chat carries forward is the `resultData` of the agent's last successful run, and `loadPriorBeholderState` builds the next prompt from that same record. So a correction has to land there or it means nothing — anything stored elsewhere would look right in the panel and then be narrated away on the following turn. The existing `PATCH /runs/:runId` cannot serve this. Both the listing and the patch reach runs through an inner join on `agentConfigs`, which a package agent's runs do not satisfy, so the client cannot discover the run id in the first place. Verified against a running Engine: `GET /runs/:chatId/custom` returns zero rows for a chat with Beholder state. ## What changed One route, beside the `GET` that already reads this state: - `PUT /api/agents/beholder-state/:chatId` — normalizes the submitted state, refuses it with 400 if it does not survive normalization, 404s when there is no run to correct yet, and otherwise updates the last successful Beholder run's `resultData`. Nothing else is touched, and nothing outside the Beholder agent's own area of the routes file. ## Package and security impact - Affected package IDs: `beholder` - Engine compatibility impact: additive route; no schema or contract change - New or changed permissions/entrypoints: none - Restart, storage, update, or uninstall impact: none. It writes the same record the agent already writes, through the same storage call the existing run-patch route uses. The body is normalized with `normalizeBeholderState` before storage, so a malformed or hostile payload is rejected rather than written into the state the prompt is built from. ## Validation - [x] `tsc --noEmit -p packages/server/tsconfig.json` clean - [x] Exercised against a running Engine: `PUT` returns 200 and the following `GET` reflects the change - [x] Driven end to end from the package UI — 29/29 UI checks pass, including "the edit is written to the stored state" and the edited garment then appearing in the panel - [ ] Installed or updated the affected package through Marinara Engine - [ ] Checked supported modes, restart behavior, and uninstall cleanup ### Manual verification notes Tested by pointing an isolated Engine (own port, own DATA_DIR) at a build of this branch with the Beholder package installed, then driving the panel in a browser: open a slot, edit it, Apply, and confirm both that `GET /beholder-state/:chatId` returns the edit and that the panel redraws with it. Also confirmed the 400 path by submitting a state that does not normalize. ## Documentation impact - [x] No documentation changes needed ## UI evidence (if applicable) The consuming UI ships in the Beholder package, not the Engine; screenshots belong with that change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a privileged endpoint for operators to update a conversation’s Beholder state. * Validates and normalizes submitted state before applying changes. * Requires a latest successful Beholder run and returns the corrected state with run metadata. * Applies rate limiting to state updates. * Provides clear errors for invalid state, missing runs, or conflicting updates. <!-- 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:14:32 +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#6879
No description provided.