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: preserve explicit series design clears across peer sync (#7203)

[._.]/ Adam Eivy1bffe1c6d76e
diff --git a/server/lib/storyArc.js b/server/lib/storyArc.js
index d3457f636e..7e6d4ca398 100644
--- a/server/lib/storyArc.js
+++ b/server/lib/storyArc.js
@@ -522,10 +522,12 @@ export function sanitizeArc(raw) {
// The foreshadowing ledger is identifying content too — an arc whose only
// authored content is a set of planted seeds must survive.
const foreshadowing = sanitizeForeshadowing(raw.foreshadowing);
+ // Keep explicit null in populated arcs: outgoing sync must distinguish a clear
+ // from an old sender that never knew this field. Legacy omission stays absent.
const seriesDesign = sanitizeSeriesDesign(raw.seriesDesign);
if (!logline && !summary && !protagonistArc && themes.length === 0 && !shape && !readerMap && !tickingClock && foreshadowing.length === 0 && !seriesDesign) return null;
const status = ARC_STATUSES.includes(raw.status) ? raw.status : 'draft';
- return { logline, summary, protagonistArc, themes, shape, readerMap, tickingClock, foreshadowing, ...(seriesDesign ? { seriesDesign } : {}), status };
+ return { logline, summary, protagonistArc, themes, shape, readerMap, tickingClock, foreshadowing, ...(raw.seriesDesign !== undefined ? { seriesDesign } : {}), status };
}
/**
diff --git a/server/routes/pipeline.test.js b/server/routes/pipeline.test.js
index e7661eaece..cd96c7d7ab 100644
--- a/server/routes/pipeline.test.js
+++ b/server/routes/pipeline.test.js
@@ -670,7 +670,9 @@ describe('pipeline routes', () => {
await request(app).patch(url).send({ locked: { arc: false } });
const cleared = await request(app).patch(url).send({ arc: { logline: 'Kept', seriesDesign: null } });
expect(cleared.status).toBe(200);
- expect(cleared.body.arc.seriesDesign).toBeUndefined();
+ expect(cleared.body.arc.seriesDesign).toBeNull();
+ const reedited = await request(app).patch(url).send({ arc: { logline: 'Still cleared' } });
+ expect(reedited.body.arc.seriesDesign).toBeNull();
expect(cleared.body.arc.logline).toBe('Kept');
});
diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.js
index 223c8b9c43..2c1a7668e6 100644
--- a/server/services/pipeline/arcPlanner.test.js
+++ b/server/services/pipeline/arcPlanner.test.js
@@ -66,12 +66,16 @@ describe('arcPlanner — generateArcOverview', () => {
])('carries saved design through planning, reviews, model rewrites and rollback: %j', async (seriesDesign) => {
const series = await setupSeries({ arc: { logline: 'Spine', shape: 'man-in-hole', seriesDesign, readerMap: { hooks: [{ label: 'What will the crew discover?' }] } }, seasons: [{ number: 1, title: 'First jobs', synopsis: 'The crew handles its first cases.', episodeCountTarget: 2 }] });
const saved = series.arc.seriesDesign;
- stageRunnerSpy = vi.fn(async () => ({ content: { logline: 'New spine', summary: 'Progress', seriesDesign: { mode: 'finite', endingCondition: 'AI overwrite' }, episodes: [{ number: 1, title: 'Broken pump', synopsis: 'The crew fixes a pump.' }], issues: [], edits: {}, changes: [], rationale: '' }, runId: 'r', providerId: 'p', model: 'm' }));
+ const episode = seriesDesign?.mode === 'finite'
+ ? { number: 1, title: 'The missing ledger', synopsis: 'The investigator finds a ledger that identifies the central suspect.' }
+ : { number: 1, title: 'The broken pump', synopsis: 'The crew repairs a pump but remain divided about acceptable risk.' };
+ stageRunnerSpy = vi.fn(async () => ({ content: { logline: 'New spine', summary: 'Progress', seriesDesign: { mode: 'finite', endingCondition: 'AI overwrite' }, episodes: [episode], issues: [], edits: {}, changes: [], rationale: '' }, runId: 'r', providerId: 'p', model: 'm' }));
const overview = await planner.generateArcOverview(series.id);
expect(overview.arc.seriesDesign).toEqual(saved);
const refine = await planner.refineArc(series.id, 'Tighten the spine.');
expect(refine.arc.seriesDesign).toEqual(saved);
- await planner.generateSeasonEpisodes(series.id, series.seasons[0].id);
+ const planned = await planner.generateSeasonEpisodes(series.id, series.seasons[0].id);
+ await planner.commitEpisodesToIssues(series.id, series.seasons[0].id, planned.episodes);
await planner.verifyArc(series.id);
await planner.verifyVolume(series.id, series.seasons[0].id);
await planner.resolveVerifyIssues(series.id, { findings: [{ severity: 'medium', problem: 'Clarify the episode connection.', suggestion: 'Connect the existing episodes.' }] });
@@ -81,6 +85,8 @@ describe('arcPlanner — generateArcOverview', () => {
expect(context.shapeGuidance).toContain(saved.episodeActivity);
} else expect(context.shapeGuidance).not.toContain('Series design (author-owned');
}
+ expect(stageRunnerSpy.mock.calls.find(([stage]) => stage === 'pipeline-arc-verify')[1].seasonsTreeJson).toContain(episode.title);
+ expect(stageRunnerSpy.mock.calls.find(([stage]) => stage === 'pipeline-volume-verify')[1].volumeIssuesJson).toContain(episode.title);
const snapshot = await planner.snapshotArcState(series.id);
await planner.commitSeasonsWithRemap(series, { arc: { ...overview.arc, seriesDesign: { mode: 'finite', endingCondition: 'AI overwrite' } }, seasons: series.seasons });
await planner.restoreArcState(series.id, snapshot);
diff --git a/server/services/pipeline/arcPlanner/arcCore.js b/server/services/pipeline/arcPlanner/arcCore.js
index 8bb927fbbb..df489982b5 100644
--- a/server/services/pipeline/arcPlanner/arcCore.js
+++ b/server/services/pipeline/arcPlanner/arcCore.js
@@ -58,7 +58,7 @@ export async function generateArcOverview(seriesId, options = {}) {
// The arc-overview prompt doesn't author the reader map — preserve any
// existing one (like `shape`) so regenerating the arc never silently wipes
// a reader map the user already built on the next step.
- seriesDesign: series.arc?.seriesDesign ?? null,
+ seriesDesign: series.arc?.seriesDesign,
readerMap: series.arc?.readerMap ?? null,
// Same for the ticking clock — the overview prompt doesn't author it, so
// preserve any existing countdown across a regenerate.
@@ -235,7 +235,7 @@ export async function refineArc(seriesId, feedback, options = {}) {
protagonistArc: refinedStr(content.protagonistArc, arc.protagonistArc),
themes: refinedThemes,
shape: arc.shape ?? null,
- seriesDesign: arc.seriesDesign ?? null,
+ seriesDesign: arc.seriesDesign,
readerMap: arc.readerMap ?? null,
// The arc-refine prompt edits the narrative fields only — preserve the
// ticking clock (like readerMap/shape) so a refine never wipes it.
@@ -901,7 +901,7 @@ export async function resolveVerifyIssues(seriesId, options = {}) {
// The resolve prompt doesn't author the reader map — preserve any existing
// one so auto-resolve never silently wipes a reader map the user already
// built on the next step. Mirrors `generateArcOverview` above.
- seriesDesign: series.arc?.seriesDesign ?? null,
+ seriesDesign: series.arc?.seriesDesign,
readerMap: series.arc?.readerMap ?? null,
// A sparse repair can move existing countdown beats without replacing them.
tickingClock: mergeTickingClockPatch(series.arc?.tickingClock, edits.arc?.tickingClock).value ?? null,
@@ -1320,7 +1320,7 @@ export async function restoreArcState(seriesId, snapshot, { episodeEdits = null
// `series.seasons[]`.
await withReexportSuppressed('series', seriesId, async () => {
await updateSeries(seriesId, {
- arc: { ...snapshot.arc, seriesDesign: (await getSeries(seriesId)).arc?.seriesDesign ?? null },
+ arc: { ...snapshot.arc, seriesDesign: (await getSeries(seriesId)).arc?.seriesDesign },
seasons: snapshot.seasons,
...(Array.isArray(snapshot.characterArcs) ? { characterArcs: snapshot.characterArcs } : {}),
});
@@ -1625,7 +1625,7 @@ export async function commitSeasonsWithRemap(currentSeries, { arc, seasons }, op
{ status: 400, code: ERR_VALIDATION },
);
}
- const mergedArc = mergeArcWithLocks(latestSeries.arc, { ...arc, seriesDesign: latestSeries.arc?.seriesDesign ?? null }, latestSeries.locked?.arcFields);
+ const mergedArc = mergeArcWithLocks(latestSeries.arc, { ...arc, seriesDesign: latestSeries.arc?.seriesDesign }, latestSeries.locked?.arcFields);
// Per-season locks: restore any locked existing seasons over LLM-proposed
// rewrites, and re-insert any locked seasons the LLM dropped. Re-sanitize
// so the locked records merge with the new shape (sort by number, dedup).
diff --git a/server/services/pipeline/series.js b/server/services/pipeline/series.js
index 871a52c3ee..ab689ee9dd 100644
--- a/server/services/pipeline/series.js
+++ b/server/services/pipeline/series.js
@@ -936,7 +936,7 @@ export async function updateSeries(id, patch = {}) {
...('premise' in patch ? { premise: patch.premise } : {}),
...('universeId' in patch ? { universeId: patch.universeId } : {}),
...('writersRoomWorkId' in patch ? { writersRoomWorkId: patch.writersRoomWorkId } : {}),
- ...('arc' in patch ? { arc: patch.arc && !Object.hasOwn(patch.arc, 'seriesDesign') && cur.arc?.seriesDesign
+ ...('arc' in patch ? { arc: patch.arc && !Object.hasOwn(patch.arc, 'seriesDesign') && Object.hasOwn(cur.arc || {}, 'seriesDesign')
? { ...patch.arc, seriesDesign: cur.arc.seriesDesign } : patch.arc } : {}),
...('seasons' in patch ? { seasons: patch.seasons } : {}),
// Wholesale replace — `characterArcs: []` clears all arcs; omission
diff --git a/server/services/pipeline/series.test.js b/server/services/pipeline/series.test.js
index 7446c3dac7..31c1d56bb8 100644
--- a/server/services/pipeline/series.test.js
+++ b/server/services/pipeline/series.test.js
@@ -65,12 +65,21 @@ describe('pipeline series service', () => {
});
- it('sync preserves an omitted authored brief even in an otherwise empty old arc, but honors explicit clear', async () => {
+ it.each([false, true])('sync preserves omitted intent and exports explicit clears (populated arc: %s)', async (populated) => {
const local = await svc.createSeries({ name: 'Repair crew', arc: { seriesDesign: { mode: 'renewable', continuingTensions: 'Rival approaches to repair.' } } });
await svc.mergeSeriesFromSync([{ ...local, arc: {}, updatedAt: '2099-01-01T00:00:00.000Z' }]);
expect((await svc.getSeries(local.id)).arc.seriesDesign).toEqual(local.arc.seriesDesign);
- await svc.mergeSeriesFromSync([{ ...local, arc: { logline: 'Crew', seriesDesign: null }, updatedAt: '2099-01-02T00:00:00.000Z' }]);
- expect((await svc.getSeries(local.id)).arc.seriesDesign).toBeUndefined();
+ const cleared = await svc.updateSeries(local.id, { arc: { ...(populated ? { logline: 'Crew' } : {}), seriesDesign: null } });
+ // Export uses the persisted record, not the raw PATCH: the clear marker must
+ // survive JSON serialization before a receiving peer can honor it.
+ const outgoing = JSON.parse(JSON.stringify(cleared));
+ if (populated) expect(outgoing.arc.seriesDesign).toBeNull();
+ else expect(outgoing.arc).toBeNull();
+ await svc.updateSeries(local.id, { arc: local.arc }); // receiving peer still holds the old brief
+ await svc.mergeSeriesFromSync([{ ...outgoing, updatedAt: '2099-01-02T00:00:00.000Z' }]);
+ const received = await svc.getSeries(local.id);
+ if (populated) expect(received.arc.seriesDesign).toBeNull();
+ else expect(received.arc).toBeNull();
});
it('projects names and summaries while retaining full editor records and hiding tombstones', async () => {
diff --git a/server/services/storyBuilder.js b/server/services/storyBuilder.js
index 74bad32c4c..51e4405899 100644
--- a/server/services/storyBuilder.js
+++ b/server/services/storyBuilder.js
@@ -1059,7 +1059,7 @@ export async function refineStep(id, stepId, { feedback, entryId, providerId, mo
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, seriesDesign: latest.arc?.seriesDesign ?? null }, latest.locked?.arcFields);
+ const mergedArc = mergeArcWithLocks(latest.arc, { ...arc, seriesDesign: latest.arc?.seriesDesign }, latest.locked?.arcFields);
const updated = await updateSeries(session.seriesId, { arc: mergedArc });
return { result: updated, changes, rationale, runId, providerId: usedProviderId, model: usedModel };
}