The best way to control Claude Code, Codex and more from any computer or phone
fix(server): a stopped run no longer shrinks thread history to one row (#31266)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Nov 5, 2026 at 09:52 UTC
67eebaca23f8f7bc46e8817434087fc9c5acf8e3
2 files changed
+40
-33
apps/server/src/orchestration-v2/threadHistoryPaging.test.ts
+38
-31
@@ -904,39 +904,46 @@ describe("threadHistoryPaging", () => {
904
expect(bounded.projection.visibleTurnItems).toEqual(actionable.visibleTurnItems);
905
});
906
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>;
940
935
- const bounded = buildBoundedThreadProjection({ projection, snapshotSequence: 1 });
941
+ const bounded = buildBoundedThreadProjection({ projection, snapshotSequence: 1 });
942
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
+ );
947
948
it("keeps paged historical plan detail in the turn item and only status in its artifact", () => {
949
const detail = "Implement the historical plan exactly.\n".repeat(1_000);
apps/server/src/orchestration-v2/threadHistoryPaging.ts
+2
-2
@@ -675,9 +675,9 @@ export function buildBoundedThreadProjection(input: {
675
turnItems: [],
676
visibleTurnItems: [],
677
});
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.
679
const windowBudget = Math.max(
680
- dependencyReserve === 0 ? policy.maxEncodedBytes / 2 : 0,
680
+ Math.max(policy.maxEncodedBytes / 2 - dependencyReserve, 0),
681
policy.maxEncodedBytes - dependencyReserve - controlBytes - 1_024,
682
);
683
const windowPolicy: ThreadHistoryPagePolicy = { ...policy, maxEncodedBytes: windowBudget };