mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2467] [Issue]: Parallel tool-using agents on different connections clobber chat.metadata (lost-update race) #1209
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#1209
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 @Romuromylus on GitHub (Jun 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2467
Originally assigned to: @SpicyMarinara on GitHub.
Summary
Severity: Medium — concurrency regression. When two tool-using agents run on different connections in the same turn, their stateful built-in tools read-modify-write the shared
chat.metadatablob concurrently, so the second writer's stale snapshot overwrites the first writer's additions (lost update).Expected behavior
Concurrent metadata mutations from parallel agents must not lose writes — either serialize metadata mutations per chat, or merge against a fresh read (main does both).
Actual behavior
Every stateful tool routes through
updateChatMetadata, which reads the shared in-memoryinput.chat.metadata, awaits a full-blobstorage.update, then reassignsinput.chat.metadata:agent-runner.tsbuilds every agent's tool closures over the sameinput, andagent-pipeline.tsexecutePhaseruns groups on different connections concurrently:Two agents on distinct connections each calling a metadata-mutating tool (
write_chat_variable,trigger_event,set_expression,update_game_state,append_chat_summary) interleave read-A → read-B → write-A → write-B; B's update overwrites A's mutation in both the in-memory object and the persisted row. (Agents on the same connection are serialized in afor...of awaitloop, so they do not race.)Steps to reproduce
write_chat_variableortrigger_event) during one turn.Impact area
Environment
1fae2c42Logs, screenshots, or video
Static trace:
tools-runtime.ts:223-233(also inline inupdate_game_state~365-367,append_chat_summary~421-425), parallelism atagent-pipeline.ts:298-315, shared-input entry atagent-runner.ts:1005.Regression notes
Regression vs main, which avoids this two ways at once: a per-chat serialization queue (
withMetadataPatchQueue) plus fresh-read + partial-patch merge inchats.storage.tspatchMetadata. The refactor dropped both, regressing to a shared stale-snapshot full-blob overwrite.Additional context
Fix: route metadata-mutating tools through a per-chat async queue, and/or have
storage.updatemerge partial metadata keys (agentVariables/agentEvents/agentGameStateUpdates) against a fresh read instead of overwriting with a stale clone — i.e. mirror main'spatchMetadata.Template check
Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:
@SpicyMarinara commented on GitHub (Jun 6, 2026):
Fixed on refactor in
038b7220.Tool-driven chat metadata writes are queued per chat and fresh-read before merge, preventing parallel agent lost-update races.
Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.