Skip to content

Commit e2bea15

Browse files
committed
fix(client-runtime): gate pending handoff on any visible timeline row
1 parent 3e1a78e commit e2bea15

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

‎packages/client-runtime/src/handoff.test.ts‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,17 @@ describe("pending context handoff", () => {
9090
expect(resolvePendingHandoff(projection, { instanceId: from, model: "source" }, [])).toBeNull();
9191
expect(resolvePendingHandoff(projection, { instanceId: from, model: "other" }, [])).toBeNull();
9292
});
93-
it("stays hidden until the thread shows conversation", () => {
94-
const withoutMessages = { ...projection, visibleTurnItems: [] };
95-
expect(
96-
resolvePendingHandoff(withoutMessages, { instanceId: to, model: "first" }, []),
97-
).toBeNull();
98-
// A wake run starts with a notification instead of a user message.
99-
const wakeOnly = {
93+
it("stays hidden while the thread's timeline is empty", () => {
94+
const empty = { ...projection, visibleTurnItems: [] };
95+
expect(resolvePendingHandoff(empty, { instanceId: to, model: "first" }, [])).toBeNull();
96+
// Paging can leave a window of only tool rows after the prompt.
97+
const toolRowsOnly = {
10098
...projection,
101-
visibleTurnItems: [{ item: { type: "notification" } }],
99+
visibleTurnItems: [{ item: { type: "command_execution" } }],
102100
} as unknown as OrchestrationV2ThreadProjection;
103-
expect(resolvePendingHandoff(wakeOnly, { instanceId: to, model: "first" }, [])?.to.model).toBe(
104-
"first",
105-
);
101+
expect(
102+
resolvePendingHandoff(toolRowsOnly, { instanceId: to, model: "first" }, [])?.to.model,
103+
).toBe("first");
106104
});
107105
it("only previews a same-provider model change when it needs a fresh native thread", () => {
108106
const providers = [

‎packages/client-runtime/src/handoff.ts‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,10 @@ export function resolvePendingHandoff(
2525
selection: ModelSelection | null | undefined,
2626
providers: ReadonlyArray<ServerProvider>,
2727
): HandoffEndpoints | null {
28-
// Nothing to hand off until the thread shows conversation. Wake runs start
29-
// with a notification, and paging can drop older user messages from view.
30-
const hasConversation = projection?.visibleTurnItems.some(
31-
({ item }) =>
32-
item.type === "user_message" ||
33-
item.type === "assistant_message" ||
34-
item.type === "notification",
35-
);
36-
if (!hasConversation) return null;
37-
const from = projection?.runs.findLast(
28+
// A thread with an empty timeline has nothing to hand off. Any loaded row
29+
// counts: paging can leave a window of only tool rows.
30+
if (!projection?.visibleTurnItems.length) return null;
31+
const from = projection.runs.findLast(
3832
(run) => run.startedAt !== null && run.status !== "rolled_back",
3933
)?.modelSelection;
4034
if (from === undefined || selection == null) return null;

0 commit comments

Comments
 (0)