mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7446] [MERGED] fix(chats): read a long chat's swipes in one batch so exports don't freeze the server #7737
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#7737
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/7446
Author: @SpicyMarinara
Created: 10/11/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/chat-export-freeze📝 Commits (6)
bebe1edfix(chats): read a long chat's swipes in one batch for export, branch, import and scene fork94965cbfix(scene): read swipes only for the messages a cut-off scene fork copiesf0fdbd2fix(chats): reuse the batched swipes for receipt targets and the branch prefix01627ffMerge remote-tracking branch 'origin/staging' into fix/chat-export-freeze1cb0798Merge branch 'staging' into fix/chat-export-freeze01710c9Merge branch 'staging' into fix/chat-export-freeze📊 Changes
5 files changed (+232 additions, -9 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
packages/server/src/routes/chats.routes.ts(+5 -6)📝
packages/server/src/routes/scene.routes.ts(+7 -1)📝
packages/server/src/services/storage/chats.storage.ts(+18 -2)➕
scripts/regressions/chat-export-swipes-batch.regression.ts(+201 -0)📄 Description
Linked issue
Closes #7445
Why this change
GET /api/chats/:id/export?format=jsonl) on the same seeded data. Half the messages have 2 swipes. Each message has about 500 characters.The rest of that time is the batch insert of the copied messages (see "Left as is" below).
What changed
chats.storage.ts: newgetSwipesByMessageId(ids)reads every swipe once through the existinglistSwipesByMessageIds. It groups them per message and sorts each list by index, the same ordergetSwipesused.serializeChatTranscript(JSONL export, which also serves the bulk ZIP export) reads all swipes in one batch before the message loop.POST /api/chats/:id/branchreads the copied prefix's swipes in one batch. The loop now walks that prefix directly, so theupToMessageIdbreak is gone. The copied set is unchanged.remapRoleplayInterruptionTargets(used by branch and JSONL import) reads the new chat's swipes once and finds receipt targets in that batch. Before, it ran one read per message and one more per receipt. Updates in the loop change onlyextra, so the swipe ids and indexes it reads stay correct.POST /api/scene/forkreads swipes once for the messages it copies.setImmediateyields. After the batch read, a 12,000-message JSONL export holds the loop for about 0.12 s warm. The plain-text export, whose code this PR does not change, holds it for 0.06 s on the same chat. Yielding inside the JSONL loop would save at most about 0.06 s, so it was left out.scripts/regressions/chat-export-swipes-batch.regression.ts:getSwipesreturns for every message. A branch and a JSONL import of it must copy the same swipes in the same order.CHANGELOG.md: one entry under Unreleased.Left as is (same pattern ruled out or not whole-chat)
createMessagesBatchchecks uniqueness against every stored row for each inserted row (findUniqueViolationinfile-backed-store.ts). This is a store-level insert cost, not a per-message swipe read. It is most of the remaining branch and import time: 4.5 s to insert 6,000 messages into a second chat. It needs its own issue.prepareRoleplayInterruptionExtraForCopymakes one read per interruption receipt, not per message. Receipts are rare.bulkSetHiddenFromAIand its undo,advanced-memory.tsvisibility writes, and thecachedPromptcleanup ingenerate.routes.tsread swipes per message alongside per-swipe writes on a bounded set. None of them reads a whole chat.Claim boundary (import/export is risky work)
convertmode copies the same way asclone, but onlyclonewas run.Validation
pnpm checkpasses locallyCONTRIBUTING.mdCommands run by the agent:
pnpm check(exit 0 on the merged branch head)pnpm --filter @marinara-engine/server exec tsc --noEmit -p tsconfig.jsonnode scripts/run-regressions.mjs --filter <file>for:chat-export-swipes-batch(fails on staging, passes here),bulk-export-zips,chat-branch-lineage,chat-story-export,export-budget-413,roleplay-interrupt-storage,scene-package-origin,one-request-dice-branch,message-sharding,message-trash,large-native-json-import,native-export-memory,autonomous-check-storage,capability-gm-verbs,conversation-game-slash,sillytavern-group-import,roleplay-user-private-storage,roleplay-whisper-hidden-recipient,spatial-only-message-visibility,tracker-manual-edit-base,game-inventory-turn,open-issues,persona-api-normalization,assigned-issues-5474-5502,profile-apply-hide-summarised. All passed.coderabbit review --agent --committed --base-commit <merge-base>), three runs:upToMessageIdcutoff. Fixed.Manual verification notes
Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)CHANGELOG.mdhas an Unreleased entry. No files underdocs/changed.UI evidence (if applicable)
Not applicable. This is a server-only change.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.