mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5106] [MERGED] feat(game): host-owned experience-state routes over game_engine_state #6630
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#6630
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/5106
Author: @kolacheee
Created: 8/15/2026
Status: ✅ Merged
Merged: 8/16/2026
Merged by: @kolacheee
Base:
staging← Head:feat/5102-experience-state📝 Commits (8)
2e61291feat(game): host-owned experience-state routes over game_engine_state (#5102)1e56056fix(game): harden experience-state per adversarial review (#5102)4fdcc6cMerge branch 'staging' into feat/5102-experience-state89a43dbMerge remote-tracking branch 'origin/staging' into feat/5102-experience-state32ea749Merge remote-tracking branch 'origin/staging' into feat/5102-experience-state2a05b81fix(game): address CodeRabbit review on the experience-state PRe350c3cMerge remote-tracking branch 'origin/staging' into feat/5102-experience-statec783b7cMerge remote-tracking branch 'origin/staging' into feat/5102-experience-state📊 Changes
11 files changed (+800 additions, -65 deletions)
View changed files
📝
CHANGELOG.md(+2 -0)📝
package.json(+2 -1)📝
packages/server/src/db/file-backed-store.ts(+11 -4)📝
packages/server/src/db/file-query.ts(+5 -1)📝
packages/server/src/db/schema/checkpoints.ts(+5 -0)📝
packages/server/src/routes/chats.routes.ts(+8 -4)📝
packages/server/src/routes/game.routes.ts(+236 -23)📝
packages/server/src/services/game/checkpoint.service.ts(+20 -0)📝
packages/server/src/services/storage/game-engine-state.storage.ts(+117 -27)📝
packages/server/src/services/turn-games/turn-game-runner.service.ts(+14 -5)➕
scripts/regressions/experience-state.regression.ts(+380 -0)📄 Description
Closes #5102
Why
A game-surface Experience (a capability package that owns an entire Game Mode world, e.g. the pixel-RPG Experience) has nowhere correct to keep its world state. The engine's
game_engine_statetable rides every lifecycle seam a game state needs — swipe delete/re-index, message and chat prunes, branch re-anchoring, checkpoint restore — but only the turn-game runner can reach it, and the package route registrar is privileged-only (admin secret off loopback, unusable from Android over LAN). So Experience saves live in chat metadata: a whole-blob store that no engine seam rewinds. Swipes don't rewind the world, branches copy stale state under dead anchors, and checkpoint restores skip it entirely.What changed
Host-owned routes on the game router over
createGameEngineStateStorage:GET /api/game/:chatId/experience-state— the row for the chat's currently-visible anchor (viaresolveVisibleGameStateAnchor, the same resolver game mode and turn-games use, including itscheckpoint_restorerule), falling back to the latest committed save; the response'sanchorMatchedflag says whether the state belongs to the visible anchor or is a fallback (fresh swipe, pruned anchor), so a package can refuse a mismatched world instead of silently continuing it.PUT /api/game/:chatId/experience-state— a bounded save (262,144 serialized chars; route-levelbodyLimitrejects oversize payloads at the socket) anchored to the visible message (""live anchor before the first one). Saves default tocommitted: true, are serialized per chat through a write lock (create is delete-then-insert across an await), and prune to the newest 100 anchors per chat.Scoping and safety:
gameType: "experience:<gameExperienceId>". The stamp is honored only on game-mode chats and re-validated against the setup schema's id shape on every read — the metadata PATCH route merges arbitrary keys, and a malformed (e.g. newline-bearing) id must never reach the namespace. Both verbs refuse unstamped/malformed chats with 409, missing chats with 404.experience:prefix (newnotLikefile-query operator) — so a newer experience save can neither shadow an active turn-game nor be destroyed by one.matchesLikeis also newline-safe now (SQL-LIKE parity), which independently fixes multi-line substring-search misses.create()'s per-anchor dedupe is scoped to the writer's owngameType, and chat branching copies every engine row at an anchor rather thanlimit(1).Checkpoint capture, by value. The pre-existing restore re-lookup (newest row with
createdAt ≤the checkpoint's) is invalid for any writer that delete-recreates a single anchor — every experience save inside one narration turn, and in-place turn games like Tic-Tac-Toe — where it reproducibly restored nothing or a stale world on the auto-checkpoint path. Checkpoints now capture the newest engine-state blob pergameTypeinto a new nullableengineStateDatacolumn at create time (mirroring the existingsnapshotDatacopies; no storage-format bump — additive nullable columns follow repo precedent since format 4) and restore clones those blobs. The legacy lookup remains only for checkpoints created before the field existed. This also closes the documented in-place-turn-game caveat for all new checkpoints.Review process
Round 1 (adversarial review, 2 empirically-reproduced blockers/majors + minors) reshaped the first cut: capture-by-value, both-direction namespace isolation, the mode gate. Round 2 (two-lens verification: an empirical probe suite re-running every pre-fix failure with discrimination controls, plus a fresh adversarial read of the fix layer) confirmed all round-1 failures fixed and surfaced the newline-stamp bypass, the body-limit gap, and the branch-copy
limit(1)hole — all fixed and regression-pinned. Checkpoint blob accumulation (pre-existing forsnapshotData) is deliberately out of scope: #5110.New tracked lane
regression:experience-state(inregression:issues), 14 cases: anchored round-trip (+anchorMatched), unstamped/malformed-stamp/mode-gate refusals with no row written, 404, namespace isolation in both directions at a shared anchor, anchor rewind, live-anchor saves, oversized-state 422, same-anchor replacement + legacy re-lookup + pruning, turn-game visibility under newer experience rows, resign survival, and checkpoint restore after a same-anchor rewrite (the ordering that broke the old heuristic).Follow-up (Marinara-Agents side): migrate the Pixelforge package's saves off chat metadata onto these routes once this ships.
Validation
pnpm checkpnpm regression:experience-state(new, 14 cases)game-checkpoint-engine-state(now exercises the capture path),chat-branch-lineage,conversation-game-slash,game-metadata-race,card-library-search(covers thematchesLikechange)Summary by CodeRabbit
New Features
Bug Fixes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.