[GH-ISSUE #5406] [Feature]: Authoritative write ordering across experience-state rows and chat metadata #2995

Closed
opened 2026-10-21 05:58:40 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Aug 22, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5406

Originally assigned to: @kolacheee on GitHub.

What exists today

A game-surface Experience's save lives in two stores: the per-anchor game_engine_state row (the authority; rewinds with the story) and a chat-metadata key the package maintains as a boot cache (whole-blob, does not rewind). The package writes both on every flush.

The problem (concrete scenario)

If the package's boot probe of the experience-state route fails transiently (server busy at startup, brief network error), the session degrades to metadata-only writes. Play continues; only the metadata copy advances. At the next boot the package sees the two stores disagree — and cannot safely tell which is newer:

  • "Metadata is ahead because last session was degraded" → it should adopt the metadata copy and write it up (recovering hours of play), or
  • "The row is 'behind' because the player deliberately swiped back to an earlier turn" → adopting metadata would overwrite the historical row and destroy the rewind.

We designed a client-side discriminator four different ways for the Pixelforge S5 plan (write counters, provenance flags, anchorMatched heuristics, anchor stamps) and adversarial review broke each one with a data-destroying counterexample. The root cause is structural: the metadata copy is chat-global and unanchored, the row is per-anchor with fallback-read semantics, and no client-visible value orders writes across the two stores. Until this exists, a degraded session's play is simply lost at the next normal boot (documented as an accepted limitation).

The ask

A server-assigned, per-chat monotonic write ordinal (or trustworthy server timestamp), stamped on both paths and readable by the client:

  • returned on PUT /api/game/:chatId/experience-state and on the row's GET shape, and
  • assigned/returned when a chat-metadata PATCH touches the package's key (or exposed as "last write ordinal for key X").

With one shared ordering, the boot comparison becomes one line: whichever store carries the higher ordinal is newer, timeline moves included. This likely helps any future package with the same two-store shape, not just Pixelforge.

Originally created by @kolacheee on GitHub (Aug 22, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5406 Originally assigned to: @kolacheee on GitHub. ## What exists today A game-surface Experience's save lives in two stores: the per-anchor `game_engine_state` row (the authority; rewinds with the story) and a chat-metadata key the package maintains as a boot cache (whole-blob, does not rewind). The package writes both on every flush. ## The problem (concrete scenario) If the package's boot probe of the experience-state route fails transiently (server busy at startup, brief network error), the session degrades to metadata-only writes. Play continues; only the metadata copy advances. At the next boot the package sees the two stores disagree — and **cannot safely tell which is newer**: - "Metadata is ahead because last session was degraded" → it should adopt the metadata copy and write it up (recovering hours of play), or - "The row is 'behind' because the player deliberately swiped back to an earlier turn" → adopting metadata would overwrite the historical row and destroy the rewind. We designed a client-side discriminator four different ways for the Pixelforge S5 plan (write counters, provenance flags, `anchorMatched` heuristics, anchor stamps) and adversarial review broke each one with a data-destroying counterexample. The root cause is structural: the metadata copy is chat-global and unanchored, the row is per-anchor with fallback-read semantics, and **no client-visible value orders writes across the two stores**. Until this exists, a degraded session's play is simply lost at the next normal boot (documented as an accepted limitation). ## The ask A server-assigned, per-chat monotonic write ordinal (or trustworthy server timestamp), stamped on both paths and readable by the client: - returned on `PUT /api/game/:chatId/experience-state` and on the row's GET shape, and - assigned/returned when a chat-metadata PATCH touches the package's key (or exposed as "last write ordinal for key X"). With one shared ordering, the boot comparison becomes one line: whichever store carries the higher ordinal is newer, timeline moves included. This likely helps any future package with the same two-store shape, not just Pixelforge.
bsakaguchi 2026-10-21 05:58:40 +07:00
Author
Owner

@kolacheee commented on GitHub (Aug 22, 2026):

Claiming this one — starting implementation now on feat/5406-write-ordinal (branched from staging). Will open a draft PR once the shape is validated.

Planned approach: one per-chat monotonic write counter that both stores draw from, so a client can totally order writes across them — a nullable writeOrdinal on the experience-state row (assigned inside the existing per-chat PUT write lock, returned on PUT and GET), plus an engine-owned metadata.metadataWriteOrdinals mirror stamped per top-level key by the queued patchMetadata path. Exact field names and the monotonicity guarantee across the two lock domains will be documented in the PR.

<!-- gh-comment-id:5382471007 --> @kolacheee commented on GitHub (Aug 22, 2026): Claiming this one — starting implementation now on `feat/5406-write-ordinal` (branched from `staging`). Will open a draft PR once the shape is validated. Planned approach: one per-chat monotonic write counter that both stores draw from, so a client can totally order writes across them — a nullable `writeOrdinal` on the experience-state row (assigned inside the existing per-chat PUT write lock, returned on PUT and GET), plus an engine-owned `metadata.metadataWriteOrdinals` mirror stamped per top-level key by the queued `patchMetadata` path. Exact field names and the monotonicity guarantee across the two lock domains will be documented in the PR.
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#2995
No description provided.