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([story-builder-refine-fallback-changes]): clear changes/rationale when reader-map refine falls back to existing map
[._.]/ Adam Eivy0ad1373546b4
diff --git a/server/services/pipeline/arcPlanner.js b/server/services/pipeline/arcPlanner.jsindex b765b7f23e..a7611f7d14 100644--- a/server/services/pipeline/arcPlanner.js+++ b/server/services/pipeline/arcPlanner.js@@ -937,7 +937,19 @@ export async function refineReaderMap(seriesId, feedback, options = {}) {if (!safeReaderMap) {throw makeErr('LLM returned an empty reader map and there is none to preserve', ERR_VALIDATION);}- return { readerMap: safeReaderMap, changes: trimChanges(content.changes), rationale, runId, providerId, model };+ // When the refine produced nothing usable and we fell back to the existing+ // map, the LLM's `changes`/`rationale` describe an attempt that was DISCARDED+ // — surfacing them would tell the user we applied edits we threw away. Only+ // report changes/rationale when the refined map is the one we're returning.+ const usedRefinedMap = readerMap != null;+ return {+ readerMap: safeReaderMap,+ changes: usedRefinedMap ? trimChanges(content.changes) : [],+ rationale: usedRefinedMap ? rationale : '',+ runId,+ providerId,+ model,+ };}/**diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.jsindex 66bdb6d7e6..dda99e4e1e 100644--- a/server/services/pipeline/arcPlanner.test.js+++ b/server/services/pipeline/arcPlanner.test.js@@ -1526,6 +1526,28 @@ describe('arcPlanner — refineReaderMap', () => {expect(out.readerMap.hooks[0].label).toBe('keep me');});+ it('clears changes/rationale when falling back to the existing map (discarded refine)', async () => {+ const s = await setupSeries({+ arc: { logline: 'rise', summary: 'spine', readerMap: { hooks: [{ label: 'keep me' }] } },+ });+ // The LLM authored a change list + rationale but produced an empty map, so+ // the refine is DISCARDED in favor of the existing map. Those changes/+ // rationale describe edits that were never applied and must be cleared —+ // otherwise the UI claims edits it threw away.+ stageRunnerSpy = vi.fn(async () => ({+ content: {+ hooks: [], payoffs: [], beats: [], cliffhangers: [],+ changes: ['rewrote the opening hook', 'added a midpoint payoff'],+ rationale: 'tightened the front',+ },+ runId: 'r', providerId: 'p', model: 'm',+ }));+ const out = await planner.refineReaderMap(s.id, 'tweak');+ expect(out.readerMap.hooks[0].label).toBe('keep me');+ expect(out.changes).toEqual([]);+ expect(out.rationale).toBe('');+ });+it('throws (rather than returns null) when generateReaderMap yields an empty map', async () => {const s = await setupSeries({ arc: { logline: 'x', summary: 'y' } });stageRunnerSpy = vi.fn(async () => ({