Skip to content

Commit eab7804

Browse files
t3dotggclaude
andcommitted
fix(server): fork titles skip rolled-back source runs
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ecb8c98 commit eab7804

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,14 @@ function dispatchUserMessage(input: {
152152
});
153153
}
154154

155-
/** Records a finished source run with one exchange, as a provider turn would. */
156-
function recordCompletedRun(input: {
155+
/** Records a settled source run with one exchange, as a provider turn would. */
156+
function recordRun(input: {
157157
readonly threadId: ThreadId;
158158
readonly runId: RunId;
159159
readonly ordinal: number;
160160
readonly user: string;
161161
readonly assistant: string;
162+
readonly status?: "completed" | "rolled_back";
162163
}) {
163164
return Effect.gen(function* () {
164165
const eventSink = yield* EventSink.EventSinkV2;
@@ -203,7 +204,7 @@ function recordCompletedRun(input: {
203204
userMessageId: MessageId.make(`${input.runId}:user`),
204205
rootNodeId: null,
205206
activeAttemptId: null,
206-
status: "completed",
207+
status: input.status ?? "completed",
207208
requestedAt: now,
208209
startedAt: now,
209210
completedAt: now,
@@ -383,18 +384,26 @@ describe("ThreadTitleRegenerationService", () => {
383384
command: "command:title:fork:create",
384385
thread: "thread:title:fork:source",
385386
});
387+
yield* recordRun({
388+
threadId: sourceThreadId,
389+
runId: RunId.make("run:title:fork:0"),
390+
ordinal: 1,
391+
user: "Rolled back attempt",
392+
assistant: "Discarded.",
393+
status: "rolled_back",
394+
});
386395
const forkRunId = RunId.make("run:title:fork:1");
387-
yield* recordCompletedRun({
396+
yield* recordRun({
388397
threadId: sourceThreadId,
389398
runId: forkRunId,
390-
ordinal: 1,
399+
ordinal: 2,
391400
user: "Move session storage from Redis to Postgres",
392401
assistant: "Sessions now persist in the Postgres sessions table.",
393402
});
394-
yield* recordCompletedRun({
403+
yield* recordRun({
395404
threadId: sourceThreadId,
396405
runId: RunId.make("run:title:fork:2"),
397-
ordinal: 2,
406+
ordinal: 3,
398407
user: "Later work the fork never saw",
399408
assistant: "Done.",
400409
});
@@ -436,6 +445,7 @@ describe("ThreadTitleRegenerationService", () => {
436445
assert.include(call?.forkSource?.history, "Move session storage from Redis to Postgres");
437446
assert.include(call?.forkSource?.history, "Sessions now persist in the Postgres");
438447
assert.notInclude(call?.forkSource?.history, "Later work the fork never saw");
448+
assert.notInclude(call?.forkSource?.history, "Rolled back attempt");
439449
const fork = yield* threads.getThreadProjection(forkThreadId);
440450
assert.equal(fork.thread.title, "Generated title");
441451
}).pipe(Effect.provide(harness.layer));

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ const make = Effect.gen(function* () {
7070
const source = yield* threads.getThreadRecords(threadId, ["messages", "runs"], {
7171
messageRoles: ["user", "assistant"],
7272
});
73-
const ordinals = new Map(source.runs.map((run) => [run.id, run.ordinal]));
73+
const ordinals = new Map(
74+
source.runs
75+
.filter((run) => run.status !== "rolled_back")
76+
.map((run) => [run.id, run.ordinal]),
77+
);
7478
const forkOrdinal = ordinals.get(runId) ?? -1;
7579
const messages = source.messages.filter((message) => {
7680
if (message.streaming) return false;

0 commit comments

Comments
 (0)