Skip to content

Commit 1337258

Browse files
t3dotggclaude
andcommitted
fix(server): skip folded async answers when chaining model switches
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 44d1758 commit 1337258

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5318,7 +5318,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
53185318
providerTurnId: null,
53195319
providerThreadId: restartProviderThread.id,
53205320
providerInstanceId: input.modelSelection.instanceId,
5321-
// Measured before the restart rewrites the run, so it compares with the selection it replaces.
5321+
// Measured on the pre-restart projection, so the rewritten run is not its own baseline.
53225322
...(restartHandoff === null ? modelSwitchSince(input.projection, input.modelSelection) : {}),
53235323
});
53245324
const interruptedAttemptId = targetRun.activeAttemptId;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,26 @@ describe("modelSwitchSince", () => {
5454
});
5555

5656
it("skips messages clients hide", () => {
57-
const [first, pending, compact] = shown("first", "pending", "/compact");
57+
const [first, pending, compact, answer] = shown(
58+
"first",
59+
"pending",
60+
"/compact",
61+
"async-answer:question",
62+
);
5863
expect(
5964
modelSwitchSince(
6065
{
6166
runs: [
6267
run("first", 1, "a"),
6368
run("pending", 2, "b", "cancelled"),
6469
run("/compact", 3, "c"),
70+
run("async-answer:question", 4, "d"),
6571
],
6672
turnItems: [
6773
first!,
6874
{ ...pending!, inputIntent: "queued_turn", status: "pending" },
6975
compact!,
76+
answer!,
7077
] as OrchestrationV2ThreadProjection["turnItems"],
7178
},
7279
selection("c"),

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ import { modelSelectionsEqual } from "@t3tools/shared/model";
88
import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";
99

1010
/**
11-
* The model or effort change a new run brings, measured from the latest run the timeline shows,
12-
* through its message or its handoff row, so consecutive dividers always chain. `baseline` stands in when there is none,
13-
* such as a fork's source run. Callers skip starts with a context handoff; the handoff item already
14-
* shows those.
11+
* The model or effort change a new run brings, measured from the latest run the timeline shows
12+
* through its message or its handoff row, so consecutive dividers always chain. `baseline` stands
13+
* in when there is none, such as a fork's source run. Callers skip starts with a context handoff;
14+
* the handoff item already shows those.
1515
*/
1616
export function modelSwitchSince(
1717
projection: Pick<OrchestrationV2ThreadProjection, "runs" | "turnItems">,
1818
to: ModelSelection,
1919
baseline?: ModelSelection,
2020
): Pick<Extract<OrchestrationV2TurnItem, { type: "user_message" }>, "modelSwitch"> {
21-
// Clients hide pending queued messages and replace `/compact` with a compaction row.
21+
// Clients hide pending queued messages, fold async answers into their question, and replace
22+
// `/compact` with a compaction row.
2223
const shown = new Set(
2324
projection.turnItems.flatMap((item) =>
2425
item.type === "user_message" &&
2526
!(item.inputIntent === "queued_turn" && item.status === "pending") &&
27+
!item.messageId.startsWith("async-answer:") &&
2628
!isCompactionCommandMessage({ role: "user", ...item })
2729
? [item.messageId]
2830
: [],

0 commit comments

Comments
 (0)