mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2985] [Issue]: Retry lorebook_update skips the capability gate and mis-attributes custom-agent writes to the lorebook-keeper's target lorebook #1559
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#1559
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/2985
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
On the retry path, the lorebook_update effect handler (1) never checks the emitting agent's capability and (2) always writes to the lorebook-keeper's target/writable set instead of the emitting agent's own. The canonical generate route does both correctly. Consequences on retry: a custom agent WITHOUT edit_lorebooks/create_lorebooks still gets its lorebook writes persisted (capability bypass), and those writes land in the keeper's target lorebook (mis-attribution) when a keeper is present, or in a freshly auto-created lorebook when no keeper ran — never the custom agent's own writable lorebook. This corrupts which lorebook receives entries.
How to reproduce (try it yourself)
lorebook_updatethat emits{updates:[...]}, and do NOT grant it edit_lorebooks/create_lorebooks (and/or point it at lorebook A via its settings).You'll see: the custom agent's updates are persisted regardless of capability, and they land in the keeper's lorebook B (or a new auto-created lorebook) instead of A.
Expected: same behavior as fresh generation — blocked without capability, and otherwise written to the agent's own lorebook A.
Where it is
packages/server/src/routes/generate/retry-agents-route.ts:2499-2520(the lorebook_update block insideapplyRetryResultEffects, defined at line 2177; reached unfiltered via line 3314). Canonical correct behavior:packages/server/src/routes/generate.routes.ts:8734-8772. Persistence helper that auto-creates a lorebook when no target is given:packages/server/src/routes/generate/lorebook-keeper-utils.ts:354-457(auto-create at :362-376).What's happening
The retry effect handler copies neither the capability gate nor the per-result-agent writable-scope resolution from the canonical route. It hard-wires
preferredTargetLorebookId = agentContext.memory._lorebookKeeperTargetLorebookIdandwritableLorebookIds = agentContext.writableLorebookIds, which are keeper-scoped and only populated when the keeper is among the retried agents. A custom agent's lorebook_update result reachesapplyRetryResultEffectsunfiltered, so it persists to whatever the keeper's scope is (or, with both null,persistLorebookKeeperUpdatesauto-creates a new lorebook and writes there).Suggested fix
Mirror the canonical route's gate and per-agent scope resolution using the retry route's OWN local helpers, and add a local writable-id resolver so it compiles. Replace the block at retry-agents-route.ts:2499-2520 with capability checks (
customAgentHasCapability(resultAgent.settings, "edit_lorebooks"/"create_lorebooks"), skipping unless built-in or capable), per-agent writable-id resolution for non-built-in agents, and the canonical refuse-to-write guard when there is no create capability and no valid target. Add a module-levelresolveRetryCustomWritableLorebookIds(settings)next tofindRetryResultAgent(identical to generate.routes.ts:672-685). Regression notes: the canonicalresolveCustomWritableLorebookIdsis private to generate.routes.ts and not importable — hence the local copy; the retry route usesBUILT_IN_AGENT_TYPE_SETandfindRetryResultAgent(notbuiltInAgentTypes/findResultAgent), so a literal copy of the canonical block would not compile. The built-in-keeper branch must keep falling back toagentContext.writableLorebookIds/_lorebookKeeperTargetLorebookIdso built-in keeper retries stay byte-for-byte unchanged. Full code:AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@kolacheee commented on GitHub (Jun 29, 2026):
Cross-checking this against the now-merged Lorebook Keeper fixes (#2970, #2980 in the v2.0.7 branch): this is a separate, still-present bug — not obsoleted by either.
parseLorebookWriteApprovalTextnow emitsaction: "append", andgetExplicitUpdateReplacementContentnow reads nestedentry.content). This issue is about the retry effect handler's capability gate and write-scope — untouched by those changes.origin/staging, just shifted down: it's now atretry-agents-route.ts:2557-2578(the body above cites 2499-2520, which was correct for v2.0.6/main). Still nocustomAgentHasCapabilitygate, and still hardwired toagentContext.memory._lorebookKeeperTargetLorebookId/agentContext.writableLorebookIds— contrast the very nextquest_updateblock, which gates oncustomAgentCanApplyRetryResult(..., "edit_trackers").continues onisAgentWriteApprovalEnvelope(deferring to the #2970 approval-commit path), and because it routes through the samepersistLorebookKeeperUpdates, it inherits #2980's nested-entry.contenthandling for free.Net: re-verified against v2.0.7 — only the line numbers are stale (2499-2520 → 2557-2578); the bug and the suggested fix are unchanged.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in merged staging PR #3004.