@devries-cameron20 / t3code-1 / commits / d9eb2b61c3
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): agent-driven threads keep their recent rows when checkpoint data is large (#21187)

fixfon committed Oct 18, 2026 at 22:35 UTC d9eb2b61c3899f1ade376fd00f1ebb7fd11cf47e
2 files changed +38 -1
apps/server/src/orchestration-v2/threadHistoryPaging.test.ts
+35
@@ -718,6 +718,41 @@ describe("threadHistoryPaging", () => {
718 expect(bounded.projection.visibleTurnItems).toEqual(actionable.visibleTurnItems);
719 });
720
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 +
756 it("keeps paged historical plan detail in the turn item and only status in its artifact", () => {
757 const detail = "Implement the historical plan exactly.\n".repeat(1_000);
758 const item = {
apps/server/src/orchestration-v2/threadHistoryPaging.ts
+3 -1
@@ -485,8 +485,10 @@ export function buildBoundedThreadProjection(input: {
485 turnItems: [],
486 visibleTurnItems: [],
487 });
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.
490 const windowBudget = Math.max(
489 - 0,
491 + policy.maxEncodedBytes / 2,
492 policy.maxEncodedBytes - dependencyReserve - controlBytes - 1_024,
493 );
494 const windowPolicy: ThreadHistoryPagePolicy = {