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
69 changes: 38 additions & 31 deletions apps/server/src/orchestration-v2/threadHistoryPaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,39 +904,46 @@ describe("threadHistoryPaging", () => {
expect(bounded.projection.visibleTurnItems).toEqual(actionable.visibleTurnItems);
});

it("keeps agent-only turns visible when checkpoint file lists fill the byte budget", () => {
const items = Array.from({ length: 3 }, (_, turn) => {
const first = makeRow(turn * 5);
const prompt = {
...first,
item: {
...first.item,
type: "user_message" as const,
createdBy: "agent" as const,
creationSource: "provider" as const,
inputIntent: "turn_start" as const,
messageId: MessageId.make(`agent-prompt-${turn}`),
text: `Step ${turn}`,
attachments: [],
},
} as OrchestrationV2ProjectedTurnItem;
return [prompt, ...Array.from({ length: 4 }, (_, index) => makeRow(turn * 5 + index + 1))];
}).flat();
const files = Array.from(
{ length: 15_000 },
(_, index) =>
`work/ws-${index % 40}/.jj/repo/store/extra/${index.toString(16).padStart(40, "0")}`,
);
const projection = {
...makeProjection(items),
checkpoints: [{ id: "checkpoint-1", files }],
} as unknown as ReturnType<typeof makeProjection>;
it.each([false, true])(
"keeps agent-only turns visible when checkpoint file lists fill the byte budget (stored interrupt request: %s)",
(withInterruptRequest) => {
const items = Array.from({ length: 3 }, (_, turn) => {
const first = makeRow(turn * 5);
const prompt = {
...first,
item: {
...first.item,
type: "user_message" as const,
createdBy: "agent" as const,
creationSource: "provider" as const,
inputIntent: "turn_start" as const,
messageId: MessageId.make(`agent-prompt-${turn}`),
text: `Step ${turn}`,
attachments: [],
},
} as OrchestrationV2ProjectedTurnItem;
return [prompt, ...Array.from({ length: 4 }, (_, index) => makeRow(turn * 5 + index + 1))];
}).flat();
const files = Array.from(
{ length: 15_000 },
(_, index) =>
`work/ws-${index % 40}/.jj/repo/store/extra/${index.toString(16).padStart(40, "0")}`,
);
const base = makeProjection(items);
const projection = {
...base,
turnItems: withInterruptRequest
? [interruptItem("old-interrupt-req", "run_interrupt_request", 0), ...base.turnItems]
: base.turnItems,
checkpoints: [{ id: "checkpoint-1", files }],
} as unknown as ReturnType<typeof makeProjection>;

const bounded = buildBoundedThreadProjection({ projection, snapshotSequence: 1 });
const bounded = buildBoundedThreadProjection({ projection, snapshotSequence: 1 });

expect(bounded.projection.visibleTurnItems).toHaveLength(items.length);
expect(bounded.hasMoreHistory).toBe(false);
});
expect(bounded.projection.visibleTurnItems).toHaveLength(items.length);
expect(bounded.hasMoreHistory).toBe(false);
},
);

it("keeps paged historical plan detail in the turn item and only status in its artifact", () => {
const detail = "Implement the historical plan exactly.\n".repeat(1_000);
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/orchestration-v2/threadHistoryPaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,9 @@ export function buildBoundedThreadProjection(input: {
turnItems: [],
visibleTurnItems: [],
});
// Keep the control-only window minimum, but required dependency cards claim their reserve first.
// Control state cannot be paged, so the window keeps half the budget; dependency cards take their reserve from that half.
const windowBudget = Math.max(
dependencyReserve === 0 ? policy.maxEncodedBytes / 2 : 0,
Math.max(policy.maxEncodedBytes / 2 - dependencyReserve, 0),
Comment thread
shivamhwp marked this conversation as resolved.
Resolved
policy.maxEncodedBytes - dependencyReserve - controlBytes - 1_024,
);
const windowPolicy: ThreadHistoryPagePolicy = { ...policy, maxEncodedBytes: windowBudget };
Expand Down
Loading