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: keep a finished import resumable until its draft shells are promoted (#10762)

Adam Eivyeb36be20eac9
diff --git a/server/services/importer.js b/server/services/importer.js
index 75c35754e8..4c86e308c9 100644
--- a/server/services/importer.js
+++ b/server/services/importer.js
@@ -784,9 +784,17 @@ function recordCommittedReceipt(importId, createdIssueIds, remappedIssues) {
}).catch((err) => console.error(`❌ importer session ${importId} not marked committed (its issue plan stays resumable): ${err.message}`));
}
-const summarizeImportSession = (session) => (session
- ? { status: session.status, createdIssueIds: session.createdIssueIds }
- : null);
+// A finished import whose receipt was lost (#10762) is reported as committed
+// only once its import-draft shells are promoted: until then the client must
+// still send the commit, which replays the issues and promotes them — a client
+// that took `committed` at its word would skip that and strand the drafts.
+const summarizeImportSession = (session, { universe, series }) => {
+ if (!session) return null;
+ if (session.receiptPending && (universe.importDraft === true || series.importDraft === true)) {
+ return { status: SESSION_STATUS.ARC_PERSISTED, createdIssueIds: [] };
+ }
+ return { status: session.status, createdIssueIds: session.createdIssueIds };
+};
/**
* Phase 1: analyze. Runs canon-extract + arc-extract in parallel (both read
@@ -1025,7 +1033,7 @@ export async function analyzeImport({
isExistingUniverse,
isExistingSeries,
importId,
- importSession: summarizeImportSession(importSession),
+ importSession: summarizeImportSession(importSession, { universe, series }),
canonPreview: {
characters: Array.isArray(canonRun.content?.characters) ? canonRun.content.characters : [],
places: Array.isArray(canonRun.content?.places) ? canonRun.content.places : [],
diff --git a/server/services/importer.test.js b/server/services/importer.test.js
index 1620480425..b466a707b6 100644
--- a/server/services/importer.test.js
+++ b/server/services/importer.test.js
@@ -1878,6 +1878,33 @@ describe('commitImport import sessions (#9943)', () => {
});
});
+ it('keeps a finished import resumable until its draft shells are promoted', async () => {
+ wireDefaultLLMResponses();
+ const preview = await analyze();
+ const issues = [{ title: 'I1', proseExcerpt: 'p1' }];
+ // The last issue lands, then the process dies before promotion and receipt.
+ mockEnsureIssue.mockImplementation(async (...args) => {
+ await realIssuesRef.current.ensureIssueWithId(...args);
+ throw new Error('simulated crash after the write');
+ });
+ mockDeleteIssue.mockRejectedValue(new Error('simulated delete failure'));
+ await expect(importerSvc.commitImport(payloadFor(preview, { issues }))).rejects.toThrow();
+ mockEnsureIssue.mockImplementation((...args) => realIssuesRef.current.ensureIssueWithId(...args));
+ mockDeleteIssue.mockImplementation((...args) => realIssuesRef.current.deleteIssue(...args));
+ expect((await seriesSvc.getSeries(preview.series.id)).importDraft).toBe(true);
+
+ // Not `committed` yet: a client that believed it would never send the
+ // commit that promotes the drafts.
+ const reanalyzed = await analyze();
+ expect(reanalyzed.importSession.status).toBe('arc-persisted');
+ const retried = await importerSvc.commitImport(payloadFor(reanalyzed, { issues }));
+
+ expect(retried.replayed).toBe(true);
+ expect((await seriesSvc.getSeries(preview.series.id)).importDraft).not.toBe(true);
+ expect(await issueCount(preview)).toBe(1);
+ expect((await analyze()).importSession).toEqual({ status: 'committed', createdIssueIds: retried.createdIssueIds });
+ });
+
// The disk state a crash after the first issue leaves: the plan is recorded,
// one issue exists, and nothing rolled it back.
const interruptAfterFirstIssue = async (preview, issues) => {