Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): cap bundle per-row role to 64 chars; document scraps re-import as lossy-not-corrupt

[._.]/ Adam Eivyd57003556639
diff --git a/server/lib/catalogBulkParsers.js b/server/lib/catalogBulkParsers.js
index 533faf1fe0..21f980b7fa 100644
--- a/server/lib/catalogBulkParsers.js
+++ b/server/lib/catalogBulkParsers.js
@@ -373,11 +373,13 @@ export function parseMarkdownBulk(payload) {
}
const entries = out.map((entry, i) => {
const normalized = normalizeEntry(entry, i);
- // Carry parsed scraps as a NON-enumerable sibling for a faithful
- // round-trip. It must be non-enumerable: the bulk-import route spreads
- // each entry into the `.strict()` catalogIngredientCreateSchema, which has
- // no `scraps` field — an enumerable key would reject every re-imported
- // export that has scraps. Consumers read `entry.scraps` explicitly.
+ // Parse scraps into a NON-enumerable sibling so the markdown re-import is
+ // lossy-but-not-corrupt (per PLAN [catalog-markdown-roundtrip-fences-scraps]):
+ // the bulk-import route does NOT persist scraps today — it spreads each
+ // entry into the `.strict()` catalogIngredientCreateSchema, which has no
+ // `scraps` field, so an enumerable key would reject the whole import. The
+ // data is preserved on `entry.scraps` for any consumer; persisting it into
+ // catalog_scraps/catalog_ingredient_sources is a tracked follow-up.
if (Array.isArray(entry.scraps) && entry.scraps.length > 0) {
attachNonEnumerable(normalized, 'scraps', entry.scraps);
}
diff --git a/server/routes/catalog.js b/server/routes/catalog.js
index 60fc53b18d..9c79eea8fe 100644
--- a/server/routes/catalog.js
+++ b/server/routes/catalog.js
@@ -295,7 +295,11 @@ router.post('/bulk-import', asyncHandler(async (req, res) => {
// explicit `defaults.role` > the bundle row's own `roleForExportedRef` >
// a `bulk-<kind>` fallback.
for (const target of refTargets) {
- const role = defaults.role || perRowRoles[i] || `bulk-${target.refKind}`;
+ // perRowRoles[i] rides as non-enumerable (un-Zod'd) metadata, so cap it
+ // to the /link schema's 64-char limit — a foreign bundle's oversized
+ // role would otherwise hit the role VARCHAR(64) constraint and surface
+ // as a 500 mid-transaction instead of a clean bulk-import rejection.
+ const role = (defaults.role || perRowRoles[i] || `bulk-${target.refKind}`).slice(0, 64);
await client.query(
`INSERT INTO catalog_ingredient_refs (ingredient_id, ref_kind, ref_id, role)
VALUES ($1, $2, $3, $4)