mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2644] [MERGED] fix(agents): retry result-loop break, lorebook-write approval gate, tracker-tag sanitizer, PDF-cache poison, multi-pass double-inject #5702
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#5702
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2644
Author: @Romuromylus
Created: 6/19/2026
Status: ✅ Merged
Merged: 6/19/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/agents-retry-approval-tracker-pdf-multipass📝 Commits (1)
f0f09fcfix(agents): retry result-loop break, lorebook-write approval gate, tracker-tag sanitizer, PDF-cache poison, multi-pass double-inject📊 Changes
5 files changed (+118 additions, -62 deletions)
View changed files
📝
packages/server/src/routes/generate/retry-agents-route.ts(+52 -4)📝
packages/server/src/routes/knowledge-sources.routes.ts(+5 -1)📝
packages/server/src/services/agents/agent-executor.ts(+2 -2)📝
packages/server/src/services/agents/knowledge-retrieval.ts(+23 -54)📝
packages/server/src/services/generation/tool-resolution-runtime.ts(+36 -1)📄 Description
Linked issue
Closes #2639
Closes #2640
Closes #2641
Closes #2642
Closes #2643
Why this change
Five independent bugs in the agents subsystem, all in
packages/server. They were filed separately but share a code area and are each small, so I'm batching them into one reviewable PR with a tight, per-issue diff.applyRetryResultEffectsruns every agent result through onefor (const result of sortedResults)loop. Thetext_rewritestale-edit guard ranbreak, which exits the entire loop the moment a rewrite is skipped, silently dropping every later result (tracker, quest, persona, cyoa, illustrator, sprite). On top of that, the guard compared the macro-resolved baseline (currentResponseForRewrite, seeded fromagentContext.mainResponse) against the raw storedcurrentMessage.content, so any message containing literal{{...}}macros falsely tripped "edited during retry" — meaning a perfectly normal retry could drop tracker writes for no reason.save_lorebook_entrytool writer wrote to the lorebook DB immediately, bypassingagentWriteApprovalRequired. Approval only gated the structuredlorebook_updatepath, so an agent that wrote lore via the tool call skipped the user's approval gate entirely.sanitizeTextAgentResponsestripped only the bare<committed_tracker_state>tag, butbuildCommittedTrackerStateContextnow emits<committed_tracker_state message_id="...">. The attributed tag slipped through and a smaller model could leak tracker JSON into the injected directive.extractFileTextcached the"[PDF text extraction failed]"sentinel unconditionally, so a single transient parse failure poisoned that knowledge source for the rest of the process lifetime — every later turn served the failure string instead of re-attempting.extractions.length < chunks.lengthas the "consolidation missing" proxy, but a chunk is also absent fromextractionswhen it returned"No relevant information found.". So when a middle chunk came back empty, it concatenated the raw partials with the final consolidation that had already merged them — double-injecting those facts into the prompt.What changed
routes/generate/retry-agents-route.ts): changed the stale-rewrite guard'sbreaktocontinueso only the stale rewrite is skipped and every later result still persists. Added anexpectedStoredMessageContentbaseline seeded from the raw last-assistant content (threaded in asmainResponseRaw) and advanced toeditedTextafter each applied rewrite, so the guard now compares raw-vs-raw and no longer misfires on macro-bearing messages.services/generation/tool-resolution-runtime.ts+routes/generate/retry-agents-route.ts): both lorebook tool writers (createLorebookEntryWriterand the retryattachRetryLorebookWriterToolContextswriter) now check the approval flag and, when approval is required, return a proposal envelope built withbuildLorebookWriteApprovalProposalinstead of writing inline — mirroring the existing structuredlorebook_updategate.services/agents/agent-executor.ts): made both strips attribute-tolerant —/<committed_tracker_state\b[^>]*>[\s\S]*?<\/committed_tracker_state\s*>/giand the same for the adjacent<assistant_response>strip.routes/knowledge-sources.routes.ts): track anextractionFailedflag and skipsetCachedTextwhen extraction throws, so only successful extractions are cached and a transient failure is re-attempted next turn.services/agents/knowledge-retrieval.ts): track consolidation success with an explicitconsolidatedTextvariable. Return only the consolidated text when the final pass produced output; fall back to concatenating raw partials only when the consolidation pass itself produced nothing.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
/api/generate/retry-agentson a roleplay chat whose assistant message contains a literal{{user}}macro (the false-trigger condition), with a batch of prose-guardian (text_rewrite) + quest + world-state + character-tracker + persona-stats. The stream ranagent_start → 5 agent_results (incl. prose-guardian/text_rewrite, success) → 4 game_state_patch → done: all four tracker writes persisted in the same batch as the rewrite result, no early break, no error. On that run prose-guardian returned no-edit-needed, so the stale-edit guard branch itself wasn't entered — the break-vs-continue decision is covered by the diff +pnpm checkrather than a live trip.save_lorebook_entrytool surfaces a proposal rather than a silent inline lorebook write (both the main generation path and the retry path).<committed_tracker_state message_id="...">context no longer leaks the tracker block into its injected output.Docs and release impact
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.