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: check a resumed import's reserved positions against moved survivors too (#10762)

Adam Eivy54fe5f44fa7b
diff --git a/server/services/importer.js b/server/services/importer.js
index 4c86e308c9..67f6b96ce0 100644
--- a/server/services/importer.js
+++ b/server/services/importer.js
@@ -1337,16 +1337,16 @@ async function commitImportOnce({
}
}
}
- // A resume still owes the series unique positions: an issue added since the
- // earlier attempt may have taken a slot the plan reserved for a missing issue.
+ // A resume still owes the series unique positions: since the earlier attempt,
+ // a new issue — or one of this import's survivors, moved — may have taken a
+ // slot the plan reserved for a missing issue. Survivors left where the plan
+ // put them never collide: the plan's positions are distinct.
if (!replaceMode && resumePlan) {
- const takenByOthers = new Set(existingIssues
- .filter((ex) => !resumeLive.has(ex.id) && Number.isInteger(ex.arcPosition))
- .map((ex) => ex.arcPosition));
+ const taken = new Set(existingIssues.map((ex) => ex.arcPosition).filter(Number.isInteger));
resumePlan.items.forEach((item, i) => {
- if (!resumeLive.has(item.issueId) && takenByOthers.has(item.arcPosition)) {
+ if (!resumeLive.has(item.issueId) && taken.has(item.arcPosition)) {
throw codedError(
- `Issue at position ${i + 1} was planned for arcPosition ${item.arcPosition}, which an issue added since now occupies — commit refused before any state changed. Move or delete that issue, then retry to finish this import.`,
+ `Issue at position ${i + 1} was planned for arcPosition ${item.arcPosition}, which another issue now occupies — commit refused before any state changed. Move or delete that issue, then retry to finish this import.`,
ERR_VALIDATION,
);
}
diff --git a/server/services/importer.test.js b/server/services/importer.test.js
index b466a707b6..66b571639e 100644
--- a/server/services/importer.test.js
+++ b/server/services/importer.test.js
@@ -1950,16 +1950,20 @@ describe('commitImport import sessions (#9943)', () => {
expect((await analyze()).importSession).toEqual({ status: 'committed', createdIssueIds: retried.createdIssueIds });
});
- it('refuses to resume onto a planned position another issue took since', async () => {
+ it.each([
+ ['a new issue', (preview) => issuesSvc.createIssue({ seriesId: preview.series.id, title: 'Added since', arcPosition: 2 })],
+ ['the moved survivor', (_preview, survivorId) => issuesSvc.updateIssue(survivorId, { arcPosition: 2 })],
+ ])('refuses to resume onto a planned position %s took since', async (_label, takeSlot) => {
wireDefaultLLMResponses();
const preview = await analyze();
const issues = [{ title: 'I1', arcPosition: 1, proseExcerpt: 'p1' }, { title: 'I2', arcPosition: 2, proseExcerpt: 'p2' }];
- await interruptAfterFirstIssue(preview, issues);
- await issuesSvc.createIssue({ seriesId: preview.series.id, title: 'Added since', arcPosition: 2 });
+ const { context: { survivingIssueIds } } = await interruptAfterFirstIssue(preview, issues);
+ await takeSlot(preview, survivingIssueIds[0]);
+ const before = await issueCount(preview);
await expect(importerSvc.commitImport(payloadFor(preview, { issues })))
.rejects.toMatchObject({ code: importerSvc.ERR_VALIDATION });
- expect(await issueCount(preview)).toBe(2);
+ expect(await issueCount(preview)).toBe(before);
});
it("refuses a changed issue list while an earlier attempt's issues still exist", async () => {