Limit tool call coalescing to prepend boundary

This commit is contained in:
Mohamed Boudra
2026-05-17 22:24:59 +07:00
parent 338a41991d
commit 1f7fc232b3
3 changed files with 100 additions and 28 deletions
@@ -601,6 +601,84 @@ describe("processTimelineResponse", () => {
]);
});
it("does not coalesce tool call lifecycle rows away from the prepend boundary", () => {
const callId = "toolu_not_boundary";
const currentTail = hydrateStreamState(
[
{
event: makeTimelineEvent("current chunk"),
timestamp: new Date(3000),
},
{
event: {
type: "timeline",
provider: "claude",
item: makeToolCallTimelineEntry(4, callId, "completed", {
type: "read",
filePath: "/tmp/example.ts",
}).item,
} as AgentStreamEventPayload,
timestamp: new Date(4000),
},
],
{ source: "canonical" },
);
const existingCursor: TimelineCursor = {
epoch: "epoch-1",
startSeq: 3,
endSeq: 5,
};
const result = processTimelineResponse({
...baseTimelineInput,
currentTail,
currentCursor: existingCursor,
payload: {
...baseTimelineInput.payload,
direction: "before",
epoch: "epoch-1",
startCursor: { seq: 1 },
endCursor: { seq: 2 },
entries: [
makeToolCallTimelineEntry(1, callId, "running", {
type: "unknown",
input: { file_path: "/tmp/example.ts" },
output: null,
}),
makeTimelineEntry(2, "older chunk "),
],
},
});
expect(
result.tail.map((item) => ({
kind: item.kind,
id: item.id,
status: item.kind === "tool_call" ? item.payload.data.status : null,
text: item.kind === "assistant_message" ? item.text : null,
})),
).toEqual([
{
kind: "tool_call",
id: `agent_tool_${callId}`,
status: "running",
text: null,
},
{
kind: "assistant_message",
id: expect.any(String),
status: null,
text: "older chunk current chunk",
},
{
kind: "tool_call",
id: `agent_tool_${callId}`,
status: "completed",
text: null,
},
]);
});
it("requests canonical catch-up when a projected entry overlaps unseen seqs", () => {
const existingCursor: TimelineCursor = {
epoch: "epoch-1",