Skip to content

Commit d9eb2b6

Browse files
authored
fix(server): agent-driven threads keep their recent rows when checkpoint data is large (pingdotgg#21187)
1 parent def17b2 commit d9eb2b6

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
@@ -718,6 +718,41 @@ describe("threadHistoryPaging", () => {
718718
expect(bounded.projection.visibleTurnItems).toEqual(actionable.visibleTurnItems);
719719
});
720720

721+
it("keeps agent-only turns visible when checkpoint file lists fill the byte budget", () => {
722+
const items = Array.from({ length: 3 }, (_, turn) => {
723+
const first = makeRow(turn * 5);
724+
const prompt = {
725+
...first,
726+
item: {
727+
...first.item,
728+
type: "user_message" as const,
729+
createdBy: "agent" as const,
730+
creationSource: "provider" as const,
731+
inputIntent: "turn_start" as const,
732+
messageId: MessageId.make(`agent-prompt-${turn}`),
733+
text: `Step ${turn}`,
734+
attachments: [],
735+
},
736+
} as OrchestrationV2ProjectedTurnItem;
737+
return [prompt, ...Array.from({ length: 4 }, (_, index) => makeRow(turn * 5 + index + 1))];
738+
}).flat();
739+
const files = Array.from(
740+
{ length: 15_000 },
741+
(_, index) =>
742+
`work/ws-${index % 40}/.jj/repo/store/extra/${index.toString(16).padStart(40, "0")}`,
743+
);
744+
const projection = {
745+
...makeProjection(items),
746+
checkpoints: [{ id: "checkpoint-1", files }],
747+
} as unknown as ReturnType<typeof makeProjection>;
748+
749+
const bounded = buildBoundedThreadProjection({ projection, snapshotSequence: 1 });
750+
751+
expect(bounded.projection.visibleTurnItems).toHaveLength(items.length);
752+
expect(bounded.hasMoreHistory).toBe(false);
753+
expect(bounded.payloadBudgetExceeded).toBe(true);
754+
});
755+
721756
it("keeps paged historical plan detail in the turn item and only status in its artifact", () => {
722757
const detail = "Implement the historical plan exactly.\n".repeat(1_000);
723758
const item = {

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

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

0 commit comments

Comments
 (0)