[GH-ISSUE #2627] [Issue]: /party/recruit merges party/cards from a stale snapshot, not the queued fresh metadata #1297

Closed
opened 2026-10-21 05:31:02 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Romuromylus on GitHub (Jun 18, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2627

Originally assigned to: @Romuromylus on GitHub.

Summary

In game mode, POST /game/party/recruit computes the new party / character-cards / setup-config from a metadata snapshot read before the (multi-second) recruit-card LLM call, then writes them via chats.patchMetadata. Because the callback ignores the fresh metadata it is handed, two recruits (or a recruit racing a /party/remove) that overlap can drop or resurrect a party member.

Expected behavior

Concurrent recruit/remove operations on the same chat should each observe prior committed party state, so no member addition or removal is lost. The recruit's party/card/setup-config merge should happen against the fresh metadata read inside the patchMetadata updater.

Actual behavior

game.routes.ts /party/recruit precomputes updatedPartyIds, updatedCards, and updatedSetupConfig from the pre-LLM meta snapshot, and the patchMetadata(chat.id, () => ({ ... })) callback returns those precomputed values without re-reading freshMeta. The chats.update(chat.id, { characterIds }) sync is likewise derived from the stale party list. A concurrent recruit/remove committed during the LLM window is overwritten on the final blob-level write of gamePartyCharacterIds / gameCharacterCards / gameSetupConfig.

This is the residual concurrency facet of #2613 for the recruit handler specifically. PR #2623 routed the handler through patchMetadata (so unrelated metadata keys — journal, quest, party arcs, etc. — are no longer clobbered), but the recruit's own party/card derivation is still based on the stale read. Flagged by CodeRabbit review on PR #2623.

Steps to reproduce

  1. In a game-mode chat with a party, trigger two /party/recruit calls (or a recruit + a /party/remove) close together so both read party state before either writes.
  2. Observe one operation's party/card change reverted (a recruited member missing, or a removed member resurrected).

Environment

  • Marinara Engine version: staging (post-#2623)
  • Install type: source
  • OS + version: n/a — code review follow-up
  • Browser or app shell: n/a

Logs, screenshots, or video

Static review follow-up; cited to packages/server/src/routes/game.routes.ts /party/recruit (the patchMetadata callback around the gameSetupConfig/gamePartyCharacterIds/gameCharacterCards write).

Additional context

Fix sketch: inside the patchMetadata updater, re-read gamePartyCharacterIds, gameCharacterCards, and gameSetupConfig from the freshMeta argument, merge this recruit's recruitId / generated card / setup-config there (matching the existing card by id), and derive the chats.update(... characterIds ...) sync from the merged party. Deferred from PR #2623 to keep that batch's scope bounded, since a correct merge has to reconcile party-NPC ids and card identity.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 18, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2627 Originally assigned to: @Romuromylus on GitHub. ## Summary In game mode, `POST /game/party/recruit` computes the new party / character-cards / setup-config from a metadata snapshot read before the (multi-second) recruit-card LLM call, then writes them via `chats.patchMetadata`. Because the callback ignores the fresh metadata it is handed, two recruits (or a recruit racing a `/party/remove`) that overlap can drop or resurrect a party member. ## Expected behavior Concurrent recruit/remove operations on the same chat should each observe prior committed party state, so no member addition or removal is lost. The recruit's party/card/setup-config merge should happen against the fresh metadata read inside the `patchMetadata` updater. ## Actual behavior `game.routes.ts` `/party/recruit` precomputes `updatedPartyIds`, `updatedCards`, and `updatedSetupConfig` from the pre-LLM `meta` snapshot, and the `patchMetadata(chat.id, () => ({ ... }))` callback returns those precomputed values without re-reading `freshMeta`. The `chats.update(chat.id, { characterIds })` sync is likewise derived from the stale party list. A concurrent recruit/remove committed during the LLM window is overwritten on the final blob-level write of `gamePartyCharacterIds` / `gameCharacterCards` / `gameSetupConfig`. This is the residual concurrency facet of #2613 for the recruit handler specifically. PR #2623 routed the handler through `patchMetadata` (so unrelated metadata keys — journal, quest, party arcs, etc. — are no longer clobbered), but the recruit's own party/card derivation is still based on the stale read. Flagged by CodeRabbit review on PR #2623. ## Steps to reproduce 1. In a game-mode chat with a party, trigger two `/party/recruit` calls (or a recruit + a `/party/remove`) close together so both read party state before either writes. 2. Observe one operation's party/card change reverted (a recruited member missing, or a removed member resurrected). ## Environment - Marinara Engine version: `staging` (post-#2623) - Install type: source - OS + version: n/a — code review follow-up - Browser or app shell: n/a ## Logs, screenshots, or video Static review follow-up; cited to `packages/server/src/routes/game.routes.ts` `/party/recruit` (the `patchMetadata` callback around the `gameSetupConfig`/`gamePartyCharacterIds`/`gameCharacterCards` write). ## Additional context Fix sketch: inside the `patchMetadata` updater, re-read `gamePartyCharacterIds`, `gameCharacterCards`, and `gameSetupConfig` from the `freshMeta` argument, merge this recruit's `recruitId` / generated card / setup-config there (matching the existing card by id), and derive the `chats.update(... characterIds ...)` sync from the merged party. Deferred from PR #2623 to keep that batch's scope bounded, since a correct merge has to reconcile party-NPC ids and card identity. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:31:02 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1297
No description provided.