Skip to content

Commit 6c84239

Browse files
maria-rcksclaude
andauthored
fix(client-runtime): hide pending context handoff on threads with no sent message (#20033)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 4d01315 commit 6c84239

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe("handoff endpoints shared by web and mobile", () => {
7575

7676
const projection = {
7777
runs: [{ ...run("source", 1, from, "source"), startedAt: "2026-10-11T00:00:00Z" }],
78+
visibleTurnItems: [{ item: { type: "user_message" } }],
7879
} as unknown as OrchestrationV2ThreadProjection;
7980

8081
describe("pending context handoff", () => {
@@ -89,6 +90,18 @@ describe("pending context handoff", () => {
8990
expect(resolvePendingHandoff(projection, { instanceId: from, model: "source" }, [])).toBeNull();
9091
expect(resolvePendingHandoff(projection, { instanceId: from, model: "other" }, [])).toBeNull();
9192
});
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 = {
98+
...projection,
99+
visibleTurnItems: [{ item: { type: "command_execution" } }],
100+
} as unknown as OrchestrationV2ThreadProjection;
101+
expect(
102+
resolvePendingHandoff(toolRowsOnly, { instanceId: to, model: "first" }, [])?.to.model,
103+
).toBe("first");
104+
});
92105
it("only previews a same-provider model change when it needs a fresh native thread", () => {
93106
const providers = [
94107
{ instanceId: from, requiresNewThreadForModelChange: true },

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export function resolvePendingHandoff(
2525
selection: ModelSelection | null | undefined,
2626
providers: ReadonlyArray<ServerProvider>,
2727
): HandoffEndpoints | null {
28-
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(
2932
(run) => run.startedAt !== null && run.status !== "rolled_back",
3033
)?.modelSelection;
3134
if (from === undefined || selection == null) return null;

0 commit comments

Comments
 (0)