Skip to content

Commit 67eebac

Browse files
shivamhwpclaude
andauthored
fix(server): a stopped run no longer shrinks thread history to one row (#31266)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 298cb24 commit 67eebac

2 files changed

Lines changed: 40 additions & 33 deletions

File tree

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

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -904,39 +904,46 @@ describe("threadHistoryPaging", () => {
904904
expect(bounded.projection.visibleTurnItems).toEqual(actionable.visibleTurnItems);
905905
});
906906

907-
it("keeps agent-only turns visible when checkpoint file lists fill the byte budget", () => {
908-
const items = Array.from({ length: 3 }, (_, turn) => {
909-
const first = makeRow(turn * 5);
910-
const prompt = {
911-
...first,
912-
item: {
913-
...first.item,
914-
type: "user_message" as const,
915-
createdBy: "agent" as const,
916-
creationSource: "provider" as const,
917-
inputIntent: "turn_start" as const,
918-
messageId: MessageId.make(`agent-prompt-${turn}`),
919-
text: `Step ${turn}`,
920-
attachments: [],
921-
},
922-
} as OrchestrationV2ProjectedTurnItem;
923-
return [prompt, ...Array.from({ length: 4 }, (_, index) => makeRow(turn * 5 + index + 1))];
924-
}).flat();
925-
const files = Array.from(
926-
{ length: 15_000 },
927-
(_, index) =>
928-
`work/ws-${index % 40}/.jj/repo/store/extra/${index.toString(16).padStart(40, "0")}`,
929-
);
930-
const projection = {
931-
...makeProjection(items),
932-
checkpoints: [{ id: "checkpoint-1", files }],
933-
} as unknown as ReturnType<typeof makeProjection>;
907+
it.each([false, true])(
908+
"keeps agent-only turns visible when checkpoint file lists fill the byte budget (stored interrupt request: %s)",
909+
(withInterruptRequest) => {
910+
const items = Array.from({ length: 3 }, (_, turn) => {
911+
const first = makeRow(turn * 5);
912+
const prompt = {
913+
...first,
914+
item: {
915+
...first.item,
916+
type: "user_message" as const,
917+
createdBy: "agent" as const,
918+
creationSource: "provider" as const,
919+
inputIntent: "turn_start" as const,
920+
messageId: MessageId.make(`agent-prompt-${turn}`),
921+
text: `Step ${turn}`,
922+
attachments: [],
923+
},
924+
} as OrchestrationV2ProjectedTurnItem;
925+
return [prompt, ...Array.from({ length: 4 }, (_, index) => makeRow(turn * 5 + index + 1))];
926+
}).flat();
927+
const files = Array.from(
928+
{ length: 15_000 },
929+
(_, index) =>
930+
`work/ws-${index % 40}/.jj/repo/store/extra/${index.toString(16).padStart(40, "0")}`,
931+
);
932+
const base = makeProjection(items);
933+
const projection = {
934+
...base,
935+
turnItems: withInterruptRequest
936+
? [interruptItem("old-interrupt-req", "run_interrupt_request", 0), ...base.turnItems]
937+
: base.turnItems,
938+
checkpoints: [{ id: "checkpoint-1", files }],
939+
} as unknown as ReturnType<typeof makeProjection>;
934940

935-
const bounded = buildBoundedThreadProjection({ projection, snapshotSequence: 1 });
941+
const bounded = buildBoundedThreadProjection({ projection, snapshotSequence: 1 });
936942

937-
expect(bounded.projection.visibleTurnItems).toHaveLength(items.length);
938-
expect(bounded.hasMoreHistory).toBe(false);
939-
});
943+
expect(bounded.projection.visibleTurnItems).toHaveLength(items.length);
944+
expect(bounded.hasMoreHistory).toBe(false);
945+
},
946+
);
940947

941948
it("keeps paged historical plan detail in the turn item and only status in its artifact", () => {
942949
const detail = "Implement the historical plan exactly.\n".repeat(1_000);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,9 @@ export function buildBoundedThreadProjection(input: {
675675
turnItems: [],
676676
visibleTurnItems: [],
677677
});
678-
// Keep the control-only window minimum, but required dependency cards claim their reserve first.
678+
// Control state cannot be paged, so the window keeps half the budget; dependency cards take their reserve from that half.
679679
const windowBudget = Math.max(
680-
dependencyReserve === 0 ? policy.maxEncodedBytes / 2 : 0,
680+
Math.max(policy.maxEncodedBytes / 2 - dependencyReserve, 0),
681681
policy.maxEncodedBytes - dependencyReserve - controlBytes - 1_024,
682682
);
683683
const windowPolicy: ThreadHistoryPagePolicy = { ...policy, maxEncodedBytes: windowBudget };

0 commit comments

Comments
 (0)