Skip to content

Commit c3a932a

Browse files
committed
fix(server): record snooze wake when pinning a thread
1 parent 1c443f6 commit c3a932a

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
28402840
settledAt: thread.settledOverride === "settled" ? null : thread.settledAt,
28412841
snoozedUntil: null,
28422842
snoozedAt: null,
2843+
lastSnoozeWakeAt: thread.snoozedUntil == null ? thread.lastSnoozeWakeAt : now,
28432844
updatedAt: alreadyPinned && !promotes ? thread.updatedAt : now,
28442845
};
28452846
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4507,6 +4507,44 @@ it.layer(layerSharedApplicationDataPlaneTest)("snooze projection", (it) => {
45074507
snoozedUntil,
45084508
});
45094509

4510+
yield* orchestrator.dispatch({
4511+
type: "thread.pin",
4512+
commandId: CommandId.make("runtime-layer-snoozed-thread-pin-wake"),
4513+
threadId,
4514+
orderKey: "a0",
4515+
});
4516+
const pinAwakened = yield* orchestrator.getThreadProjection(threadId);
4517+
const pinWakeAt = yield* DateTime.now;
4518+
assert.deepEqual(pinAwakened.thread.lastSnoozeWakeAt, pinWakeAt);
4519+
assert.isNull(pinAwakened.thread.snoozedUntil);
4520+
assert.isNull(pinAwakened.thread.snoozedAt);
4521+
assert.deepEqual(pinAwakened.thread.unsettledAt, firstProjection.thread.unsettledAt);
4522+
yield* TestClock.adjust("10 seconds");
4523+
yield* orchestrator.dispatch({
4524+
type: "thread.pin",
4525+
commandId: CommandId.make("runtime-layer-snoozed-thread-pin-again"),
4526+
threadId,
4527+
orderKey: "a1",
4528+
});
4529+
const pinnedAgain = yield* orchestrator.getThreadProjection(threadId);
4530+
assert.deepEqual(pinnedAgain.thread.lastSnoozeWakeAt, pinWakeAt);
4531+
assert.equal(pinnedAgain.thread.pinOrderKey, "a0");
4532+
yield* orchestrator.dispatch({
4533+
type: "thread.unpin",
4534+
commandId: CommandId.make("runtime-layer-snoozed-thread-unpin-after-wake"),
4535+
threadId,
4536+
});
4537+
assert.deepEqual(
4538+
(yield* projections.getSettlementCandidates(threadId))[0]?.lastSnoozeWakeAt,
4539+
pinWakeAt,
4540+
);
4541+
yield* orchestrator.dispatch({
4542+
type: "thread.snooze",
4543+
commandId: CommandId.make("runtime-layer-snoozed-thread-snooze-after-pin"),
4544+
threadId,
4545+
snoozedUntil,
4546+
});
4547+
45104548
yield* orchestrator.dispatch({
45114549
type: "message.dispatch",
45124550
createdBy: "user",

0 commit comments

Comments
 (0)