Skip to content

Commit 5f69cac

Browse files
fix(web): turn diffs cut off at the size limit say changes are incomplete (pingdotgg#36079)
1 parent 6790f85 commit 5f69cac

4 files changed

Lines changed: 54 additions & 7 deletions

File tree

‎apps/server/src/checkpointing/CheckpointDiffQuery.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CHECKPOINT_DIFF_TRUNCATED_MARKER,
23
OrchestrationGetTurnDiffResult,
34
type OrchestrationGetFullThreadDiffInput,
45
type OrchestrationGetFullThreadDiffResult,
@@ -28,7 +29,6 @@ import { isGitImport, parseTurnDiffFilesFromNumstat, type TurnDiffFileSummary }
2829

2930
// Windows limits a command line to 32,767 characters. Leave room for the rest of git's arguments.
3031
const MAX_PATHSPEC_CHARS = 24_000;
31-
const DIFF_TRUNCATED_MARKER = "\n\n[truncated]";
3232

3333
function batchFilePaths(files: ReadonlyArray<TurnDiffFileSummary>) {
3434
const batches: string[][] = [];
@@ -243,10 +243,11 @@ export const make = Effect.gen(function* () {
243243
new TextDecoder().decode(
244244
Buffer.from(diff).subarray(
245245
0,
246-
CHECKPOINT_DIFF_MAX_OUTPUT_BYTES - Buffer.byteLength(DIFF_TRUNCATED_MARKER),
246+
CHECKPOINT_DIFF_MAX_OUTPUT_BYTES -
247+
Buffer.byteLength(CHECKPOINT_DIFF_TRUNCATED_MARKER),
247248
),
248249
{ stream: true },
249-
) + DIFF_TRUNCATED_MARKER;
250+
) + CHECKPOINT_DIFF_TRUNCATED_MARKER;
250251
break;
251252
}
252253
remainingBytes -= patchBytes;

‎apps/web/src/components/DiffPanel.browser.test.tsx‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
DEFAULT_CLIENT_SETTINGS,
55
EnvironmentId,
66
ProjectId,
7+
RunId,
78
ThreadId,
89
type ClientSettings,
910
type ReviewBranchCommitsResult,
@@ -35,6 +36,8 @@ const state = vi.hoisted(() => ({
3536
localRefs: null as unknown as ResultAtom<VcsListRefsResult>,
3637
remoteRefs: null as unknown as ResultAtom<VcsListRefsResult>,
3738
commits: null as unknown as ResultAtom<ReviewBranchCommitsResult>,
39+
checkpoints: [] as unknown[],
40+
checkpointDiff: null as { diff: string } | null,
3841
}));
3942

4043
vi.mock("~/state/server", () => ({
@@ -59,7 +62,7 @@ vi.mock("~/state/vcs", () => ({
5962
vi.mock("~/state/entities", () => ({
6063
useQuietThreadShell: () => state.thread,
6164
useProject: () => ({ workspaceRoot: "/project", repositoryIdentity: null }),
62-
useThreadCheckpointSummaries: () => [],
65+
useThreadCheckpointSummaries: () => state.checkpoints,
6366
useQuietThreadVisibleTurnItems: () => [],
6467
}));
6568
vi.mock("~/state/filesystem", () => ({
@@ -77,7 +80,7 @@ vi.mock("~/hooks/useTheme", () => ({
7780
subscribeRenderedAppearance: () => () => {},
7881
}));
7982
vi.mock("~/state/queries", () => ({
80-
useCheckpointDiff: () => ({ data: null, error: null, isPending: false }),
83+
useCheckpointDiff: () => ({ data: state.checkpointDiff, error: null, isPending: false }),
8184
useTurnItemDetail: () => ({ data: null, error: null, isPending: false }),
8285
useDebouncedValue: <A,>(value: A) => value,
8386
}));
@@ -126,6 +129,8 @@ function setup(failedBaseRef: string | null) {
126129
};
127130
reset();
128131
state.diffFilesCollapsed = false;
132+
state.checkpoints = [];
133+
state.checkpointDiff = null;
129134
const patch = Atom.make<AsyncResult.AsyncResult<ReviewDiffPreviewSource, Error>>(
130135
AsyncResult.initial(),
131136
);
@@ -267,3 +272,33 @@ it.each([false, true])(
267272
await expect.element(toggle).toHaveAttribute("aria-expanded", "false");
268273
},
269274
);
275+
276+
it("says a turn diff cut off at the server's size limit is incomplete", async () => {
277+
using context = setup("origin/orphan");
278+
state.checkpoints = [
279+
{
280+
runId: "run",
281+
checkpointTurnCount: 1,
282+
checkpointRef: "ref",
283+
status: "ready",
284+
files: [],
285+
assistantMessageId: null,
286+
completedAt: "2026-01-01T00:00:00Z",
287+
},
288+
];
289+
state.checkpointDiff = {
290+
diff: "diff --git a/first.txt b/first.txt\n--- a/first.txt\n+++ b/first.txt\n@@ -0,0 +1 @@\n+visible\n\n[truncated]",
291+
};
292+
useDiffPanelStore.getState().selectTurn(context.threadRef, RunId.make("run"));
293+
await using screen = await render(
294+
<RegistryContext.Provider value={context.registry}>
295+
<div style={{ height: 600, display: "flex", flexDirection: "column" }}>
296+
<DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
297+
</div>
298+
</RegistryContext.Provider>,
299+
);
300+
await expect.element(screen.getByText("first.txt", { exact: true }).first()).toBeVisible();
301+
await expect
302+
.element(screen.getByText("This preview exceeds the size limit. Changes shown are incomplete."))
303+
.toBeVisible();
304+
});

‎apps/web/src/components/DiffPanel.tsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import {
66
squashAtomCommandFailure,
77
} from "@t3tools/client-runtime/state/runtime";
88
import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors";
9-
import type { ReviewBranchCommitsResult, ScopedThreadRef, RunId } from "@t3tools/contracts";
9+
import {
10+
CHECKPOINT_DIFF_TRUNCATED_MARKER,
11+
type ReviewBranchCommitsResult,
12+
type ScopedThreadRef,
13+
type RunId,
14+
} from "@t3tools/contracts";
1015
import {
1116
ArrowRightIcon,
1217
CheckIcon,
@@ -483,7 +488,10 @@ export default function DiffPanel({
483488
: gitDiff;
484489
const isSelectedPatchTruncated =
485490
toolCallPreview?.truncated === true ||
486-
(isGitSelection && selectedGitSource?.truncated === true);
491+
(isGitSelection && selectedGitSource?.truncated === true) ||
492+
(!toolCallSelection &&
493+
selectedTurn !== undefined &&
494+
selectedPatch?.endsWith(CHECKPOINT_DIFF_TRUNCATED_MARKER) === true);
487495
const selectedPatchQuery = toolCallSelection
488496
? toolCallDetail
489497
: selectedTurn

‎packages/contracts/src/checkpointDiff.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import * as Struct from "effect/Struct";
44

55
import { NonNegativeInt, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
66

7+
/** Ends a checkpoint diff the server cut off at its output size limit. */
8+
export const CHECKPOINT_DIFF_TRUNCATED_MARKER = "\n\n[truncated]";
9+
710
export const TurnCountRange = Schema.Struct({
811
fromTurnCount: NonNegativeInt,
912
toTurnCount: NonNegativeInt,

0 commit comments

Comments
 (0)