[PR #6456] [CLOSED] fix: decouple text release from tracker/lorebook-keeper post-processing #7184

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6456
Author: @Bainshie
Created: 9/20/2026
Status: ❌ Closed

Base: staging ← Head: fix/decouple-text-release-from-post-processing


📝 Commits (1)

  • d9848b9 fix: decouple text release from tracker/lorebook-keeper post-processing

📊 Changes

5 files changed (+375 additions, -162 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/routes/generate.routes.ts (+181 -157)
📝 scripts/regressions/agent-activation.regression.ts (+28 -3)
📝 scripts/regressions/spatial-context.regression.ts (+2 -2)
➕ scripts/regressions/text-rewrite-lane-concurrency.regression.ts (+163 -0)

📄 Description

Summary

  • Roleplay turns with both trackers (or Lorebook Keeper, or a custom tracker-type agent like a Plot Guardian) and rewrite-lane agents (Prose Guardian, Continuity Checker, Immersive HTML, or a custom text_rewrite agent) active kept the "Rewrite agents are working!" placeholder up until the entire post_processing phase resolved — trackers included — even though only the rewrite lane touches the visible message. A captured run held the placeholder for ~86s when only ~20s of that was the rewrite lane itself.
  • The rewrite lane is now kicked off concurrently with the tracker/Lorebook Keeper post-processing pipeline instead of strictly after it. Its text_rewrite SSE event (which replaces the placeholder with the real text) now fires as soon as the rewrite lane itself finishes.
  • The ability to start a new generation is unchanged: it's still gated on the full post-processing agent set (trackers, Lorebook Keeper, custom tracker-type agents, and the rewrite lane) or an explicit stop, exactly as before — only the text display gate moved earlier, not the can-I-generate-again gate.

Why

Traced in packages/server/src/routes/generate.routes.ts: the rewrite-lane loop ran strictly after pipeline.postGenerate() (trackers), the Lorebook Keeper call, the auto-retry-failed-agents block, and a large results/game-state persistence block — none of which mutate the message text, but all of which the placeholder waited on. Non-text agents (trackers, Lorebook Keeper, custom tracker-type agents) already report progress independently via existing agent_result SSE events, so there was no reason for text display to share their critical path.

Known trade-off, called out explicitly: the rewrite lane's prompt used to include tracker/Lorebook Keeper output (via an unconditional <agent_results> block built from every other post-processing agent's results) once those had resolved. Since the rewrite lane now starts before that output exists, it no longer sees it — only earlier-phase (parallel) agent results are included, matching exactly what it already saw in chats with no tracker-type agents configured. This is inherent to decoupling the two critical paths per the request; flagging it explicitly since it isn't spelled out anywhere in code comments.

Preserved as before:

  • Lorebook Keeper's own execution still runs after trackers (it reads their committed output) — only text release moved, not Lorebook Keeper's place in the pipeline.
  • Sequential ordering within the rewrite lane itself (each rewrite-lane agent still sees the prior one's edit).
  • Agent failure/retry handling for non-text agents still gates the generation-complete signal, not text release.
  • The existing stop/abort path unblocks new generation immediately regardless.

Test plan

  • Manually verify in the app: a roleplay chat with a slow tracker (or Lorebook Keeper / a custom tracker-type agent) and a rewrite-lane agent (Prose Guardian/Continuity Checker/custom) both active — confirm the reply's real text appears well before the tracker/Lorebook Keeper finish, and that the send/new-message control stays disabled until everything (or Stop) resolves.
  • Manually verify no regression when only rewrite-lane agents are configured (no trackers) — placeholder behavior should be unchanged.
  • Manually verify a chat with trackers only (no rewrite-lane agents) behaves as before.
  • pnpm --filter @marinara-engine/server run lint (tsc -b ../shared && tsc --noEmit && tsc -p ../../scripts/regressions/tsconfig.character-activity.json) — clean, 0 errors.
  • Added scripts/regressions/text-rewrite-lane-concurrency.regression.ts — spins up the real /generate route with a fixture provider (a deliberately slow non-text post-processing agent + a fast custom rewrite agent) and asserts text_rewrite fires before the slow agent's agent_result, while done still waits for both. Verified it fails against the pre-fix code (reverted the route file locally, reran — assertion failure as expected) and passes with the fix.
  • Updated two existing source-pattern regressions (agent-activation.regression.ts, spatial-context.regression.ts) that pinned the old single-block code shape; both pass against the new structure.
  • Ran targeted regressions covering generation/agents/trackers/lorebook/streaming (agent-context-generation, agent-runtime, agent-progress, agent-scene-check, manual-agent-retry-resolution, roleplay-streaming, one-request-dice-rendering, issue-sweep-5391-5394, open-issues) — all pass.
  • Full pnpm regression (complete Node lane) was not run to completion locally — it's a large, long-running suite; relying on CI for the full run. Everything targeted at the changed area passed.

No linked issue exists for this yet — one should be opened before/alongside this PR per CONTRIBUTING.md § Before You Open a Pull Request.


🔄 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/6456 **Author:** [@Bainshie](https://github.com/Bainshie) **Created:** 9/20/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `fix/decouple-text-release-from-post-processing` --- ### 📝 Commits (1) - [`d9848b9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d9848b932f513636f60f2babe53f4be949336b95) fix: decouple text release from tracker/lorebook-keeper post-processing ### 📊 Changes **5 files changed** (+375 additions, -162 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+181 -157) 📝 `scripts/regressions/agent-activation.regression.ts` (+28 -3) 📝 `scripts/regressions/spatial-context.regression.ts` (+2 -2) ➕ `scripts/regressions/text-rewrite-lane-concurrency.regression.ts` (+163 -0) </details> ### 📄 Description ## Summary - Roleplay turns with both trackers (or Lorebook Keeper, or a custom tracker-type agent like a Plot Guardian) **and** rewrite-lane agents (Prose Guardian, Continuity Checker, Immersive HTML, or a custom `text_rewrite` agent) active kept the "Rewrite agents are working!" placeholder up until the entire `post_processing` phase resolved — trackers included — even though only the rewrite lane touches the visible message. A captured run held the placeholder for ~86s when only ~20s of that was the rewrite lane itself. - The rewrite lane is now kicked off **concurrently** with the tracker/Lorebook Keeper post-processing pipeline instead of strictly after it. Its `text_rewrite` SSE event (which replaces the placeholder with the real text) now fires as soon as the rewrite lane itself finishes. - The ability to start a **new** generation is unchanged: it's still gated on the full post-processing agent set (trackers, Lorebook Keeper, custom tracker-type agents, and the rewrite lane) or an explicit stop, exactly as before — only the *text display* gate moved earlier, not the *can-I-generate-again* gate. ## Why Traced in `packages/server/src/routes/generate.routes.ts`: the rewrite-lane loop ran strictly after `pipeline.postGenerate()` (trackers), the Lorebook Keeper call, the auto-retry-failed-agents block, and a large results/game-state persistence block — none of which mutate the message text, but all of which the placeholder waited on. Non-text agents (trackers, Lorebook Keeper, custom tracker-type agents) already report progress independently via existing `agent_result` SSE events, so there was no reason for text display to share their critical path. **Known trade-off, called out explicitly:** the rewrite lane's prompt used to include tracker/Lorebook Keeper output (via an unconditional `<agent_results>` block built from every other post-processing agent's results) once those had resolved. Since the rewrite lane now starts before that output exists, it no longer sees it — only earlier-phase (parallel) agent results are included, matching exactly what it already saw in chats with no tracker-type agents configured. This is inherent to decoupling the two critical paths per the request; flagging it explicitly since it isn't spelled out anywhere in code comments. Preserved as before: - Lorebook Keeper's own execution still runs after trackers (it reads their committed output) — only text release moved, not Lorebook Keeper's place in the pipeline. - Sequential ordering within the rewrite lane itself (each rewrite-lane agent still sees the prior one's edit). - Agent failure/retry handling for non-text agents still gates the generation-complete signal, not text release. - The existing stop/abort path unblocks new generation immediately regardless. ## Test plan - [ ] Manually verify in the app: a roleplay chat with a slow tracker (or Lorebook Keeper / a custom tracker-type agent) and a rewrite-lane agent (Prose Guardian/Continuity Checker/custom) both active — confirm the reply's real text appears well before the tracker/Lorebook Keeper finish, and that the send/new-message control stays disabled until everything (or Stop) resolves. - [ ] Manually verify no regression when only rewrite-lane agents are configured (no trackers) — placeholder behavior should be unchanged. - [ ] Manually verify a chat with trackers only (no rewrite-lane agents) behaves as before. - [x] `pnpm --filter @marinara-engine/server run lint` (`tsc -b ../shared && tsc --noEmit && tsc -p ../../scripts/regressions/tsconfig.character-activity.json`) — clean, 0 errors. - [x] Added `scripts/regressions/text-rewrite-lane-concurrency.regression.ts` — spins up the real `/generate` route with a fixture provider (a deliberately slow non-text post-processing agent + a fast custom rewrite agent) and asserts `text_rewrite` fires before the slow agent's `agent_result`, while `done` still waits for both. Verified it **fails** against the pre-fix code (reverted the route file locally, reran — assertion failure as expected) and **passes** with the fix. - [x] Updated two existing source-pattern regressions (`agent-activation.regression.ts`, `spatial-context.regression.ts`) that pinned the old single-block code shape; both pass against the new structure. - [x] Ran targeted regressions covering generation/agents/trackers/lorebook/streaming (`agent-context-generation`, `agent-runtime`, `agent-progress`, `agent-scene-check`, `manual-agent-retry-resolution`, `roleplay-streaming`, `one-request-dice-rendering`, `issue-sweep-5391-5394`, `open-issues`) — all pass. - [ ] Full `pnpm regression` (complete Node lane) was not run to completion locally — it's a large, long-running suite; relying on CI for the full run. Everything targeted at the changed area passed. No linked issue exists for this yet — one should be opened before/alongside this PR per `CONTRIBUTING.md § Before You Open a Pull Request`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:17:18 +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#7184
No description provided.