mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3047] [Issue]: /conversation/schedule/generate saves schedules via unqueued full-overwrite updateMetadata, clobbering concurrent metadata patches (lost update) #1614
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#1614
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/3047
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
After generating character schedules, the route saves them with
chats.updateMetadata(), which does a FULL JSON overwrite of the chat's metadata column and — unlikechats.patchMetadata()— does NOT run inside the per-chat metadata patch queue. Any metadata write performed bypatchMetadataduring the (LLM-latency-long) generation window is silently lost. Concretely, GET /status/:chatId and POST /autonomous/check both callinheritFreshConversationSchedules(), which usespatchMetadata()to persist inherited schedules / status overrides. A status or autonomous poll that lands while /schedule/generate is mid-flight has its patched keys overwritten when generate finishes, because the final write is built from metadata read BEFORE the generation work plus a stale-snapshot schedules object, and being unqueued it isn't serialized against the patch queue at all. The cross-chat sync loop repeats the same pattern on OTHER chats.How to reproduce (try it yourself)
ensureSchedules()POSTs /conversation/schedule/generate (seconds long due to the LLM call).inheritFreshConversationSchedules()->patchMetadata().You'll see: any metadata key written by the concurrent
patchMetadataafter generate's pre-LLM read (an inherited schedule for another character, a status override) is gone — overwritten by the blind full-document write.Expected: the schedule save merges onto the latest committed metadata and preserves concurrently-patched keys.
Where it is
packages/server/src/routes/conversation.routes.ts:538-548(self-chat save) and570-577(cross-chat sync loop) — both callchats.updateMetadata.packages/server/src/services/storage/chats.storage.ts:459-465(updateMetadata, unqueued full overwrite) vs467-489(patchMetadata, queued viawithChatMetadataPatchQueue).chats.storage.ts:340-367inheritFreshConversationSchedules->patchMetadataat line 360, reached from conversation.routes.ts:595, 712, 863, 903.chats.routes.ts:907-911.What's happening
updateMetadatais a blind stringify-and-write with no compare-and-set and no queue membership, so it is not mutually exclusive withpatchMetadata. The route's "re-read fresh metadata" mitigation only narrows the window — it cannot protect againstpatchMetadatawrites that interleave after the re-read, because there are await boundaries between the read and the write and the write isn't serialized against the queue.Suggested fix
Replace both unqueued
updateMetadatacalls with queuedpatchMetadataupdaters that merge ONLY the entries this run actually changed onto freshly-read committed metadata.Self-chat (conversation.routes.ts:538-548) — patch only the characters this run generated or shared:
Cross-chat sync (conversation.routes.ts:570-577) — re-merge inside the queue against each chat's fresh metadata, layering only the overlapping entries:
Regression note (important): do NOT spread
...newScheduleswholesale into the merge as the naive fix would.newSchedulesis seeded as a stale snapshot read at request start, and characters whose schedule was "fresh" and skipped keep that stale value — spreading it last would re-clobber any newer per-character schedule a concurrent writer committed during the LLM window, reintroducing a narrower form of the same lost update. Merge only the run's actually-produced/overlapping entries ontocurrent.mergeMetadataPatchis a shallow top-level spread, so omitted top-level keys are preserved automatically. This mirrors the canonical pattern at chats.routes.ts:906-924 (/summaries route).AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Claiming this for the current staging sweep in draft PR #3053 (branch
codex/issue-sweep-3033-3052).@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in PR #3053 on branch
codex/issue-sweep-3033-3052(commitbfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.