Skip to content

Commit 8d7c4c0

Browse files
committed
fix(server): order orphaned question dismissals after requests
1 parent 92ea3ee commit 8d7c4c0

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3847,7 +3847,7 @@ describe("ProviderCommandReactor", () => {
38473847
);
38483848
const threadId = ThreadId.make("thread-1");
38493849
const requestId = asApprovalRequestId("orphaned-question");
3850-
const createdAt = "2026-01-01T00:00:01.000Z";
3850+
const createdAt = "2099-01-01T00:00:01.000Z";
38513851
if (status !== "missing") {
38523852
yield* harness.engine.dispatch({
38533853
type: "thread.session.set",
@@ -3939,6 +3939,16 @@ describe("ProviderCommandReactor", () => {
39393939
turnId: "old-turn",
39403940
payload: { requestId },
39413941
});
3942+
if (status !== "running") {
3943+
expect(Option.getOrThrow(latest).createdAt > createdAt).toBe(true);
3944+
}
3945+
const events = yield* harness.engine.readEvents(0).pipe(Stream.runCollect);
3946+
const resolutions = events.filter(
3947+
(event) =>
3948+
event.type === "thread.activity-appended" &&
3949+
event.payload.activity.kind === "user-input.resolved",
3950+
);
3951+
expect(resolutions).toHaveLength(status === "running" ? 0 : 1);
39423952
const shell = yield* harness.snapshotQuery.getThreadShellById(threadId);
39433953
expect(Option.getOrThrow(shell).hasPendingUserInput).toBe(status === "running");
39443954
expect(harness.respondToUserInput).toHaveBeenCalledTimes(status === "running" ? 2 : 0);

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,16 @@ const make = Effect.gen(function* () {
16161616
request.value.payload.responseMode === "message"
16171617
)
16181618
) {
1619+
// Legacy activities have no sequence, so their durable lookup orders
1620+
// by timestamp even when the client or server clock has moved back.
1621+
const resolvedAt = DateTime.formatIso(
1622+
DateTime.makeUnsafe(
1623+
Math.max(
1624+
DateTime.toEpochMillis(yield* DateTime.now),
1625+
DateTime.toEpochMillis(DateTime.makeUnsafe(request.value.createdAt)) + 1,
1626+
),
1627+
),
1628+
);
16191629
yield* orchestrationEngine.dispatch({
16201630
type: "thread.activity.append",
16211631
commandId: yield* serverCommandId("orphaned-user-input-resolved"),
@@ -1627,9 +1637,9 @@ const make = Effect.gen(function* () {
16271637
summary: "User input dismissed because the provider session ended",
16281638
payload: { requestId: event.payload.requestId },
16291639
turnId: request.value.turnId,
1630-
createdAt: event.payload.createdAt,
1640+
createdAt: resolvedAt,
16311641
},
1632-
createdAt: event.payload.createdAt,
1642+
createdAt: resolvedAt,
16331643
});
16341644
}
16351645
return;

0 commit comments

Comments
 (0)