mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5417] [MERGED] feat(game): authoritative write ordering across experience-state rows and chat metadata #6759
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#6759
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5417
Author: @kolacheee
Created: 8/22/2026
Status: ✅ Merged
Merged: 8/22/2026
Merged by: @kolacheee
Base:
staging← Head:feat/5406-write-ordinal📝 Commits (5)
e724f77feat(game): share one per-chat write ordinal across both experience stores06a98c9fix(game): close the write-ordinal seams an adversarial review foundbcd46datest(game): delete the chat preset the ordinal regression creates3791156Merge upstream/staging into feat/5406-write-ordinalfeb1207Merge upstream/staging into feat/5406-write-ordinal📊 Changes
10 files changed (+1281 additions, -43 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
packages/server/src/db/schema/chats.ts(+13 -0)📝
packages/server/src/db/schema/game-engine-state.ts(+11 -0)📝
packages/server/src/routes/chats.routes.ts(+27 -0)📝
packages/server/src/routes/game.routes.ts(+101 -41)📝
packages/server/src/services/capability-packages/capability-persistence.service.ts(+4 -0)📝
packages/server/src/services/storage/chats.storage.ts(+301 -2)📝
packages/server/src/services/storage/game-engine-state.storage.ts(+14 -0)📝
packages/shared/src/types/chat-preset.ts(+5 -0)➕
scripts/regressions/experience-state-ordinal.regression.ts(+804 -0)📄 Description
Linked issue
Closes #5406
Why this change
game_engine_staterows (engine-rewound by swipes/branches/checkpoints) and chat metadata (rewound by nothing). After a checkpoint restore, branch, or import, "which store is newer" is provably unanswerable from the client side — wall-clock timestamps lie across restores, and freshness counters kept in either store travel with that store's own rewinds. Filed from the Pixelforge S5 planning work, where every client-side arbitration scheme fell to adversarial review; the package's boot logic consumes this ordinal as the authoritative answer.What changed
chats.writeOrdinalCounter, allocates a strictly increasing write ordinal shared by both stores: experience-state PUTs stampgameEngineState.writeOrdinal, and metadata patches stamp an engine-ownedmetadata.metadataWriteOrdinalsmirror per actually-changed top-level key (Object.is+ bounded JSON compare, 32,768-char cap per key, fingerprints captured before the updater runs). Comparison rule for consumers: higher ordinal = newer,null= legacy row/blob, fall back to existing heuristics.max(counter, every mirror ordinal) + 1— so a restored, imported, branched, or preset-applied metadata blob can never time-travel the floor downward and mint duplicate ordinals. The floor lives in the allocator, closing every seam at once instead of patching callers one by one.experience:*rows, and Next Session drops the mirror rather than carrying it into a fresh-counter chat.chat-preset.ts), so applying a preset cannot graft one chat's ordinal history onto another.experience-state-ordinal(13 cases): mirror floors, the branch race, restore-under-lock, Next Session, preset exclusion, in-place-mutating updaters, oversize short-circuit — guards proven fail-first.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Boxes left for the human contributor per the template. What was agent-validated, exactly:
pnpm checkrun on this branch: exit 0 (impeccable, localization, format:check, lint, build).experience-state+experience-state-ordinallanes green, plus 20 adjacent lane runs (checkpoint, game, chat, capability, preset, storage-writer-lock, experience-generation filters) all green; server + shared typecheck green; prettier clean on all 10 touched files. Independently verified by a separate review pass: complete hunk→finding map against the adversarial review, and clean sweeps on lock-order inversion, floor edge cases (0/null/empty mirror), mirror growth (pruned on stamp, pre-prune floor read so pruning never lowers it), restore-path floor bypass, and type laundering.allocateWriteOrdinalnow reads the chat's metadata blob per allocation (to floor against the mirror), and function-updater metadata patches fingerprint object-valued top-level keys (32K cap each) since the changed keys aren't known until the updater runs. Both scale with chat metadata size, not with the ordinal.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.