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-arc-refine-feedback]): re-check arc lock at commit time in the arc-only persist
[._.]/ Adam Eivy0440521772c6
diff --git a/server/services/storyBuilder.js b/server/services/storyBuilder.jsindex 754067c874..c4ebf23366 100644--- a/server/services/storyBuilder.js+++ b/server/services/storyBuilder.js@@ -681,6 +681,13 @@ export async function refineStep(id, stepId, { feedback, entryId, providerId, mo// mergeArcWithLocks (the same guard commitSeasonsWithRemap uses), and write// only `arc` — seasons are untouched.const latest = await getSeries(session.seriesId);+ // Re-check the whole-arc lock against the LATEST series, not just the+ // pre-LLM snapshot refineArc saw — commitSeasonsWithRemap does the same, and+ // dropping that re-check (this path bypasses it) would let a refine land if+ // the arc was locked while the LLM call was in flight.+ if (latest.locked?.arc === true) {+ throw makeErr('Arc is locked — unlock it on the Arc Canvas before refining', ARC_ERR_VALIDATION);+ }const mergedArc = mergeArcWithLocks(latest.arc, arc, latest.locked?.arcFields);const updated = await updateSeries(session.seriesId, { arc: mergedArc });return { result: updated, changes, rationale, runId };diff --git a/server/services/storyBuilder.test.js b/server/services/storyBuilder.test.jsindex f522a47064..8f18b07524 100644--- a/server/services/storyBuilder.test.js+++ b/server/services/storyBuilder.test.js@@ -288,6 +288,21 @@ describe('storyBuilder — refine delegation', () => {await expect(sb.refineStep(s.id, 'plotArc', { feedback: 'x' })).rejects.toMatchObject({ code: 'PIPELINE_ARC_VALIDATION' });expect(stageRunnerSpy).not.toHaveBeenCalled();});++ it('refineStep(plotArc) re-checks the arc lock at commit time (locked mid-flight) and does not persist', async () => {+ const s = await sb.createStorySession({ title: 'X' });+ await seriesSvc.updateSeries(s.seriesId, { arc: { logline: 'spine', summary: 'sum' } });+ // Simulate the arc being locked DURING the in-flight LLM call: the stage+ // runner locks the arc before returning, so refineArc's pre-call snapshot+ // saw it unlocked but the commit-time re-read must catch it.+ stageRunnerSpy = vi.fn(async () => {+ await sb.lockStep(s.id, 'plotArc');+ return { content: { logline: 'should not land', summary: 'nope', changes: [], rationale: '' }, runId: 'r', providerId: 'p', model: 'm' };+ });+ await expect(sb.refineStep(s.id, 'plotArc', { feedback: 'x' })).rejects.toMatchObject({ code: 'PIPELINE_ARC_VALIDATION' });+ const after = await seriesSvc.getSeries(s.seriesId);+ expect(after.arc.logline).toBe('spine'); // unchanged — refine did not persist+ });});describe('generateStep backfill (fromDownstream)', () => {