[PR #5079] [MERGED] fix(game): route time/weather metadata writes through the patch queue (#5076) #6617

Closed
opened 2026-10-23 04:12:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5079
Author: @kolacheee
Created: 8/15/2026
Status: ✅ Merged
Merged: 8/15/2026
Merged by: @kolacheee

Base: staging ← Head: fix/5076-game-metadata-race


📝 Commits (4)

  • 1b28faf fix(game): route time/weather metadata writes through the patch queue (#5076)
  • 3d0e24f test(game): clean up seeded chats in the metadata-race regression
  • a5dda55 Merge branch 'staging' into fix/5076-game-metadata-race
  • 46ea666 Merge branch 'staging' into fix/5076-game-metadata-race

📊 Changes

4 files changed (+133 additions, -13 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 package.json (+1 -1)
📝 packages/server/src/routes/game.routes.ts (+16 -12)
➕ scripts/regressions/game-metadata-race.regression.ts (+114 -0)

📄 Description

Linked issue

Closes #5076

Why this change

Advancing Game Mode time or updating weather could silently revert any other change to the same chat's metadata that landed at the same moment. Both endpoints read the whole metadata blob, mutated one key, and wrote the entire blob back with no queue, so a concurrent write through the queued patch path everything else uses was reverted with no error.

The worst case is a permanent, silent World Map movement lock: the World Maps definition (including its revision counter) lives in that same metadata blob, while the party's location lives in a separate snapshots table. If a definition write (a newly discovered location bumping the revision) lands inside the time-advance window, the definition is rolled back while the snapshot keeps the newer revision, and from then on every map move fails validation as spatial_transition_stale_definition with no visible cause. A player hits the time/weather buttons every session, so the race is easy to trigger during normal play.

What changed

  • POST /game/time/advance and POST /game/weather/update now write through the queued chats.patchMetadata path instead of the unqueued whole-blob chats.updateMetadata, so a concurrent metadata write is merged rather than clobbered.
  • time/advance uses the updater form and recomputes the new time against the queue-fresh metadata, so concurrent time advances also can't lose an update.
  • weather/update writes a narrow { gameWeather } patch at both of its write sites.
  • Added a deterministic regression (scripts/regressions/game-metadata-race.regression.ts, wired into regression:issues) that holds the per-chat metadata queue open and asserts each handler blocks on it (the old whole-blob write bypassed the queue and would already be visible), then that a concurrent metadata write survives after the queue drains.
  • CHANGELOG entry under Fixed.

Other updateMetadata call sites in game.routes.ts share this read-modify-write shape and are worth a follow-up audit, but these two are the ones a player hits every session (scoped per the issue).

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Automated (done): pnpm check and the new game-metadata-race regression pass locally. The regression was confirmed to fail on the pre-fix handler and pass on the fix — it is deterministic (it holds the metadata queue open rather than relying on a timing stress loop), so it locks in the queue adoption.

Still needs a manual pass in a running app (unchecked above on purpose):

  • Reproduce the issue's race with the two-terminal curl loop (PATCH a custom metadata key while POSTing /game/time/advance ~10x) and confirm the custom key survives.
  • In a World Maps game, advance time/weather while the maps agent is updating a definition mid-turn and confirm map movement still works (no spatial_transition_stale_definition lock).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG updated under Fixed. No user-facing docs under docs/ changed, so no docs-i18n follow-up is needed. No version bump.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Game Mode time and weather updates to prevent concurrent changes from overwriting one another.
    • Fixed an issue that could cause World Map movement to become permanently locked after simultaneous game metadata updates.
    • Preserved other game metadata changes while time or weather updates are processed.
    • Improved reliability when multiple game updates occur at the same time.
  • Tests

    • Added regression coverage for concurrent Game Mode metadata updates and related movement behavior.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5079 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/15/2026 **Status:** ✅ Merged **Merged:** 8/15/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/5076-game-metadata-race` --- ### 📝 Commits (4) - [`1b28faf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1b28faf6eb1bd65cc20903e2686cacaf3eb3ec02) fix(game): route time/weather metadata writes through the patch queue (#5076) - [`3d0e24f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3d0e24f13faab093d0a0b9e59c2f614b349fce20) test(game): clean up seeded chats in the metadata-race regression - [`a5dda55`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a5dda55fb34d2dd7381be53e5158544da288d993) Merge branch 'staging' into fix/5076-game-metadata-race - [`46ea666`](https://github.com/Pasta-Devs/Marinara-Engine/commit/46ea66673aba473e8baade6f752d41f05dd89f86) Merge branch 'staging' into fix/5076-game-metadata-race ### 📊 Changes **4 files changed** (+133 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `package.json` (+1 -1) 📝 `packages/server/src/routes/game.routes.ts` (+16 -12) ➕ `scripts/regressions/game-metadata-race.regression.ts` (+114 -0) </details> ### 📄 Description ## Linked issue Closes #5076 ## Why this change Advancing Game Mode time or updating weather could silently revert any other change to the same chat's metadata that landed at the same moment. Both endpoints read the whole metadata blob, mutated one key, and wrote the **entire blob** back with no queue, so a concurrent write through the queued patch path everything else uses was reverted with no error. The worst case is a permanent, silent World Map movement lock: the World Maps definition (including its `revision` counter) lives in that same metadata blob, while the party's location lives in a separate snapshots table. If a definition write (a newly discovered location bumping the revision) lands inside the time-advance window, the definition is rolled back while the snapshot keeps the newer revision, and from then on **every** map move fails validation as `spatial_transition_stale_definition` with no visible cause. A player hits the time/weather buttons every session, so the race is easy to trigger during normal play. ## What changed - `POST /game/time/advance` and `POST /game/weather/update` now write through the queued `chats.patchMetadata` path instead of the unqueued whole-blob `chats.updateMetadata`, so a concurrent metadata write is merged rather than clobbered. - `time/advance` uses the updater form and recomputes the new time against the queue-fresh metadata, so concurrent time advances also can't lose an update. - `weather/update` writes a narrow `{ gameWeather }` patch at both of its write sites. - Added a deterministic regression (`scripts/regressions/game-metadata-race.regression.ts`, wired into `regression:issues`) that holds the per-chat metadata queue open and asserts each handler blocks on it (the old whole-blob write bypassed the queue and would already be visible), then that a concurrent metadata write survives after the queue drains. - CHANGELOG entry under Fixed. Other `updateMetadata` call sites in `game.routes.ts` share this read-modify-write shape and are worth a follow-up audit, but these two are the ones a player hits every session (scoped per the issue). ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Automated (done): `pnpm check` and the new `game-metadata-race` regression pass locally. The regression was confirmed to **fail on the pre-fix handler and pass on the fix** — it is deterministic (it holds the metadata queue open rather than relying on a timing stress loop), so it locks in the queue adoption. Still needs a manual pass in a running app (unchecked above on purpose): - Reproduce the issue's race with the two-terminal curl loop (PATCH a custom metadata key while POSTing `/game/time/advance` ~10x) and confirm the custom key survives. - In a World Maps game, advance time/weather while the maps agent is updating a definition mid-turn and confirm map movement still works (no `spatial_transition_stale_definition` lock). ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) CHANGELOG updated under Fixed. No user-facing docs under `docs/` changed, so no `docs-i18n` follow-up is needed. No version bump. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved Game Mode time and weather updates to prevent concurrent changes from overwriting one another. * Fixed an issue that could cause World Map movement to become permanently locked after simultaneous game metadata updates. * Preserved other game metadata changes while time or weather updates are processed. * Improved reliability when multiple game updates occur at the same time. * **Tests** * Added regression coverage for concurrent Game Mode metadata updates and related movement behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:12:06 +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#6617
No description provided.