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

fix: worldbuilding/craft refine drops human-locked universe fields (#2176)

Adam Eivy464b086c7880
diff --git a/server/services/pipeline/foundationJudge.js b/server/services/pipeline/foundationJudge.js
index f6a68337bb..ef19138655 100644
--- a/server/services/pipeline/foundationJudge.js
+++ b/server/services/pipeline/foundationJudge.js
@@ -476,13 +476,26 @@ async function refineWorld(universeId, { providerId, model }) {
providerId,
model,
});
- await updateUniverse(universeId, {
- logline: expanded.logline,
- premise: expanded.premise,
- styleNotes: expanded.styleNotes,
- ...(expanded.influences ? { influences: expanded.influences } : {}),
+ // Persist through the write-queue mutator against the FRESHEST record, and
+ // defensively DROP any field the user has locked — expandWorldTemplate is
+ // meant to echo locked fields unchanged, but a bad LLM echo (or a lock set
+ // DURING the LLM round-trip) must never overwrite human-locked canon. The
+ // gate's whole contract is "locked entries are constraints, not fix targets."
+ let wrote = false;
+ 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
+ wrote = true;
+ return patch;
});
- return { applied: true };
+ // `wrote === false` means every refinable field is locked — report it so the
+ // gate pauses 'inapplicable' for human review instead of silently no-op-ing.
+ return wrote ? { applied: true } : { applied: false, reason: 'every refinable world field is locked' };
}
/**
diff --git a/server/services/pipeline/foundationJudge.test.js b/server/services/pipeline/foundationJudge.test.js
index c53a4622b8..c4ab477e5f 100644
--- a/server/services/pipeline/foundationJudge.test.js
+++ b/server/services/pipeline/foundationJudge.test.js
@@ -232,16 +232,41 @@ describe('applyFoundationFix — dimension → owning-service routing table', ()
expect(r).toMatchObject({ dimension: 'character', applied: true, entryId: 'thin' });
});
- it('routes worldbuilding → expandWorldTemplate + updateUniverse (locked echoed, no clobber)', async () => {
- universeBuilder.getUniverse.mockResolvedValue({ id: 'uni-1', name: 'U', locked: { logline: true } });
+ it('routes worldbuilding → expandWorldTemplate + a lock-aware updateUniverse write', async () => {
+ const uni = { id: 'uni-1', name: 'U' };
+ universeBuilder.getUniverse.mockResolvedValue(uni);
+ 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(universeBuilderExpand.expandWorldTemplate).toHaveBeenCalledWith(expect.objectContaining({ locked: { logline: true } }));
- expect(universeBuilder.updateUniverse).toHaveBeenCalled();
+ expect(universeBuilderExpand.expandWorldTemplate).toHaveBeenCalledWith(expect.objectContaining({ starterPrompt: 'U' }));
+ expect(writtenPatch).toMatchObject({ logline: 'L2', premise: 'P2', styleNotes: 'S2' });
expect(r).toMatchObject({ dimension: 'worldbuilding', applied: true });
});
+ it('worldbuilding refine DROPS a human-locked field from the write (never clobbers locked canon)', async () => {
+ const uni = { id: 'uni-1', name: 'U', locked: { logline: true } };
+ universeBuilder.getUniverse.mockResolvedValue(uni);
+ 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', {});
+ // logline is locked → the refreshed logline must NOT be in the write patch.
+ expect(writtenPatch).not.toHaveProperty('logline');
+ expect(writtenPatch).toMatchObject({ premise: 'P2', 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);
+ universeBuilder.updateUniverse.mockImplementation(async (id, m) => { const p = typeof m === 'function' ? m(uni) : m; return p === null ? { id } : { id, ...p }; });
+ const r = await applyFoundationFix('ser-1', 'worldbuilding', {});
+ expect(r).toMatchObject({ dimension: 'worldbuilding', applied: false });
+ });
+
it('routes craft → the same universe world refine as worldbuilding', async () => {
- universeBuilder.getUniverse.mockResolvedValue({ id: 'uni-1', name: 'U' });
+ const uni = { id: 'uni-1', name: 'U' };
+ universeBuilder.getUniverse.mockResolvedValue(uni);
+ universeBuilder.updateUniverse.mockImplementation(async (id, m) => { const p = typeof m === 'function' ? m(uni) : m; return { id, ...(p || {}) }; });
await applyFoundationFix('ser-1', 'craft', {});
expect(universeBuilderExpand.expandWorldTemplate).toHaveBeenCalled();
});