Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,9 @@ function buildAutoHandoff(entries: readonly EntryLike[], projected: readonly Pro
for (const entry of current) {
if (entry.type === "context_edit" && entry.targetId) edits.set(entry.targetId, entry);
}
const omittedProjectedIds = new Set(projected.filter(({ messages }) => !messages.length).map(({ sourceEntry }) => sourceEntry.id));
const edited = current.flatMap((entry) => {
if (entry.id && omittedProjectedIds.has(entry.id)) return [];
const edit = entry.id ? edits.get(entry.id) : undefined;
if (edit?.replacement === null) return [];
if (!edit?.replacement) return [entry];
Expand Down
6 changes: 3 additions & 3 deletions test/native.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ test("interleaved async receipts retain projected provenance across complete res
assert.ok(handoff.indexOf("EDITED_FIRST_RECEIPT") < handoff.indexOf("SECOND_ASYNC_RECEIPT"));
});

test("recovery excludes results dependent on an omitted async call", async (t) => {
for (const toolName of ["work", "ask_question"]) test(`recovery excludes ${toolName} results dependent on an omitted async call`, async (t) => {
const h = await fixture(t, { seed(manager) {
const call = { ...fauxToolCall("work", {}), async: true, executionStarted: true };
const call = { ...fauxToolCall(toolName, {}), async: true, executionStarted: true };
const callId = manager.appendMessage(fauxAssistantMessage(call, { stopReason: "toolUse" }));
const laterId = manager.appendMessage(fauxAssistantMessage("Unrelated complete response"));
manager.appendMessage({
role: "toolResult", toolName: "work", toolCallId: call.id,
role: "toolResult", toolName, toolCallId: call.id,
content: [{ type: "text", text: "PRIVATE_ASYNC_RESULT" }], isError: false, timestamp: Date.now(),
});
manager.appendCompaction("Previous context", laterId, 100);
Expand Down