Skip to content

Commit 0c13691

Browse files
committed
fix(server): persist rejected fork command receipts
1 parent 1dfbdf8 commit 0c13691

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

‎apps/server/src/orchestration-v2/EventSink.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,15 @@ it.effect.each([false, true])(
101101
});
102102
if (deleteFirst) {
103103
yield* deleteSource;
104-
const error = yield* sink.commitCommand(plannedFork).pipe(Effect.flip);
105-
assert.instanceOf(error, EventSink.EventSinkWriteError);
104+
const rejected = yield* sink.commitCommand(plannedFork);
105+
assert.equal(rejected.receipt.status, "rejected");
106+
assert.equal(rejected.receipt.error, "Cannot fork a missing or deleted thread.");
107+
assert.isFalse(rejected.committed);
108+
assert.deepEqual(rejected.storedEvents, []);
109+
const replayed = yield* sink.commitCommand(plannedFork);
110+
assert.deepEqual(replayed.receipt, rejected.receipt);
111+
assert.isFalse(replayed.committed);
112+
assert.deepEqual(replayed.storedEvents, []);
106113
const missing = yield* projections.getThread(targetId).pipe(Effect.flip);
107114
assert.instanceOf(missing, ProjectionStore.ProjectionStoreThreadNotFoundError);
108115
} else {

‎apps/server/src/orchestration-v2/EventSink.ts‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,6 @@ export class EventSinkStreamError extends Schema.TaggedError<EventSinkStreamErro
6363
}
6464
}
6565

66-
class ForkSourceUnavailableError extends Schema.TaggedError<ForkSourceUnavailableError>()(
67-
"ForkSourceUnavailableError",
68-
{ threadId: ThreadId },
69-
) {
70-
override get message(): string {
71-
return "Cannot fork a missing or deleted thread.";
72-
}
73-
}
74-
7566
export const EventSinkV2Error = Schema.Union([EventSinkWriteError, EventSinkStreamError]);
7667
export type EventSinkV2Error = typeof EventSinkV2Error.Type;
7768

@@ -676,8 +667,24 @@ const layerBase: Layer.Layer<
676667
SELECT 1 FROM orchestration_v2_projection_threads
677668
WHERE thread_id = ${sourceId} AND deleted_at IS NULL
678669
`;
679-
if (source.length === 0)
680-
return yield* new ForkSourceUnavailableError({ threadId: sourceId });
670+
if (source.length === 0) {
671+
const receipt: CommandReceiptStore.CommandReceiptV2 = {
672+
commandId: input.commandId,
673+
threadId: input.threadId,
674+
commandType: input.commandType,
675+
acceptedAt: input.acceptedAt,
676+
resultSequence: yield* eventStore.latestSequence({ threadId: input.threadId }),
677+
status: "rejected",
678+
error: "Cannot fork a missing or deleted thread.",
679+
};
680+
yield* commandReceipts.upsert(receipt);
681+
return {
682+
receipt,
683+
storedEvents: [],
684+
committed: false as const,
685+
cancelledEffectIds: [],
686+
};
687+
}
681688
}
682689
}
683690

0 commit comments

Comments
 (0)