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

address review (claude): don't strip issues out of a locked non-kept volume in commitDerivedManuscript

[._.]/ Adam Eivy3450ac7e59b8
diff --git a/server/services/pipeline/arcPlanner.js b/server/services/pipeline/arcPlanner.js
index 1189ed8b0e..43eafec2bc 100644
--- a/server/services/pipeline/arcPlanner.js
+++ b/server/services/pipeline/arcPlanner.js
@@ -525,13 +525,26 @@ export async function commitDerivedManuscript(seriesId, { arc, bible, volume, is
// migrates orphans). Re-read first so we merge against the bible write.
const sanitizedArc = sanitizeArc({ ...(arc || {}), status: 'draft' });
const latest = await getSeries(seriesId);
- await commitSeasonsWithRemap(latest, { arc: sanitizedArc, seasons: [targetSeason] });
+ const { series: afterSeasons } = await commitSeasonsWithRemap(latest, { arc: sanitizedArc, seasons: [targetSeason] });
+
+ // A locked NON-target season survives commitSeasonsWithRemap (mergeSeasonsWithLocks
+ // re-inserts it). Pinning its issues onto the target volume would empty a locked
+ // volume — the exact destructive move deleteSeason / bulkReassignSeason refuse.
+ // So leave a locked survivor's issues where they are (deleteSeason's contract).
+ const lockedSurvivorIds = new Set(
+ (afterSeasons?.seasons || [])
+ .filter((s) => s.locked === true && s.id !== targetSeason.id)
+ .map((s) => s.id),
+ );
// 4) Pin every issue onto the single volume and apply per-issue edits.
const editsById = new Map((Array.isArray(issues) ? issues : []).map((e) => [e.id, e]));
await withReexportSuppressed('series', seriesId, async () => {
for (const iss of existingIssues) {
- if (iss.seasonId !== targetSeason.id) {
+ // `iss.seasonId` is the pre-collapse season; a locked survivor keeps its id
+ // (and its issues weren't remapped), so this skip is correct against either
+ // the stale or fresh view.
+ if (!lockedSurvivorIds.has(iss.seasonId) && iss.seasonId !== targetSeason.id) {
await updateIssue(iss.id, { seasonId: targetSeason.id }, { skipRenumber: true });
}
const edit = editsById.get(iss.id);
diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.js
index 1de45db590..139ca1399c 100644
--- a/server/services/pipeline/arcPlanner.test.js
+++ b/server/services/pipeline/arcPlanner.test.js
@@ -1619,4 +1619,29 @@ describe('arcPlanner — manuscript completeness + derive-from-manuscript', () =
const f1 = await issuesSvc.getIssue(i1.id);
expect(f1.stages.idea.input).toBe('frozen synopsis');
});
+
+ it('commitDerivedManuscript does not strip issues out of a locked non-kept volume', async () => {
+ const s = await setupSeries();
+ const v1 = await seasonsSvc.createSeason(s.id, { title: 'V1', number: 1 });
+ const v2 = await seasonsSvc.createSeason(s.id, { title: 'V2 (locked)', number: 2 });
+ await seasonsSvc.updateSeason(s.id, v2.id, { locked: true });
+ const i1 = await issuesSvc.createIssue({ seriesId: s.id, seasonId: v1.id, title: 'Issue 1', arcPosition: 1, stages: { comicScript: { output: 'PAGE 1\nx', status: 'ready' } } });
+ const iLocked = await issuesSvc.createIssue({ seriesId: s.id, seasonId: v2.id, title: 'Locked vol issue', arcPosition: 2, stages: { comicScript: { output: 'PAGE 1\ny', status: 'ready' } } });
+
+ const out = await planner.commitDerivedManuscript(s.id, {
+ arc: { logline: 'L', summary: 'S' },
+ bible: { logline: 'L', premise: 'S', issueCountTarget: 2 },
+ volume: { title: 'The Giant' },
+ issues: [{ id: i1.id, synopsis: 'a' }, { id: iLocked.id, synopsis: 'b' }],
+ });
+
+ // The locked volume survives (commitSeasonsWithRemap re-inserts it) — so we
+ // did NOT collapse to a single volume, and its issue must stay put.
+ const seasonIds = out.series.seasons.map((x) => x.id);
+ expect(seasonIds).toContain(v2.id);
+ const fLocked = await issuesSvc.getIssue(iLocked.id);
+ expect(fLocked.seasonId).toBe(v2.id); // not stripped onto the target volume
+ const f1 = await issuesSvc.getIssue(i1.id);
+ expect(f1.seasonId).toBe(v1.id); // the kept (lowest, unlocked) volume reused its id
+ });
});