[PR #5411] [MERGED] Return the raw stored text when an experience-state row fails to parse #6756

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

📋 Pull Request Information

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

Base: staging ← Head: feat/5407-rawstate


📝 Commits (2)

  • 1c5c876 feat(game): return the raw stored text when experience state fails to parse
  • 70a731a fix(game): log unreadable experience state at error severity

📊 Changes

3 files changed (+175 additions, -7 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/routes/game.routes.ts (+41 -6)
📝 scripts/regressions/experience-state.regression.ts (+133 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #5407

Why this change

  • When a stored experience-state row fails to parse, the GET currently returns { exists: true, state: null } and drops the raw text — so a package's correct repair (a replacing PUT) destroys the damaged bytes with no way to preserve them first, and a corrupt row is indistinguishable from a legitimately stored null.
  • Filed from the Pixelforge S5 (player state) planning work, where the save block makes corrupt-row recovery worth having.

What changed

  • GET /api/game/:chatId/experience-state: when the stored value is unreadable, the response now carries stateUnparseable: true (always-truthy corruption discriminator), rawState (the stored text, capped at MAX_EXPERIENCE_STATE_CHARS), and rawStateTruncated. Healthy rows are byte-identical to before — none of the three keys appear.
  • A non-string state column (a missing key reading back as null, or a hand-repaired shard holding a real object) is treated as corruption too — a 200 with a string rawState (its JSON text), never a 500 and never a silent state: null masquerading as legitimate. The catch path no longer re-assumes the type it exists to distrust.
  • The parse-failure warn log is now error-object-first per repo convention (note: the SyntaxError message can carry a snippet of the stored text into the log).
  • Regression case 13 extended: verbatim raw text, truncation cap + prefix, healthy/stored-null rows carry no corruption keys, object-column, null-column, and empty-string-column shapes (the last is why the discriminator is a boolean — rawState can legitimately be falsy). Fail-first proven.
  • CHANGELOG entry under Unreleased.

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

  • Agent-run (not manual): experience-state regression lane green (fail-first proven before the change); pnpm lint (typecheck, all 3 packages) green; prettier clean on touched files. format:check on the whole tree false-fails in CRLF worktrees (pre-existing, environmental); CI on LF is authoritative.
  • No UI surface — this is a package-facing HTTP response change; there is nothing to click through in a browser.

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)

Summary by CodeRabbit

  • Bug Fixes

    • Experience state requests now remain successful when stored data is malformed, empty, non-string, or oversized.
    • Invalid state data returns clear corruption details, including bounded raw text and truncation status.
    • Valid states and legitimately stored null values continue to be handled distinctly.
  • Documentation

    • Added changelog documentation for providing recoverable raw saved-world text when parsing fails.

🔄 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/5411 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/22/2026 **Status:** ✅ Merged **Merged:** 8/22/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/5407-rawstate` --- ### 📝 Commits (2) - [`1c5c876`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1c5c876c7b2a2ec374df703102a6e55efa37d9dc) feat(game): return the raw stored text when experience state fails to parse - [`70a731a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/70a731a4dee98705abc2e1da2f087ed7ff4cbd74) fix(game): log unreadable experience state at error severity ### 📊 Changes **3 files changed** (+175 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/routes/game.routes.ts` (+41 -6) 📝 `scripts/regressions/experience-state.regression.ts` (+133 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #5407 ## Why this change - When a stored experience-state row fails to parse, the GET currently returns `{ exists: true, state: null }` and drops the raw text — so a package's correct repair (a replacing PUT) destroys the damaged bytes with no way to preserve them first, and a corrupt row is indistinguishable from a legitimately stored `null`. - Filed from the Pixelforge S5 (player state) planning work, where the save block makes corrupt-row recovery worth having. ## What changed - `GET /api/game/:chatId/experience-state`: when the stored value is unreadable, the response now carries `stateUnparseable: true` (always-truthy corruption discriminator), `rawState` (the stored text, capped at `MAX_EXPERIENCE_STATE_CHARS`), and `rawStateTruncated`. Healthy rows are byte-identical to before — none of the three keys appear. - A **non-string** `state` column (a missing key reading back as null, or a hand-repaired shard holding a real object) is treated as corruption too — a 200 with a *string* `rawState` (its JSON text), never a 500 and never a silent `state: null` masquerading as legitimate. The catch path no longer re-assumes the type it exists to distrust. - The parse-failure warn log is now error-object-first per repo convention (note: the SyntaxError message can carry a snippet of the stored text into the log). - Regression case 13 extended: verbatim raw text, truncation cap + prefix, healthy/stored-null rows carry no corruption keys, object-column, null-column, and empty-string-column shapes (the last is why the discriminator is a boolean — `rawState` can legitimately be falsy). Fail-first proven. - CHANGELOG entry under Unreleased. ## 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 - Agent-run (not manual): `experience-state` regression lane green (fail-first proven before the change); `pnpm lint` (typecheck, all 3 packages) green; prettier clean on touched files. `format:check` on the whole tree false-fails in CRLF worktrees (pre-existing, environmental); CI on LF is authoritative. - No UI surface — this is a package-facing HTTP response change; there is nothing to click through in a browser. ## Docs and release impact - [x] 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) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Experience state requests now remain successful when stored data is malformed, empty, non-string, or oversized. - Invalid state data returns clear corruption details, including bounded raw text and truncation status. - Valid states and legitimately stored `null` values continue to be handled distinctly. - **Documentation** - Added changelog documentation for providing recoverable raw saved-world text when parsing fails. <!-- 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:13:26 +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#6756
No description provided.