Skip to content

Commit 94e415c

Browse files
committed
fix(contracts): old message-sent events without turnId no longer stop the server from starting
`thread.message-sent` events written before `turnId` existed have no key at all, and the payload schema required it. One such row fails the event store read with "Missing key", the server exits during startup, and the desktop app restarts it forever without opening a window. The field now decodes a missing key as null, the same way the other fields added after events were already persisted do.
1 parent c14f601 commit 94e415c

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
@@ -1873,7 +1873,8 @@ export const ThreadMessageSentPayload = Schema.Struct({
18731873
text: Schema.String,
18741874
attachments: Schema.optional(Schema.Array(ChatAttachment)),
18751875
context: Schema.optional(OrchestrationMessageContext),
1876-
turnId: Schema.NullOr(TurnId),
1876+
// Events persisted before the field existed carry no key at all.
1877+
turnId: Schema.NullOr(TurnId).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
18771878
streaming: Schema.Boolean,
18781879
createdAt: IsoDateTime,
18791880
updatedAt: IsoDateTime,

0 commit comments

Comments
 (0)