The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 16:00 UTC
fix(web): manual compaction counts history beyond the loaded page (#25445)
Co-authored-by: jason chien <3936511+jason5545@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Jui-Chen Chien committed
Nov 14, 2026 at 17:06 UTC
3b18dc2935af2f7cb9b7d5ed60594ffc42e0f605
3 files changed
+106
-5
apps/web/src/components/ChatView.logic.test.ts
+81
@@ -61,6 +61,7 @@ import {
61
deriveCommittedServerUserMessageIds,
62
deriveComposerSendState,
63
deriveLockedProvider,
64
+ hasCompactableConversation,
65
hasServerAcknowledgedLocalDispatch,
66
waitForRevertedMessage,
67
} from "./ChatView.logic";
@@ -434,6 +435,86 @@ describe("deriveCommittedServerUserMessageIds", () => {
435
});
436
});
437
438
+describe("hasCompactableConversation", () => {
439
+ const at = DateTime.makeUnsafe("2026-10-26T08:00:00.000Z");
440
+ const runId = RunId.make("run:thread:thread-1:ordinal:1");
441
+ const itemBase = (id: string, ordinal: number) => ({
442
+ id: TurnItemId.make(id),
443
+ threadId,
444
+ runId,
445
+ nodeId: null,
446
+ providerThreadId: null,
447
+ providerTurnId: null,
448
+ nativeItemRef: null,
449
+ parentItemId: null,
450
+ ordinal,
451
+ status: "completed" as const,
452
+ title: null,
453
+ startedAt: at,
454
+ completedAt: at,
455
+ updatedAt: at,
456
+ });
457
+ const userMessage = (text: string): OrchestrationV2ProjectedTurnItem => ({
458
+ position: 0,
459
+ visibility: "local",
460
+ sourceThreadId: threadId,
461
+ sourceItemId: TurnItemId.make("turn-item:user"),
462
+ item: {
463
+ ...itemBase("turn-item:user", 1),
464
+ createdBy: "user",
465
+ creationSource: "web",
466
+ type: "user_message",
467
+ messageId: MessageId.make("message-user"),
468
+ inputIntent: "turn_start",
469
+ text,
470
+ attachments: [],
471
+ },
472
+ });
473
+ const assistantMessage: OrchestrationV2ProjectedTurnItem = {
474
+ position: 1,
475
+ visibility: "local",
476
+ sourceThreadId: threadId,
477
+ sourceItemId: TurnItemId.make("turn-item:assistant"),
478
+ item: {
479
+ ...itemBase("turn-item:assistant", 2),
480
+ type: "assistant_message",
481
+ messageId: MessageId.make("message-assistant"),
482
+ text: "done",
483
+ streaming: false,
484
+ },
485
+ };
486
+
487
+ it("counts a user message beyond the loaded page", () => {
488
+ expect(
489
+ hasCompactableConversation({
490
+ visibleTurnItems: [assistantMessage],
491
+ hasMoreHistory: true,
492
+ latestUserMessageAt: "2026-10-26T08:00:00.000Z",
493
+ }),
494
+ ).toBe(true);
495
+ });
496
+
497
+ it("stays unavailable when the thread never had a user message", () => {
498
+ expect(
499
+ hasCompactableConversation({
500
+ visibleTurnItems: [assistantMessage],
501
+ hasMoreHistory: true,
502
+ latestUserMessageAt: null,
503
+ }),
504
+ ).toBe(false);
505
+ });
506
+
507
+ it("does not count a lone /compact on a fully loaded thread", () => {
508
+ expect(
509
+ hasCompactableConversation({
510
+ visibleTurnItems: [userMessage("/compact"), assistantMessage],
511
+ hasMoreHistory: false,
512
+ latestUserMessageAt: "2026-10-26T08:00:00.000Z",
513
+ }),
514
+ ).toBe(false);
515
+ });
516
+});
517
+
518
describe("resolveThreadSwitchTimeline", () => {
519
afterEach(() => {
520
resetHeldThreadTimeline();
apps/web/src/components/ChatView.logic.ts
+19
@@ -1014,6 +1014,25 @@ export function deriveCommittedServerUserMessageIds(
1014
);
1015
}
1016
1017
+/**
1018
+ * The server checks the full history, but the first page of an
1019
+ * agent-started thread or a long turn can hold no user message.
1020
+ */
1021
+export function hasCompactableConversation(input: {
1022
+ readonly visibleTurnItems: ReadonlyArray<ThreadStructureRow>;
1023
+ readonly hasMoreHistory: boolean;
1024
+ readonly latestUserMessageAt: string | null;
1025
+}): boolean {
1026
+ return (
1027
+ input.visibleTurnItems.some(
1028
+ ({ item }) =>
1029
+ item.type === "user_message" &&
1030
+ (item.text.trim().toLowerCase() !== "/compact" || item.attachments.length > 0),
1031
+ ) ||
1032
+ (input.hasMoreHistory && input.latestUserMessageAt !== null)
1033
+ );
1034
+}
1035
+
1036
export function hasServerAcknowledgedLocalDispatch(input: {
1037
localDispatch: LocalDispatchSnapshot | null;
1038
phase: SessionPhase;
apps/web/src/components/ChatView.tsx
+6
-5
@@ -361,6 +361,7 @@ import {
361
startNewThreadForProject,
362
codexArtifactTemplatePromptToAppend,
363
shouldRefocusComposerOnWindowFocus,
364
+ hasCompactableConversation,
365
} from "./ChatView.logic";
366
import { useLocalStorage } from "~/hooks/useLocalStorage";
367
import { useComposerHandleContext } from "../composerHandleContext";
@@ -2485,11 +2486,11 @@ export default function ChatView(props: ChatViewProps) {
2486
scrollToEnd,
2487
persistThreadSettingsForNextTurn,
2488
});
2488
- const activeThreadHasCompactableConversation = serverVisibleTurnItems.some(
2489
- ({ item }) =>
2490
- item.type === "user_message" &&
2491
- (item.text.trim().toLowerCase() !== "/compact" || item.attachments.length > 0),
2492
- );
2489
+ const activeThreadHasCompactableConversation = hasCompactableConversation({
2490
+ visibleTurnItems: serverVisibleTurnItems,
2491
+ hasMoreHistory: serverThreadHistory.hasMoreHistory,
2492
+ latestUserMessageAt: serverThread?.latestUserMessageAt ?? null,
2493
+ });
2494
const pendingHandoffSelection =
2495
(composerModelSelectionApplies ? composerSelectedModelSelection : null) ??
2496
activeThread?.modelSelection;