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: cap mergeCanonByName at BIBLE_LIMITS, gate auto-create on setSaving to prevent double-submit, exclude *.test.js from migration runner, refresh stale comment

[._.]/ Adam Eivya3ce5b1961e0
diff --git a/client/src/pages/UniverseBuilder.jsx b/client/src/pages/UniverseBuilder.jsx
index 93f511916b..0af164a595 100644
--- a/client/src/pages/UniverseBuilder.jsx
+++ b/client/src/pages/UniverseBuilder.jsx
@@ -92,6 +92,12 @@ const mergeVariations = (existing, fresh) => {
// separate place-canon entries, and `Foundry-City`
// vs `Foundry City` would duplicate by name even
// though every downstream lookup treats them as one.
+// Match server's BIBLE_LIMITS.ENTRIES_PER_BIBLE_MAX so the client doesn't
+// optimistically display + count entries the server will silently truncate
+// at sanitize time. Without this cap, the post-expand toast can claim
+// "+12 canon entries" while the server-saved record only kept some of them.
+const CLIENT_CANON_MAX = 200;
+
const mergeCanonByName = (existing, fresh, kind = 'character') => {
// Empty/missing fresh — return `existing` unchanged (preserve reference so
// a no-op expand doesn't trigger downstream identity-comparing effects).
@@ -131,6 +137,7 @@ const mergeCanonByName = (existing, fresh, kind = 'character') => {
if (sluglineKey) seen.add(sluglineKey);
for (const k of aliasMatches) seen.add(k);
if (collides) continue;
+ if (merged.length >= CLIENT_CANON_MAX) break;
merged.push(e);
}
return merged;
@@ -459,10 +466,8 @@ export default function UniverseBuilder() {
categories: draft.categories,
compositeSheets: draft.compositeSheets || [],
// Canon arrays must be included on the manual Save/Create path too —
- // a brand-new world that took the "review then Save" toast path would
- // otherwise drop every expanded canon entry on first create, since
- // only the auto-save branch (which only runs for already-saved worlds)
- // forwards them. See review-resolved Copilot finding on PRRT_kwDOQx8jQ86CpLRw.
+ // the post-expand auto-save covers most paths, but a user editing a
+ // saved world's canon manually still goes through this handler.
characters: draft.characters || [],
settings: draft.settings || [],
objects: draft.objects || [],
@@ -648,6 +653,10 @@ export default function UniverseBuilder() {
// important for the canon section's visibility — it's gated on
// `selectedId && draft.id === selectedId`, so without an id the user
// can't see/manage the canon arrays just merged into the draft.
+ //
+ // Wrap the auto-save in `setSaving(true/false)` so the Create button
+ // (disabled={saving || ...}) can't double-submit during the await window
+ // between expanding=false and goToWorld(saved.id).
if (expandedDraft.name?.trim()) {
const payload = {
name: expandedDraft.name.trim(),
@@ -664,9 +673,12 @@ export default function UniverseBuilder() {
locked: expandedDraft.locked || {},
llm: expandedDraft.llm || {},
};
- const saved = selectedId
- ? await updateUniverse(selectedId, payload).catch((e) => { toast.error(`Auto-save after expand failed: ${e.message}`); return null; })
- : await createUniverse(payload).catch((e) => { toast.error(`Auto-save after expand failed: ${e.message}`); return null; });
+ setSaving(true);
+ const saved = await (selectedId
+ ? updateUniverse(selectedId, payload)
+ : createUniverse(payload))
+ .catch((e) => { toast.error(`Auto-save after expand failed: ${e.message}`); return null; })
+ .finally(() => setSaving(false));
if (saved) {
setWorlds((prev) => {
const without = prev.filter((w) => w.id !== saved.id);
diff --git a/scripts/run-migrations.js b/scripts/run-migrations.js
index 21fa3d1b50..feb24f15cd 100644
--- a/scripts/run-migrations.js
+++ b/scripts/run-migrations.js
@@ -46,9 +46,10 @@ export async function runMigrations({
}
}
- // Scan for migration files (*.js, sorted by filename). Test files live
- // alongside their migration; exclude them so the runner doesn't try to
- // import a vitest module as a migration.
+ // Scan for migration files (*.js, sorted by filename). Co-located vitest
+ // files (*.test.js) are excluded — they don't export `up()` and would
+ // throw the runner if imported as migrations. The vitest config picks
+ // them up via its own glob (`../scripts/migrations/**\/*.test.js`).
const files = (await readdir(migrationsDir))
.filter(f => f.endsWith('.js') && !f.endsWith('.test.js'))
.sort();