mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2984] [Issue]: Batched text_rewrite agents lose markup preservation on retry, so prose-guardian/continuity rewrites are silently dropped (custom rewrites destroy markup) #1558
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1558
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2984
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
When a text_rewrite agent (prose-guardian, continuity, or a custom rewrite agent) is run in a batch on the retry path, it is fed a tag-stripped version of the assistant response instead of the raw markup. As a result its rewrite comes back without the original HTML/XML tags. For prose-guardian/continuity the markup-drop safety guard then trips and silently skips the rewrite (warn log only). For a custom text_rewrite agent the tag-free edit is written anyway, destroying all original HTML/markup in the message. The same agent works correctly when it runs alone or during fresh generation — only retry batching is broken.
How to reproduce (try it yourself)
<div>,<i>,<speaker>— common in roleplay).You'll see: prose-guardian's rewrite is silently skipped (only a "dropped protected markup" warn log). With a custom text_rewrite agent instead, its tag-free edit overwrites the message and wipes the markup.
Expected: the rewrite applies and preserves markup, exactly as it does when prose-guardian runs alone or during fresh generation.
Where it is
packages/server/src/services/agents/agent-executor.ts:762-768(batch call tobuildAgentMessageswith no options object, sopreserveAssistantResponseMarkupdefaults to false),:1769-1773(the<assistant_response>markup branch usesstripHtmlTagswhen the flag is false),:1173-1182(shouldRunAgentIndividuallyomits text_rewrite). Single-agent path sets the flag correctly at:1265-1268. Retry reachability:packages/server/src/routes/generate/retry-agents-route.ts:3159-3166(no text_rewrite carve-out),:2011-2016(non-tool agents batched),:2253-2268(markup-drop guard / overwrite). Guard:packages/server/src/services/generation/text-rewrite-safety.ts:1-17.What's happening
executeAgentBatchbuilds one shared message array viabuildAgentMessages(...)and never forwards the per-agent options that the single-agent path computes — sopreserveAssistantResponseMarkupis false and the shared<assistant_response>block isstripHtmlTags(mainResponse). The main generate route carves text_rewrite agents out of the pipeline so they always run individually, but the retry route does not, andshouldRunAgentIndividuallyonly isolates expression/illustrator/lorebook-keeper/JSON-music. So a batched rewrite agent only ever sees stripped content and returns tag-free editedText, which the markup-drop guard (which compares against the still-tagged original) rejects.Suggested fix
Run text_rewrite agents individually at the single batching chokepoint. Extend
shouldRunAgentIndividually(agent-executor.ts:1173-1182) to also isolate any agent whose RESOLVED result type istext_rewrite(so it covers built-in prose-guardian/continuity, the merged prose-guardian+continuity agent, AND custom agents):This routes every batched text_rewrite agent through
executeAgent→buildStandardAgentMessages, which already setspreserveAssistantResponseMarkup: resultType === "text_rewrite". Regression avoided: do NOT instead threadpreserveAssistantResponseMarkup: trueinto the batch path — the batch builds ONE shared<assistant_response>, so co-batched JSON tracker agents (world-state, director, etc.) would then receive raw markup instead of the deliberately tag-stripped version, wasting tokens and confusing their JSON extraction. The fix MUST key offresolveAgentResultType, notconfig.type— there is no agent literally typedtext_rewrite; it is a RESULT type. First-generation already carves these out before the pipeline, so this is a no-op there.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in merged staging PR #3004.