Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Scope checkpoint diff cache keys to avoid collisions

Julius Marminge6aea858ed85f
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index a8efd1e7f..f01f226cc 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -529,6 +529,7 @@ export default function ChatView() {
threadRuntimeId: activeThreadRuntimeId,
fromTurnCount: target.fromTurnCount,
toTurnCount: target.toTurnCount,
+ cacheScope: `turn:${target.turnId}`,
}),
),
});
diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsx
index 638c5dc70..c6ad5eabc 100644
--- a/apps/web/src/components/DiffPanel.tsx
+++ b/apps/web/src/components/DiffPanel.tsx
@@ -138,12 +138,19 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
const activeCheckpointRange = selectedTurn
? selectedCheckpointRange
: conversationCheckpointRange;
+ const conversationCacheScope = useMemo(() => {
+ if (selectedTurn || turnDiffSummaries.length === 0) {
+ return null;
+ }
+ return `conversation:${turnDiffSummaries.map((summary) => summary.turnId).join(",")}`;
+ }, [selectedTurn, turnDiffSummaries]);
const activeCheckpointDiffQuery = useQuery(
checkpointDiffQueryOptions(api, {
sessionId: activeSessionId,
threadRuntimeId: activeThreadRuntimeId,
fromTurnCount: activeCheckpointRange?.fromTurnCount ?? null,
toTurnCount: activeCheckpointRange?.toTurnCount ?? null,
+ cacheScope: selectedTurn ? `turn:${selectedTurn.turnId}` : conversationCacheScope,
}),
);
const selectedTurnCheckpointDiff = selectedTurn
@@ -184,6 +191,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
threadRuntimeId: activeThreadRuntimeId,
fromTurnCount: Math.max(0, checkpointTurnCount - 1),
toTurnCount: checkpointTurnCount,
+ cacheScope: `turn:${summary.turnId}`,
}),
)?.diff;
if (checkpointPatch) {
diff --git a/apps/web/src/lib/providerReactQuery.test.ts b/apps/web/src/lib/providerReactQuery.test.ts
new file mode 100644
index 000000000..45d822aae
--- /dev/null
+++ b/apps/web/src/lib/providerReactQuery.test.ts
@@ -0,0 +1,53 @@
+import type { NativeApi } from "@t3tools/contracts";
+import { describe, expect, it, vi } from "vitest";
+import { checkpointDiffQueryOptions, providerQueryKeys } from "./providerReactQuery";
+
+describe("providerQueryKeys.checkpointDiff", () => {
+ it("includes cacheScope so reused turn counts do not collide", () => {
+ const baseInput = {
+ sessionId: "session-id",
+ threadRuntimeId: "thread-id",
+ fromTurnCount: 1,
+ toTurnCount: 2,
+ } as const;
+
+ expect(
+ providerQueryKeys.checkpointDiff({
+ ...baseInput,
+ cacheScope: "turn:old-turn",
+ }),
+ ).not.toEqual(
+ providerQueryKeys.checkpointDiff({
+ ...baseInput,
+ cacheScope: "turn:new-turn",
+ }),
+ );
+ });
+});
+
+describe("checkpointDiffQueryOptions", () => {
+ it("forwards checkpoint range to the provider API", async () => {
+ const getCheckpointDiff = vi.fn().mockResolvedValue({ diff: "patch" });
+ const api = {
+ providers: {
+ getCheckpointDiff,
+ },
+ } as unknown as NativeApi;
+
+ const options = checkpointDiffQueryOptions(api, {
+ sessionId: "session-id",
+ threadRuntimeId: "thread-id",
+ fromTurnCount: 3,
+ toTurnCount: 4,
+ cacheScope: "turn:abc",
+ });
+
+ await options.queryFn();
+
+ expect(getCheckpointDiff).toHaveBeenCalledWith({
+ sessionId: "session-id",
+ fromTurnCount: 3,
+ toTurnCount: 4,
+ });
+ });
+});
diff --git a/apps/web/src/lib/providerReactQuery.ts b/apps/web/src/lib/providerReactQuery.ts
index 31f6bdf1e..1dc837b7b 100644
--- a/apps/web/src/lib/providerReactQuery.ts
+++ b/apps/web/src/lib/providerReactQuery.ts
@@ -6,6 +6,7 @@ export interface CheckpointDiffQueryInput {
threadRuntimeId: string | null;
fromTurnCount: number | null;
toTurnCount: number | null;
+ cacheScope?: string | null;
}
export const providerQueryKeys = {
@@ -18,6 +19,7 @@ export const providerQueryKeys = {
input.threadRuntimeId,
input.fromTurnCount,
input.toTurnCount,
+ input.cacheScope ?? null,
] as const,
};