Skip to content

Commit ad33a13

Browse files
fix(summaries): keep the newest messages ahead of tool results in a summary trial
A summary trial now selects the pinned messages first. On a tool-heavy 638-item thread this raises the dropped history that arrives as a summary from 50% to 99%, because the second roll-up is no longer refused. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 72f1c28 commit ad33a13

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ export const deliverContextHandoffs = Effect.fn("orchestrationV2.deliverContextH
161161
omittedItems:
162162
priorOmittedCount - [...proposed].filter((id) => priorOmitted.has(id)).length,
163163
budget,
164+
// Otherwise a newer tool result takes the room an older pinned message needs, and
165+
// the summary is refused for a loss it did not have to cause.
166+
first: pinned,
164167
});
165168
// A summary earns its space only when more history arrives with it than without it.
166169
const kept = new Set<string>(reduced.messages.map((message) => message.itemId));

‎packages/provider-core/src/server/handoffBudget.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ export function selectHistory(input: {
339339
readonly coverage: string;
340340
readonly omittedItems?: number;
341341
readonly budget: number;
342+
/** Items to keep ahead of the usual order, newest first, while they fit. */
343+
readonly first?: ReadonlySet<string>;
342344
}) {
343345
const messages = input.messages;
344346
const selected = new Set<number>();
@@ -362,6 +364,9 @@ export function selectHistory(input: {
362364
selected.add(index);
363365
remaining -= cost;
364366
};
367+
if (input.first !== undefined)
368+
for (let index = messages.length - 1; index >= 0; index--)
369+
if (input.first.has(messages[index]!.itemId)) tryAdd(index);
365370
tryAdd(messages.findLastIndex((message) => message.role === "user"));
366371
tryAdd(messages.findLastIndex((message) => message.role === "assistant"));
367372
tryAdd(messages.findIndex((message) => message.role === "user"));

0 commit comments

Comments
 (0)