mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3006] [Issue]: edit_chat_message silently truncates replacement content at 16 KB (wrong byte cap, no truncated flag) #1578
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#1578
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/3006
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
editChatMessagecaps the full replacement message body toMAX_APPEND_BYTES(16 KB) usingtrimToUtf8Bytes, then persists the truncated text with no indication that truncation occurred.MAX_APPEND_BYTESis the per-append cap for the rolling chat-summary feature, not a message-size limit — it appears to have been copy-pasted into the message-edit path. Chat messages have no length limit in storage, and long roleplay/assistant messages routinely exceed 16 KB. When an agent with theedit_messagescapability callsedit_chat_messagewith a replacement longer than 16 KB, the stored message is silently chopped and the tail is permanently lost. Unlikewrite_chat_variable(which returnstruncated/bytes),edit_chat_messagereturns only{applied, messageId, role, reason}, so neither the model nor the user is told the edit was cut.How to reproduce (try it yourself)
edit_messagescapability soedit_chat_messageis enabled andreplaceChatMessageContentis wired.edit_chat_message({ messageId: "<a real message id>", content: "<a string longer than 16384 UTF-8 bytes>" }).You'll see: the message is truncated to 16 KB; the tool reports
applied:truewith no truncation indicator; content past 16 KB is gone permanently.Expected: the full replacement content is stored (messages have no storage cap), consistent with every other message-writing path.
Where it is
packages/server/src/services/tools/tool-executor.ts:685(thetrimToUtf8Bytes(args.content.trim(), MAX_APPEND_BYTES)call ineditChatMessage); the constantMAX_APPEND_BYTES = 16 * 1024at line 68. The writer that persists with no truncated flag isreplaceChatMessageContentinpackages/server/src/services/generation/tool-resolution-runtime.ts:643-649. The manifest schema has nomaxLengthatpackages/shared/src/features/function-calls/tools/edit-chat-message/manifest.ts:14-17.What's happening
editChatMessagereusesMAX_APPEND_BYTES(named/intended for chat-summary appends) as the cap for a full message replacement. The cap is far smaller than realistic message sizes (lorebook content uses a 64 KB cap), and unlike other writers notruncated/bytesflag is returned, so silent data loss occurs.updateMessageContent(chats.storage.ts:843-848) does a plaindb.update(messages).set({ content })with no length limit.Suggested fix
In
tool-executor.tseditChatMessage, stop applying the chat-summary append cap to full message replacements — pass the trimmed content through unchanged:i.e. replace
trimToUtf8Bytes(args.content.trim(), MAX_APPEND_BYTES)withargs.content.trim(). This matches every other message-writing path (createMessage, updateMessageContent, continuation, prose-guardian rewrites), all of which persist uncapped content.MAX_APPEND_BYTESstays in place for its legitimate use at line 528 (append_chat_summary). Notruncated/bytesflag is needed because no truncation occurs. Existing validation (non-emptymessageId/content, role restriction) is preserved. (Alternative, also acceptable: introduce a dedicatedMAX_CHAT_MESSAGE_BYTES, e.g. 64 KB, and surfacetruncated/byteswhen truncation actually occurs — but since storage caps nothing, dropping the cap is cleaner and more consistent.) No new oversize/DoS exposure: the model already produces and persists arbitrarily long messages through the other paths every turn.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 #3018.