Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

fix(studio): show compaction notices for tool-loop checkpoints (#11702)

Lee Jackson44ac9b548201
diff --git a/studio/frontend/src/components/assistant-ui/compaction-notice.tsx b/studio/frontend/src/components/assistant-ui/compaction-notice.tsx
index 7c2701c6f07..18125003041 100644
--- a/studio/frontend/src/components/assistant-ui/compaction-notice.tsx
+++ b/studio/frontend/src/components/assistant-ui/compaction-notice.tsx
@@ -19,7 +19,7 @@ import {
*
* Rendered once per COMPACTION, gated by the caller, not once per compacted turn: a
* thread past its window refits on every request, so per-turn would mean a notice on
- * every reply forever. The caller shows this only when the eviction boundary moved.
+ * every reply forever. The caller shows this when the boundary moved or a checkpoint started.
*/
export const CompactionNotice: FC<{ truncation: ContextTruncation }> = ({
truncation,
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index fc1c8f5dc40..0bd339e168b 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -12,6 +12,7 @@ import {
import { CompactionNotice } from "@/components/assistant-ui/compaction-notice";
import {
compactionBoundary,
+ shouldShowCompactionNotice,
type ContextTruncation,
} from "@/features/chat/utils/context-truncation";
import { downloadImagePart } from "@/components/assistant-ui/image";
@@ -7841,8 +7842,8 @@ const AssistantMessage: FC = () => {
// Once a thread outgrows the window every request runs the fit, so "this turn
// compacted" is true of every later reply and would put a notice on all of them. What
// matters is when MORE of the conversation fell out of view: the eviction boundary
- // rising above the last turn that reported one. Between moves the model sees the same
- // history, so there is nothing new to say.
+ // rising above the last turn that reported one, or a checkpoint starting inside a tool
+ // loop (which evicts without moving the boundary). Sticky replays stay quiet.
const showsNotice = useAuiState(({ thread }) => {
let previousDropped = 0;
for (const message of thread.messages) {
@@ -7853,9 +7854,9 @@ const AssistantMessage: FC = () => {
| undefined
)?.custom?.contextTruncation as ContextTruncation | undefined;
const dropped = compactionBoundary(value);
- if (dropped > previousDropped) {
+ if (shouldShowCompactionNotice(value, previousDropped)) {
if (message.id === messageId) return true;
- previousDropped = dropped;
+ previousDropped = Math.max(previousDropped, dropped);
} else if (message.id === messageId) {
return false;
}
diff --git a/studio/frontend/src/features/chat/types/api.ts b/studio/frontend/src/features/chat/types/api.ts
index 7060a684c25..2ddbf020dea 100644
--- a/studio/frontend/src/features/chat/types/api.ts
+++ b/studio/frontend/src/features/chat/types/api.ts
@@ -739,6 +739,8 @@ export interface OpenAIChatChunk {
// dropped_messages, so re-sending it after a turn that refit several times cannot advance the
// boundary past the turns actually evicted.
boundary_messages?: number;
+ // True when this fit started a new checkpoint, including within the current tool loop.
+ checkpoint_started?: boolean;
// The text the boundary landed ON, so the count can be re-derived by position: a count is only
// valid against the transcript it was counted on, and deleting an already evicted prompt
// shortens that transcript.
diff --git a/studio/frontend/src/features/chat/utils/context-truncation.ts b/studio/frontend/src/features/chat/utils/context-truncation.ts
index 327d36f6372..baa241852ec 100644
--- a/studio/frontend/src/features/chat/utils/context-truncation.ts
+++ b/studio/frontend/src/features/chat/utils/context-truncation.ts
@@ -40,6 +40,18 @@ export function compactionBoundary(
);
}
+/** A saved-transcript boundary can stay put when a tool loop compacts its own messages. */
+export function shouldShowCompactionNotice(
+ truncation: ContextTruncation | undefined,
+ previousBoundary: number,
+): boolean {
+ return (
+ promptWasShortened(truncation) &&
+ (truncation.checkpoint_started === true ||
+ compactionBoundary(truncation) > previousBoundary)
+ );
+}
+
function nonNegativeInt(value: number | undefined): number {
// A propagated NaN would print "NaN tokens on its own" at the user.
return Number.isFinite(value) ? Math.max(0, Math.trunc(value as number)) : 0;
@@ -100,6 +112,15 @@ export function mergeContextTruncation(
...current,
...incoming,
dropped_messages: current.dropped_messages + incoming.dropped_messages,
+ // Sticky: a later replay fit in the same tool loop must not clear it.
+ ...(current.checkpoint_started !== undefined ||
+ incoming.checkpoint_started !== undefined
+ ? {
+ checkpoint_started:
+ current.checkpoint_started === true ||
+ incoming.checkpoint_started === true,
+ }
+ : {}),
prompt_tokens_before:
current.prompt_tokens_before ?? incoming.prompt_tokens_before,
prompt_tokens_after:
diff --git a/studio/frontend/tests/rolling-context-window.test.ts b/studio/frontend/tests/rolling-context-window.test.ts
index c2e95590797..c948cf1b8fd 100644
--- a/studio/frontend/tests/rolling-context-window.test.ts
+++ b/studio/frontend/tests/rolling-context-window.test.ts
@@ -6,6 +6,7 @@ import test from "node:test";
import {
type ContextTruncation,
compactionBoundary,
+ shouldShowCompactionNotice,
mergeContextTruncation,
promptWasShortened,
} from "../src/features/chat/utils/context-truncation.ts";
@@ -192,7 +193,6 @@ test("tool-loop truncation metadata accumulates across stream events", () => {
});
});
-
test("compaction counts accumulate and stay absent on a plain rolling window", () => {
// A plain rolling-window response must keep exactly the shape it had before the
// conversation archive existed, rather than carrying archive keys set to undefined.
@@ -218,13 +218,11 @@ test("the compaction notice renders from persisted metadata, not from a message"
assert.match(COMPACTION_NOTICE, /This conversation got long, so it was compacted/);
});
-test("the compaction notice is gated on the eviction boundary MOVING", () => {
- // Every request after the window fills runs the fit, so "this turn compacted" puts a
- // notice on every reply. The trigger is dropped_messages rising above the last turn
- // that reported it: more of the conversation actually leaving the context.
+test("the compaction notice uses the shared boundary/checkpoint predicate", () => {
+ // Replayed fits stay quiet; a new boundary or checkpoint is a new compaction.
assert.match(THREAD, /const showsNotice = useAuiState/);
assert.match(THREAD, /contextTruncation && showsNotice && !isEditing/);
- assert.match(THREAD, /dropped > previousDropped/);
+ assert.match(THREAD, /shouldShowCompactionNotice\(value, previousDropped\)/);
// Walked in order, not against the preceding message: turns between two moves report
// the same count and must not reset the baseline.
assert.match(THREAD, /for \(const message of thread\.messages\)/);
@@ -237,7 +235,7 @@ const noticeTurns = (dropped: (number | null)[]): number[] => {
let previousDropped = 0;
dropped.forEach((value, index) => {
const d = value ?? 0;
- if (d > previousDropped) {
+ if (shouldShowCompactionNotice({ dropped_messages: d, boundary_messages: d, fits: true }, previousDropped)) {
shown.push(index);
previousDropped = d;
}
@@ -386,3 +384,28 @@ test("the too-long check uses the prompt budget, not the raw window", () => {
// shared floor off the turn first.
assert.match(CHAT_ADAPTER, /latestTurnIsTheProblem\(\s*irreducible,\s*budget,?\s*\)/);
});
+
+test("a checkpoint inside the current tool loop shows a notice without advancing the saved boundary", () => {
+ const recorded = {
+ dropped_messages: 6,
+ boundary_messages: 0,
+ checkpoint_started: true,
+ fits: true,
+ };
+ assert.equal(shouldShowCompactionNotice(recorded, 0), true);
+ assert.equal(shouldShowCompactionNotice({ ...recorded, boundary_messages: 4 }, 4), true);
+ // Sticky replay, with no new checkpoint, must remain quiet.
+ assert.equal(shouldShowCompactionNotice({ ...recorded, checkpoint_started: false }, 0), false);
+ assert.equal(shouldShowCompactionNotice({ ...recorded, dropped_messages: 0 }, 0), false);
+ assert.equal(shouldShowCompactionNotice(undefined, 0), false);
+});
+
+test("later tool-loop fits cannot erase a checkpoint started earlier in the same reply", () => {
+ const merged = mergeContextTruncation(
+ { dropped_messages: 6, boundary_messages: 0, checkpoint_started: true, fits: true },
+ { dropped_messages: 0, boundary_messages: 0, checkpoint_started: false, fits: true },
+ );
+ assert.equal(merged.checkpoint_started, true);
+ assert.equal(shouldShowCompactionNotice(merged, 0), true);
+ assert.equal(shouldShowCompactionNotice({ ...merged, checkpoint_started: false }, 0), false);
+});