TypeScript
fix(server): a stopped run no longer shrinks thread history to one row (#31266)
shivam67eebaca23f8
diff --git a/apps/server/src/orchestration-v2/threadHistoryPaging.test.ts b/apps/server/src/orchestration-v2/threadHistoryPaging.test.tsindex eba4ceec7f6..111cf054135 100644--- a/apps/server/src/orchestration-v2/threadHistoryPaging.test.ts+++ b/apps/server/src/orchestration-v2/threadHistoryPaging.test.ts@@ -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);diff --git a/apps/server/src/orchestration-v2/threadHistoryPaging.ts b/apps/server/src/orchestration-v2/threadHistoryPaging.tsindex abfaf0ade69..8bc794ce36c 100644--- a/apps/server/src/orchestration-v2/threadHistoryPaging.ts+++ b/apps/server/src/orchestration-v2/threadHistoryPaging.ts@@ -675,9 +675,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),policy.maxEncodedBytes - dependencyReserve - controlBytes - 1_024,);const windowPolicy: ThreadHistoryPagePolicy = { ...policy, maxEncodedBytes: windowBudget };