mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5879] [MERGED] feat(server): let capability packages register their own file tables #6977
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#6977
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/5879
Author: @Gunterlie
Created: 9/5/2026
Status: ✅ Merged
Merged: 9/5/2026
Merged by: @Gunterlie
Base:
staging← Head:feat/capability-package-file-tables📝 Commits (3)
5a3155afeat(server): let capability packages register their own file tables6a274cafix(server): harden package table registration against bad definitions898f5c2test(server): assert registration continues past a malformed package table📊 Changes
5 files changed (+699 additions, -33 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
packages/server/src/db/file-backed-store.ts(+315 -31)📝
packages/server/src/routes/backup.routes.ts(+14 -1)📝
scripts/regressions/launcher/format-guard.regression.mjs(+4 -1)➕
scripts/regressions/package-table-registration.regression.ts(+365 -0)📄 Description
Linked issue
Closes #5878
Why this change
The Slurp capability package needs package-owned storage. Slurp declares its own file tables and cannot persist them.
The file-backed store builds every table's metadata once at module load, from a hardcoded allowlist of the Engine's own tables. Any name outside that list has no metadata, so
getMeta()throws[file-storage] Unsupported table: <name>. A downloaded capability package therefore has no supported way to persist its own data; it can only borrow an Engine table that was designed for something else.This PR closes the Engine-side gap: it adds the storage API that accepts package-declared tables into a live store.
What changed
registerTableson the store controller. Packages activate afterinitialize(), so registration runs against an already-running store rather than at boot. A registered table gets everything a boot-loaded table gets, because the alternative is a table that accepts writes and silently loses them: validated metadata, a row container, its existing on-disk rows, membership in the flush loop, and an entry in the snapshot manifest. Registration is idempotent, so a package reload re-registering the same table does not reset it. It cannot shadow a table that already exists — the first definition of a name, always the Engine's own since those are built at module load, keeps the name. Failures are per table and logged rather than thrown, so one malformed package table definition cannot abort host startup.Table-name validation. Table names become filesystem paths (
tables/<name>.json,tables/<name>/) with no escaping anywhere in the store. That was safe only while every name came from the Engine's own hardcoded list; an unvalidated package-supplied name would be an arbitrary-write primitive outside the data directory.fileBackedTableNameRejectionnow gates every registered name and accepts only what the Engine's own names already look like: non-empty, at most 64 characters, matching/^[a-z][a-z0-9_]*$/, and not a Windows reserved basename (Windows blocks those with any extension). The length bound keeps<name>.jsonplus a shard filename inside path limits. A rejected name is refused before it reaches any path join or any registry.The regression asserts this against the real store: it registers a set of hostile names —
../../escaped,..,nested/table,back\slash,Uppercase,trailing.,with space,_leading,9leading,con, and a 65-character name — and then walks the entire sandbox tree, which is one level above the storage directory so an escape would land somewhere the test can see. It asserts that no rejected name joins the file-backed table list and that not one file or directory was created, inside or outside the data directory.Sharding. Registered tables are sharded, like every Engine table.
SHARDED_TABLESaliasesFILE_BACKED_TABLES, so a name pushed onto the list becomes sharded by array identity whether or not that was intended; making registered tables flat would opt a brand-new table into the store's least-exercised path and would still leave the alias lying about them. That aliasing was also a trap worth closing:SHARDED_TABLE_SETused to be a module-load snapshot of the list, so after registration the array said "sharded" and the set said "not sharded", and the load, flush and delete paths would each have classified the same table differently. The set is now mutable and registration writes the list and the set together, or neither.No primary key is refused at registration. Registered tables have no
SHARD_KEY_COLUMNSentry, so they shard by primary key. A keyless table would register cleanly and then throw "no stable shard key" on its first insert, long after a package author could connect the failure to the definition. It is now refused up front, before the name enters any registry.Profile export/import. Registered tables persist exactly like Engine tables and are captured by a full data-directory backup, but they are deliberately excluded from profile export.
profileTableObjectsinbackup.routes.tsis built from the schema barrel, so a runtime-registered table has no entry and every loop skips it. That exclusion is intentional, not an oversight to fix by consulting the live registry: a profile snapshot is portable user data that may be restored into a different install where the owning package does not exist, so importing those rows would be a restore-time failure or a silent orphan with no schema to validate against. A comment at that site records the reasoning.Known constraint — the registries are process-global.
tableMetasByName,FILE_BACKED_TABLE_SETandSHARDED_TABLE_SETare module-level, as the Engine's own table metadata already is. A registered name therefore outlives the store that registered it: a store constructed later in the same process, against a different storage directory, already knows the name, boot-loads it from its own directory, and finds nothing. That degrades to an empty table, never to corruption or a cross-directory read. It is accepted because production runs one store per process, and because the alternative — instance-scoped registries — means threading a store throughgetMeta()and the entire module-level lookup surface. Per-instance registration is the correct fix if the Engine ever runs more than one store at a time. Until then there is a concrete consequence for tests: a test that constructs several stores must give each scenario a distinct table name, or its second store silently exercises the boot loader instead ofregisterTables. The regression follows that rule explicitly, with a comment at each case that needs a fresh name.No caller is wired yet. Nothing in the Engine currently loads package-supplied table objects. This PR is the storage-side API only; connecting a package loader to it is separate work.
Also included:
FILE_BACKED_TABLESis now a widened runtime list built fromBUILT_IN_FILE_BACKED_TABLES, so every consumer that walks "all file-backed tables" sees registered names. The Engine's own tuple keeps its literal-union type soCASCADESand other table-name constants stay compile-checked. The list itself is module-private; the only sanctioned way to grow it isregisterTables, which validates the name and updates every companion registry in the same breath.scripts/regressions/launcher/format-guard.regression.mjsnow compares the launcher'sSHARDED_TABLEScopy againstBUILT_IN_FILE_BACKED_TABLESrather than the widened list. An offline downgrade script can never know a runtime-registered name.loadRegisteredTableRowsreads a newly registered table's existing shards. It is deliberately thinner than the boot loader: the re-home detection, duplicate arbitration and format-migration repair there exist for histories a table the Engine has never written cannot have. Corrupt-file recovery still applies, because that comes fromparseJsonFileand applies to any file on disk.buildFileTableMetadatais extracted so schema-declared and package-registered tables share the same shape and unique-constraint validation.scripts/regressions/package-table-registration.regression.ts(auto-discovered by the runner).Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
The checkboxes above are left unticked for a human to confirm. This change has no UI surface and no wired caller, so the meaningful verification is the new regression, which drives the real store end to end rather than a mock. It is written to be run as
node ./scripts/run-regressions.mjs --filter package-table-registrationafterpnpm build:shared, and each case builds a real store over a fresh temporary storage directory:.bak, so normal store bookkeeping stays out of the comparison), snapshot the whole sandbox, register each hostile name plus a keyless table, flush again, and assert the sandbox tree is byte-for-byte unchanged and no rejected name enteredFILE_BACKED_TABLES.<name>.jsonmonolith was also created. Then close the store, open a new one over the same directory, register again, and confirm the row is read back with its values intact. Delete the row, flush, and confirm the emptied shard is removed rather than left as litter.chatsrow, register an impostor table also namedchatswith different columns, and confirm the Engine's rows and column metadata are untouched and the name is not duplicated in the table list..bak. Registration must recover the rows and mark the shard dirty; the test then flushes and reads the file back to confirm it was rewritten canonically, so the next boot does not recover from backup all over again..bak. There is no shard key to dirty, so the file is marked stale instead; the test confirms the flush removes the primary and its backup rather than leaving a corrupt pair that is re-recovered and re-logged on every boot..bakthat both fail to parse, and confirm both are quarantined for manual inspection, reported throughgetQuarantinedTables()against the registered table, and left undisturbed by the following flush.The regression sets
LOG_LEVEL=silentbefore importing the store, because these cases deliberately provoke error-level rejections and quarantine reports, and the pretty-print transport worker can otherwise outlive the test and hang the runner.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue openedA
CHANGELOG.mdentry is added under[Unreleased]. No user-facing docs change, because there is no user-facing surface yet. No version bump.UI evidence (if applicable)
Not applicable; no UI surface.
Summary by CodeRabbit
New Features
Bug Fixes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.