mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #5601] A shard file with a valid non-array JSON root loads as empty — no quarantine, and a valid .bak is never consulted #3104
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#3104
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?
Originally created by @kolacheee on GitHub (Aug 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5601
Originally assigned to: @kolacheee on GitHub.
What happens
A shard file whose content is syntactically valid JSON but not an array — for example
{}or{"rows": [...]}after a hand edit, a partial download, or an external tool writing the wrong shape — loads as zero rows with no error, no quarantine, and no backup recovery. The chat (or other entity) silently appears empty, and because JSON parsing succeeded on the primary, a perfectly valid.baksitting right next to it is never consulted.Why
parseJsonFileonly falls back to.bakwhen parsing fails. Both shard-loading paths inpackages/server/src/db/file-backed-store.tsthen guard the root withArray.isArray(value) ? value : []— a non-array root becomes an empty list, somalformedRowCountis0 - 0 = 0and every recovery branch (preserve-source, quarantine, dirty-marking for self-heal) is skipped. This is not new: the eager boot loop and the lazy per-unit loader added in #5597 share the exact same pattern (the lazy path deliberately replicated the eager pipeline), and the boot harvest skips such files the same way. Surfaced by CodeRabbit while reviewing #5597.Try it yourself
then start the server and open that chat: it renders empty, no log line mentions the file, and nothing is quarantined. Restore the array content and the messages return.
Suggested direction
Treat a non-array root as corruption in one place rather than three: teach
parseJsonFile(or a thin wrapper used by the shard paths) to accept a root validator, so a non-array root on the primary triggers the existing.bakfallback, and when both are bad, the existing quarantine path. That keeps eager, lazy, and harvest behavior aligned automatically. The subtlety worth a decision: today.bakis only read when the primary fails to parse — extending "fails" to "fails validation" is the actual fix, and it touches the shared recovery primitive used by every table, which is why this is a standalone change with its own tests rather than a rider on #5597.How verified
Code reading on the #5597 branch (the
Array.isArray(value) ? value : []guard in the eager boot loop, the lazyloadShardFileSync, and the boot harvest) plus the repro above. Behavior is identical with and withoutMARINARA_EAGER_STORAGE=1, confirming it predates the lazy-loading work.