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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: worldbuilding refine skips LLM-omitted/blank scalars (no erase) (#2176)
Adam Eivy7adf319c7e82
diff --git a/server/services/pipeline/foundationJudge.js b/server/services/pipeline/foundationJudge.jsindex ef19138655..c12b04eab4 100644--- a/server/services/pipeline/foundationJudge.js+++ b/server/services/pipeline/foundationJudge.js@@ -485,11 +485,17 @@ async function refineWorld(universeId, { providerId, model }) {await updateUniverse(universeId, (latest) => {const locked = latest?.locked || {};const patch = {};- if (locked.logline !== true) patch.logline = expanded.logline;- if (locked.premise !== true) patch.premise = expanded.premise;- if (locked.styleNotes !== true) patch.styleNotes = expanded.styleNotes;- if (expanded.influences && locked.influences !== true) patch.influences = expanded.influences;- if (!Object.keys(patch).length) return null; // every field locked → no-op+ // Only write a scalar the LLM actually authored: expandWorldTemplate returns+ // null (or blank) for an OMITTED field, which is "nothing to add" — NOT a+ // clear. Writing it would erase the existing unlocked value (sanitize turns a+ // non-string into ''). Skip locked fields AND absent/blank ones; preserve the+ // current value in both cases (the CLAUDE.md absent-vs-empty rule).+ const filled = (v) => typeof v === 'string' && v.trim() !== '';+ if (locked.logline !== true && filled(expanded.logline)) patch.logline = expanded.logline;+ if (locked.premise !== true && filled(expanded.premise)) patch.premise = expanded.premise;+ if (locked.styleNotes !== true && filled(expanded.styleNotes)) patch.styleNotes = expanded.styleNotes;+ if (locked.influences !== true && expanded.influences && typeof expanded.influences === 'object') patch.influences = expanded.influences;+ if (!Object.keys(patch).length) return null; // all locked or nothing authored → no-opwrote = true;return patch;});diff --git a/server/services/pipeline/foundationJudge.test.js b/server/services/pipeline/foundationJudge.test.jsindex c4ab477e5f..adcc254759 100644--- a/server/services/pipeline/foundationJudge.test.js+++ b/server/services/pipeline/foundationJudge.test.js@@ -76,6 +76,9 @@ beforeEach(() => {stageRunner.resolveJudgeForStage.mockResolvedValue({ provider: { id: 'judge-x' }, model: 'jm-heavy' });seriesSvc.getSeries.mockResolvedValue({ id: 'ser-1', name: 'S', logline: 'L', premise: 'P', universeId: 'uni-1' });universeBuilder.getUniverse.mockResolvedValue(null);+ // Restore the default authored-scalar echo so a test that overrides it (blank+ // /null values) doesn't leak into later order-dependent tests.+ universeBuilderExpand.expandWorldTemplate.mockResolvedValue({ logline: 'L2', premise: 'P2', styleNotes: 'S2', influences: null });});describe('computeWeightedScore — weighted composite', () => {@@ -255,6 +258,21 @@ describe('applyFoundationFix — dimension → owning-service routing table', ()expect(r.applied).toBe(true);});+ it('worldbuilding refine OMITS an unlocked field the LLM returned blank/null (preserves existing, no erase)', async () => {+ const uni = { id: 'uni-1', name: 'U' };+ universeBuilder.getUniverse.mockResolvedValue(uni);+ // LLM omitted logline (null) and returned an empty premise → neither should+ // be written; only the authored styleNotes lands.+ universeBuilderExpand.expandWorldTemplate.mockResolvedValue({ logline: null, premise: ' ', styleNotes: 'S2', influences: null });+ let writtenPatch = null;+ universeBuilder.updateUniverse.mockImplementation(async (id, m) => { writtenPatch = typeof m === 'function' ? m(uni) : m; return { id, ...(writtenPatch || {}) }; });+ const r = await applyFoundationFix('ser-1', 'worldbuilding', {});+ expect(writtenPatch).not.toHaveProperty('logline');+ expect(writtenPatch).not.toHaveProperty('premise');+ expect(writtenPatch).toMatchObject({ styleNotes: 'S2' });+ expect(r.applied).toBe(true);+ });+it('worldbuilding refine reports applied:false when EVERY refinable field is locked', async () => {const uni = { id: 'uni-1', name: 'U', locked: { logline: true, premise: true, styleNotes: true, influences: true } };universeBuilder.getUniverse.mockResolvedValue(uni);