Skip to content

Commit d9a151d

Browse files
committed
fix(server): agent-driven threads keep their recent rows when checkpoint data is large
1 parent 9c16146 commit d9a151d

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/threadHistoryPaging.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,41 @@ describe("threadHistoryPaging", () => {
689689
expect(bounded.projection.visibleTurnItems).toEqual(actionable.visibleTurnItems);
690690
});
691691

692+
it("keeps agent-only turns visible when checkpoint file lists fill the byte budget", () => {
693+
const items = Array.from({ length: 3 }, (_, turn) => {
694+
const first = makeRow(turn * 5);
695+
const prompt = {
696+
...first,
697+
item: {
698+
...first.item,
699+
type: "user_message" as const,
700+
createdBy: "agent" as const,
701+
creationSource: "provider" as const,
702+
inputIntent: "turn_start" as const,
703+
messageId: MessageId.make(`agent-prompt-${turn}`),
704+
text: `Step ${turn}`,
705+
attachments: [],
706+
},
707+
} as OrchestrationV2ProjectedTurnItem;
708+
return [prompt, ...Array.from({ length: 4 }, (_, index) => makeRow(turn * 5 + index + 1))];
709+
}).flat();
710+
const files = Array.from(
711+
{ length: 15_000 },
712+
(_, index) =>
713+
`work/ws-${index % 40}/.jj/repo/store/extra/${index.toString(16).padStart(40, "0")}`,
714+
);
715+
const projection = {
716+
...makeProjection(items),
717+
checkpoints: [{ id: "checkpoint-1", files }],
718+
} as unknown as ReturnType<typeof makeProjection>;
719+
720+
const bounded = buildBoundedThreadProjection({ projection, snapshotSequence: 1 });
721+
722+
expect(bounded.projection.visibleTurnItems).toHaveLength(items.length);
723+
expect(bounded.hasMoreHistory).toBe(false);
724+
expect(bounded.payloadBudgetExceeded).toBe(true);
725+
});
726+
692727
it("keeps paged historical plan detail in the turn item and only status in its artifact", () => {
693728
const detail = "Implement the historical plan exactly.\n".repeat(1_000);
694729
const item = {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,10 @@ export function buildBoundedThreadProjection(input: {
482482
turnItems: [],
483483
visibleTurnItems: [],
484484
});
485+
// Control state (checkpoint file lists, an active plan) cannot be paged, so it may claim at most
486+
// half the budget; past that the window would shrink to the one row every page admits.
485487
const windowBudget = Math.max(
486-
0,
488+
policy.maxEncodedBytes / 2,
487489
policy.maxEncodedBytes - dependencyReserve - controlBytes - 1_024,
488490
);
489491
const windowPolicy: ThreadHistoryPagePolicy = {

0 commit comments

Comments
 (0)