Skip to content

Commit b796da9

Browse files
only21milclaude
andauthored
perf(server): sending a message no longer rereads the thread from the database after settle, snooze or title updates (pingdotgg#28301)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 4c3808a commit b796da9

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5483,7 +5483,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
54835483
: now,
54845484
updatedAt: now,
54855485
};
5486-
yield* emit(
5486+
const event = yield* emit(
54875487
events,
54885488
command,
54895489
)({
@@ -5493,7 +5493,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
54935493
occurredAt: now,
54945494
payload: thread,
54955495
});
5496-
projection = yield* getProjectionWithPendingEvents(command.threadId, events);
5496+
projection = applyToProjection(projection, event);
54975497
}
54985498
// Background wakes and delegated completions continue work the user already snoozed, so
54995499
// only a message someone actually sent ends the snooze.
@@ -5507,7 +5507,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
55075507
snoozedAt: null,
55085508
updatedAt: now,
55095509
};
5510-
yield* emit(
5510+
const event = yield* emit(
55115511
events,
55125512
command,
55135513
)({
@@ -5517,7 +5517,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
55175517
occurredAt: now,
55185518
payload: thread,
55195519
});
5520-
projection = yield* getProjectionWithPendingEvents(command.threadId, events);
5520+
projection = applyToProjection(projection, event);
55215521
}
55225522
const userMessages = projection.messages.filter((message) => message.role === "user");
55235523
const onlyMaintenanceHistory =
@@ -5537,7 +5537,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
55375537
titleRegeneration: { requestId: command.commandId, startedAt: now },
55385538
updatedAt: now,
55395539
};
5540-
yield* emit(
5540+
const event = yield* emit(
55415541
events,
55425542
command,
55435543
)({
@@ -5554,7 +5554,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
55545554
messageId: command.messageId,
55555555
}),
55565556
]);
5557-
projection = yield* getProjectionWithPendingEvents(command.threadId, events);
5557+
projection = applyToProjection(projection, event);
55585558
}
55595559
const modelSelection = command.modelSelection ?? projection.thread.modelSelection;
55605560
let dispatchMode = resolveMessageDispatchIntent(

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6940,7 +6940,7 @@ it.layer(layerScratchPromotionTest)("turning a No project thread into a project"
69406940
});
69416941

69426942
it.layer(layerSharedApplicationDataPlaneTest)("snooze projection", (it) => {
6943-
it.effect("carries snooze state through the V2 shell projection", () =>
6943+
it.effect("carries snooze, settle and title state through the V2 shell projection", () =>
69446944
Effect.gen(function* () {
69456945
const projects = yield* ProjectService.ProjectService;
69466946
const orchestrator = yield* Orchestrator.OrchestratorV2;
@@ -7009,6 +7009,11 @@ it.layer(layerSharedApplicationDataPlaneTest)("snooze projection", (it) => {
70097009
);
70107010
const [candidate] = yield* projections.getSettlementCandidates(threadId);
70117011
assert.deepEqual(candidate?.lastSnoozeWakeAt, yield* DateTime.now);
7012+
yield* orchestrator.dispatch({
7013+
type: "thread.settle",
7014+
commandId: CommandId.make("runtime-layer-snoozed-thread-settle"),
7015+
threadId,
7016+
});
70127017
yield* orchestrator.dispatch({
70137018
type: "thread.snooze",
70147019
commandId: CommandId.make("runtime-layer-snoozed-thread-snooze-after-wake"),
@@ -7024,6 +7029,7 @@ it.layer(layerSharedApplicationDataPlaneTest)("snooze projection", (it) => {
70247029
threadId,
70257030
messageId: MessageId.make("runtime-layer-snoozed-message"),
70267031
text: "Wake this thread.",
7032+
titleSeed: "Woken thread",
70277033
attachments: [],
70287034
modelSelection,
70297035
dispatchMode: { type: "start_immediately" },
@@ -7032,6 +7038,13 @@ it.layer(layerSharedApplicationDataPlaneTest)("snooze projection", (it) => {
70327038
const awakened = yield* orchestrator.getThreadProjection(threadId);
70337039
assert.isNull(awakened.thread.snoozedUntil);
70347040
assert.isNull(awakened.thread.snoozedAt);
7041+
assert.isNull(awakened.thread.settledOverride);
7042+
assert.isNull(awakened.thread.settledAt);
7043+
assert.equal(awakened.thread.title, "Woken thread");
7044+
assert.equal(
7045+
awakened.thread.titleRegeneration?.requestId,
7046+
CommandId.make("runtime-layer-snoozed-message"),
7047+
);
70357048
}),
70367049
);
70377050

0 commit comments

Comments
 (0)