Skip to content

Commit 80d9c18

Browse files
authored
fix(contracts): old message-sent events without turnId no longer stop the server from starting (pingdotgg#12763)
1 parent d2a90b9 commit 80d9c18

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎packages/contracts/src/orchestration.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,37 @@ it.effect("decodes thread pull request links with snapshot and stack", () =>
812812
}),
813813
);
814814

815+
// A stored event that fails to decode stops the event store read, and with it
816+
// server startup, so rows written before `turnId` existed must still load.
817+
it.effect("decodes a legacy message-sent event persisted without turnId", () =>
818+
Effect.gen(function* () {
819+
const event = yield* decodeOrchestrationEvent({
820+
sequence: 539,
821+
eventId: "event-message-legacy-1",
822+
aggregateKind: "thread",
823+
aggregateId: "thread-1",
824+
type: "thread.message-sent",
825+
occurredAt: "2026-01-01T00:00:00.000Z",
826+
commandId: "cmd-message-legacy-1",
827+
causationEventId: null,
828+
correlationId: "cmd-message-legacy-1",
829+
metadata: {},
830+
payload: {
831+
threadId: "thread-1",
832+
messageId: "message-1",
833+
role: "user",
834+
text: "written before turn ids were recorded",
835+
streaming: false,
836+
createdAt: "2026-01-01T00:00:00.000Z",
837+
updatedAt: "2026-01-01T00:00:00.000Z",
838+
},
839+
});
840+
assert.strictEqual(event.type, "thread.message-sent");
841+
if (event.type !== "thread.message-sent") return;
842+
assert.strictEqual(event.payload.turnId, null);
843+
}),
844+
);
845+
815846
it.effect("decodes thread archived and unarchived events", () =>
816847
Effect.gen(function* () {
817848
const archived = yield* decodeOrchestrationEvent({

‎packages/contracts/src/orchestration.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,8 @@ export const ThreadMessageSentPayload = Schema.Struct({
18931893
text: Schema.String,
18941894
attachments: Schema.optional(Schema.Array(ChatAttachment)),
18951895
context: Schema.optional(OrchestrationMessageContext),
1896-
turnId: Schema.NullOr(TurnId),
1896+
// Events persisted before the field existed carry no key at all.
1897+
turnId: Schema.NullOr(TurnId).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
18971898
streaming: Schema.Boolean,
18981899
createdAt: IsoDateTime,
18991900
updatedAt: IsoDateTime,

0 commit comments

Comments
 (0)