Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix(native): say what Recheck and Continue will do on a snapshot

justrachf51ed78ad066
diff --git a/apps/native/components/site/SavedCacheCheck.tsx b/apps/native/components/site/SavedCacheCheck.tsx
index 69cd13fe..e8002755 100644
--- a/apps/native/components/site/SavedCacheCheck.tsx
+++ b/apps/native/components/site/SavedCacheCheck.tsx
@@ -1,23 +1,26 @@
"use client";
import { useCallback, useEffect, useRef, useState } from "react";
-import { checkSavedCache, type CacheCheck } from "@/lib/saved-cache-check";
+import { checkSavedCache, formatSaveSize, type CacheCheck } from "@/lib/saved-cache-check";
export default function SavedCacheCheck({ name, cwd, model, disabled, onContinue }: {
name: string; cwd?: string; model?: string; disabled: boolean; onContinue: () => void;
}) {
const key = JSON.stringify([name, cwd, model]);
const pending = useRef<AbortController | null>(null);
- const [state, setState] = useState<{ key: string; result?: CacheCheck; error?: boolean; busy: boolean }>({ key, busy: true });
+ const [state, setState] = useState<{ key: string; result?: CacheCheck; error?: boolean; busy: boolean; note?: string }>({ key, busy: true });
const run = useCallback(async (continueAfter: boolean, previous?: CacheCheck) => {
pending.current?.abort();
const controller = new AbortController(); pending.current = controller;
- setState({ key, result: previous, busy: true });
+ setState({ key, result: previous, busy: true, note: previous ? "Rechecking…" : undefined });
try {
const result = await checkSavedCache(name, { cwd, model }, controller.signal);
if (controller.signal.aborted) return;
- setState({ key, result, busy: false });
- // If the freshly read save changes the assessment, show it before proceeding.
- if (continueAfter && JSON.stringify(result) === JSON.stringify(previous)) onContinue();
+ const same = JSON.stringify(result) === JSON.stringify(previous);
+ setState({
+ key, result, busy: false,
+ note: previous ? (same ? "Rechecked — same as before." : "Rechecked — this changed.") : undefined,
+ });
+ if (continueAfter && same) onContinue();
} catch {
if (!controller.signal.aborted) setState({ key, busy: false, error: true });
}
@@ -28,17 +31,21 @@ export default function SavedCacheCheck({ name, cwd, model, disabled, onContinue
return () => pending.current?.abort();
}, [key]);
const current = state.key === key ? state : { key, busy: true };
+ const size = formatSaveSize(current.result?.bytes);
return <div data-saved-cache-check className="mt-1">
- <p role="status" className="font-medium text-ink">{current.busy ? "Checking saved cache compatibility…" : current.error ? "Prompt cache check unavailable" : current.result?.summary}</p>
+ <p role="status" className="font-medium text-ink">{current.busy ? (current.note ?? "Checking saved cache compatibility…") : current.error ? "Prompt cache check unavailable" : current.result?.summary}</p>
+ {current.note && !current.busy && <p className="mt-1">{current.note}</p>}
+ {current.result && !current.busy && <p className="mt-1">{current.result.next}</p>}
{current.result && <details className="mt-1">
<summary className="cursor-pointer">Check details</summary>
<ul className="mt-1 list-disc pl-4">{current.result.reasons.map(reason => <li key={reason}>{reason}</li>)}</ul>
- <p className="mt-1">This checks saved settings only. Changes to instructions, tools, provider routing, or cache expiry cannot be verified here. Confirm reuse from provider-reported cache usage after a request.</p>
</details>}
{current.error && <p role="alert" className="mt-1 text-red">Could not read the save. Retry before continuing.</p>}
<div className="mt-2 flex gap-2">
- <button type="button" disabled={disabled || current.busy} onClick={() => void run(false)} className="rounded-control px-3 py-1.5 hover:bg-hover disabled:opacity-50">Recheck cache</button>
- <button type="button" data-continue-snapshot disabled={disabled || current.busy || !current.result} onClick={() => void run(true, current.result)} className="rounded-control bg-hover-2 px-3 py-1.5 text-ink disabled:opacity-50">Continue here</button>
+ <button type="button" disabled={disabled || current.busy} onClick={() => void run(false, current.result)} className="rounded-control px-3 py-1.5 hover:bg-hover disabled:opacity-50">Recheck cache</button>
+ <button type="button" data-continue-snapshot disabled={disabled || current.busy || !current.result} onClick={() => void run(true, current.result)} className="rounded-control bg-hover-2 px-3 py-1.5 text-ink disabled:opacity-50">
+ {size ? `Continue here · ${size}` : "Continue here"}
+ </button>
</div>
</div>;
}
diff --git a/apps/native/lib/saved-cache-check.test.ts b/apps/native/lib/saved-cache-check.test.ts
index e2b15e93..a9f86627 100644
--- a/apps/native/lib/saved-cache-check.test.ts
+++ b/apps/native/lib/saved-cache-check.test.ts
@@ -6,6 +6,7 @@ test("matching saved settings never promise a cache hit", () => {
expect(result.status).toBe("unknown");
expect(result.summary).toContain("unverified");
expect(result.reasons).toEqual(["The selected model matches the save.", "The workspace matches the save."]);
+ expect(result.next).toContain("Continue will send");
});
test("model and workspace changes flag risk; absent legacy metadata stays unknown", () => {
diff --git a/apps/native/lib/saved-cache-check.ts b/apps/native/lib/saved-cache-check.ts
index ec937cb4..9326aaaf 100644
--- a/apps/native/lib/saved-cache-check.ts
+++ b/apps/native/lib/saved-cache-check.ts
@@ -1,11 +1,17 @@
import type { StoredSession } from "./sessions";
-export type CacheCheck = { status: "changed" | "unknown"; summary: string; reasons: string[] };
+export type CacheCheck = { status: "changed" | "unknown"; summary: string; reasons: string[]; next: string; bytes?: number };
const normalized = (path: string) => path.replace(/\/+$/, "") || "/";
+export function formatSaveSize(bytes?: number): string | undefined {
+ if (!bytes || bytes <= 0 || !Number.isFinite(bytes)) return undefined;
+ if (bytes < 1024) return `${bytes} B`;
+ if (bytes < 1024 * 1024) return `${Math.max(1, Math.round(bytes / 1024))} KB`;
+ return `${(bytes / (1024 * 1024)).toFixed(bytes >= 10 * 1024 * 1024 ? 0 : 1)} MB`;
+}
/** Local compatibility only. Matching metadata cannot prove provider cache retention
* or equality of the actual system prompt, tool schemas, or request prefix. */
-export function assessSavedCache(saved: Pick<StoredSession, "model" | "workspace"> & { cacheWorkspaceMatches?: boolean | null }, target: { model?: string; cwd?: string }): CacheCheck {
+export function assessSavedCache(saved: Pick<StoredSession, "model" | "workspace" | "size"> & { cacheWorkspaceMatches?: boolean | null }, target: { model?: string; cwd?: string }): CacheCheck {
const reasons: string[] = [];
let changed = false;
if (!saved.model || !target.model) reasons.push("Model comparison unavailable.");
@@ -19,7 +25,17 @@ export function assessSavedCache(saved: Pick<StoredSession, "model" | "workspace
else if (!workspaceMatches) {
changed = true; reasons.push("The workspace differs; prompt context and cache routing may change.");
} else reasons.push("The workspace matches the save.");
- return { status: changed ? "changed" : "unknown", summary: changed ? "Prompt cache: reuse at risk" : "Prompt cache: reuse unverified", reasons };
+ const bytes = typeof saved.size === "number" ? saved.size : undefined;
+ const payload = formatSaveSize(bytes) ? `this save (${formatSaveSize(bytes)})` : "the full saved context";
+ return {
+ status: changed ? "changed" : "unknown",
+ summary: changed ? "Prompt cache: reuse at risk" : "Prompt cache: reuse unverified",
+ reasons,
+ next: changed
+ ? `Continue will send ${payload}. Cache reuse is at risk; /compact after that can break it further.`
+ : `Continue will send ${payload}. Cache reuse is unverified until a real request.`,
+ ...(bytes ? { bytes } : {}),
+ };
}
/** Read a fresh save without bootstrapping an agent or sending a model prompt. */