The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(chat): say when a turn is summarizing earlier conversation
Sanil40c64bf99ee0
diff --git a/app/src/features/conversations/aui/AgentRunningStatus.test.tsx b/app/src/features/conversations/aui/AgentRunningStatus.test.tsxindex 6e04f8359e..6cef2abe59 100644--- a/app/src/features/conversations/aui/AgentRunningStatus.test.tsx+++ b/app/src/features/conversations/aui/AgentRunningStatus.test.tsx@@ -105,6 +105,30 @@ describe('AgentRunningStatus waiting states', () => {});});+describe('AgentRunningStatus while compacting', () => {+ it('says it is summarizing earlier conversation instead of thinking', () => {+ renderStatus({+ inferenceStatusByThread: {+ [THREAD_ID]: { phase: 'compacting', iteration: 1, maxIterations: 0 },+ },+ });+ expect(screen.getByTestId('agent-running-status-thinking')).toHaveTextContent(+ 'Summarizing earlier conversation'+ );+ });++ it('thinks again once the next model call starts', () => {+ renderStatus({+ inferenceStatusByThread: {+ [THREAD_ID]: { phase: 'thinking', iteration: 1, maxIterations: 0 },+ },+ });+ expect(screen.getByTestId('agent-running-status-thinking')).not.toHaveTextContent(+ 'Summarizing'+ );+ });+});+describe('waitingOnUser', () => {it('ranks approval over review over answer', () => {expect(waitingOnUser({ approval: true, review: true, answer: true })).toBe('approval');diff --git a/app/src/features/conversations/aui/AgentRunningStatus.tsx b/app/src/features/conversations/aui/AgentRunningStatus.tsxindex f89c5ef3e5..84f30d66aa 100644--- a/app/src/features/conversations/aui/AgentRunningStatus.tsx+++ b/app/src/features/conversations/aui/AgentRunningStatus.tsx@@ -27,6 +27,9 @@* 3. **Thinking.** The vendored `GenerationLoader`, with "Thinking · {elapsed}"* once a second has passed. The clock starts when this slot mounts, which is* when the turn starts running: the runtime keeps no turn-start timestamp.+ * While the turn summarizes earlier conversation before its next model call+ * (`inferenceStatusByThread.phase === 'compacting'`), the same loader says+ * so instead: that can take minutes with nothing else to show.*/import { useAuiState } from '@assistant-ui/react';import { useEffect, useState } from 'react';@@ -140,6 +143,14 @@ function useParentWaitsOnSubagents(): boolean {);}+/** Whether the turn is summarizing earlier conversation before its next call. */+function useCompacting(): boolean {+ const threadId = useAuiThreadId();+ return useAppSelector(state =>+ threadId ? state.chatRuntime.inferenceStatusByThread?.[threadId]?.phase === 'compacting' : false+ );+}+function WaitingLine({ kind }: { kind: WaitingOnUser }) {const { t } = useT();return (@@ -163,6 +174,7 @@ export function AgentRunningStatus() {const strings = useAgentStatusStrings();const waiting = useWaitingOnUser();const parentWaits = useParentWaitsOnSubagents();+ const compacting = useCompacting();const [tick, setTick] = useState(0);const [startedAt] = useState(() => Date.now());const turnTasks = useAuiState(s => turnHasTasks(s.thread.tasks, s.thread.messages));@@ -178,9 +190,14 @@ export function AgentRunningStatus() {if (waiting !== null) return <WaitingLine kind={waiting} />;if (!turnTasks) {- const label =- elapsedMs !== undefined && elapsedMs >= 1000- ? t('chat.status.thinkingElapsed').replace('{elapsed}', formatElapsed(elapsedMs))+ const elapsed =+ elapsedMs !== undefined && elapsedMs >= 1000 ? formatElapsed(elapsedMs) : undefined;+ const label = compacting+ ? elapsed+ ? t('chat.status.compactingElapsed').replace('{elapsed}', elapsed)+ : t('chat.status.compacting')+ : elapsed+ ? t('chat.status.thinkingElapsed').replace('{elapsed}', elapsed): t('chat.thinkingDots');return (<GenerationLoaderdiff --git a/app/src/lib/i18n/ar.ts b/app/src/lib/i18n/ar.tsindex 1e05070734..9c2d6d26aa 100644--- a/app/src/lib/i18n/ar.ts+++ b/app/src/lib/i18n/ar.ts@@ -1271,6 +1271,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'فشل تحميل الرسائل','chat.thinkingDots': 'جارٍ التفكير...','chat.status.thinkingElapsed': 'جارٍ التفكير · {elapsed}',+ 'chat.status.compacting': 'جارٍ تلخيص المحادثة السابقة…',+ 'chat.status.compactingElapsed': 'جارٍ تلخيص المحادثة السابقة · {elapsed}','chat.status.waitingApproval': 'في انتظار موافقتك','chat.status.waitingReview': 'في انتظار مراجعتك','chat.status.waitingAnswer': 'في انتظار إجابتك',diff --git a/app/src/lib/i18n/bn.ts b/app/src/lib/i18n/bn.tsindex 99ce16245c..853554fb7e 100644--- a/app/src/lib/i18n/bn.ts+++ b/app/src/lib/i18n/bn.ts@@ -1290,6 +1290,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'বার্তা লোড করতে ব্যর্থ','chat.thinkingDots': 'ভাবছে...','chat.status.thinkingElapsed': 'ভাবছে · {elapsed}',+ 'chat.status.compacting': 'আগের কথোপকথনের সারাংশ তৈরি হচ্ছে…',+ 'chat.status.compactingElapsed': 'আগের কথোপকথনের সারাংশ তৈরি হচ্ছে · {elapsed}','chat.status.waitingApproval': 'আপনার অনুমোদনের অপেক্ষায়','chat.status.waitingReview': 'আপনার পর্যালোচনার অপেক্ষায়','chat.status.waitingAnswer': 'আপনার উত্তরের অপেক্ষায়',diff --git a/app/src/lib/i18n/de.ts b/app/src/lib/i18n/de.tsindex 70b0976f88..02a418c80b 100644--- a/app/src/lib/i18n/de.ts+++ b/app/src/lib/i18n/de.ts@@ -1331,6 +1331,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'Nachrichten konnten nicht geladen werden','chat.thinkingDots': 'Denken...','chat.status.thinkingElapsed': 'Denkt nach · {elapsed}',+ 'chat.status.compacting': 'Fasse den bisherigen Verlauf zusammen…',+ 'chat.status.compactingElapsed': 'Fasse den bisherigen Verlauf zusammen · {elapsed}','chat.status.waitingApproval': 'Wartet auf deine Freigabe','chat.status.waitingReview': 'Wartet auf deine Prüfung','chat.status.waitingAnswer': 'Wartet auf deine Antwort',diff --git a/app/src/lib/i18n/en.ts b/app/src/lib/i18n/en.tsindex aecf1dd492..2a8d76d251 100644--- a/app/src/lib/i18n/en.ts+++ b/app/src/lib/i18n/en.ts@@ -1488,6 +1488,8 @@ const en: TranslationMap = {'chat.failedToLoadMessages': 'Failed to load messages','chat.thinkingDots': 'Thinking...','chat.status.thinkingElapsed': 'Thinking · {elapsed}',+ 'chat.status.compacting': 'Summarizing earlier conversation…',+ 'chat.status.compactingElapsed': 'Summarizing earlier conversation · {elapsed}','chat.status.waitingApproval': 'Waiting for your approval','chat.status.waitingReview': 'Waiting for your review','chat.status.waitingAnswer': 'Waiting for your answer',diff --git a/app/src/lib/i18n/es.ts b/app/src/lib/i18n/es.tsindex d44075ce46..f59e3901a5 100644--- a/app/src/lib/i18n/es.ts+++ b/app/src/lib/i18n/es.ts@@ -1322,6 +1322,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'No se pudieron cargar los mensajes','chat.thinkingDots': 'Pensando...','chat.status.thinkingElapsed': 'Pensando · {elapsed}',+ 'chat.status.compacting': 'Resumiendo la conversación anterior…',+ 'chat.status.compactingElapsed': 'Resumiendo la conversación anterior · {elapsed}','chat.status.waitingApproval': 'Esperando tu aprobación','chat.status.waitingReview': 'Esperando tu revisión','chat.status.waitingAnswer': 'Esperando tu respuesta',diff --git a/app/src/lib/i18n/fr.ts b/app/src/lib/i18n/fr.tsindex 8ec019a85f..9da53a8290 100644--- a/app/src/lib/i18n/fr.ts+++ b/app/src/lib/i18n/fr.ts@@ -1330,6 +1330,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'Échec du chargement des messages','chat.thinkingDots': 'Réflexion…','chat.status.thinkingElapsed': 'Réflexion · {elapsed}',+ 'chat.status.compacting': 'Résumé de la conversation précédente…',+ 'chat.status.compactingElapsed': 'Résumé de la conversation précédente · {elapsed}','chat.status.waitingApproval': 'En attente de votre approbation','chat.status.waitingReview': 'En attente de votre relecture','chat.status.waitingAnswer': 'En attente de votre réponse',diff --git a/app/src/lib/i18n/hi.ts b/app/src/lib/i18n/hi.tsindex f079c1c5e7..397f08e6a0 100644--- a/app/src/lib/i18n/hi.ts+++ b/app/src/lib/i18n/hi.ts@@ -1298,6 +1298,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'मैसेज लोड नहीं हो पाए','chat.thinkingDots': 'सोच रहा है...','chat.status.thinkingElapsed': 'सोच रहा है · {elapsed}',+ 'chat.status.compacting': 'पिछली बातचीत का सारांश बना रहा है…',+ 'chat.status.compactingElapsed': 'पिछली बातचीत का सारांश बना रहा है · {elapsed}','chat.status.waitingApproval': 'आपकी स्वीकृति की प्रतीक्षा','chat.status.waitingReview': 'आपकी समीक्षा की प्रतीक्षा','chat.status.waitingAnswer': 'आपके उत्तर की प्रतीक्षा',diff --git a/app/src/lib/i18n/id.ts b/app/src/lib/i18n/id.tsindex 75f639880b..15ced87273 100644--- a/app/src/lib/i18n/id.ts+++ b/app/src/lib/i18n/id.ts@@ -1308,6 +1308,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'Gagal memuat pesan','chat.thinkingDots': 'Berpikir...','chat.status.thinkingElapsed': 'Berpikir · {elapsed}',+ 'chat.status.compacting': 'Meringkas percakapan sebelumnya…',+ 'chat.status.compactingElapsed': 'Meringkas percakapan sebelumnya · {elapsed}','chat.status.waitingApproval': 'Menunggu persetujuan Anda','chat.status.waitingReview': 'Menunggu tinjauan Anda','chat.status.waitingAnswer': 'Menunggu jawaban Anda',diff --git a/app/src/lib/i18n/it.ts b/app/src/lib/i18n/it.tsindex 74225b8b78..983f43fcd2 100644--- a/app/src/lib/i18n/it.ts+++ b/app/src/lib/i18n/it.ts@@ -1318,6 +1318,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'Impossibile caricare i messaggi','chat.thinkingDots': 'Sto pensando...','chat.status.thinkingElapsed': 'Sto pensando · {elapsed}',+ 'chat.status.compacting': 'Riassumo la conversazione precedente…',+ 'chat.status.compactingElapsed': 'Riassumo la conversazione precedente · {elapsed}','chat.status.waitingApproval': 'In attesa della tua approvazione','chat.status.waitingReview': 'In attesa della tua revisione','chat.status.waitingAnswer': 'In attesa della tua risposta',diff --git a/app/src/lib/i18n/ja.ts b/app/src/lib/i18n/ja.tsindex 2a06d07cd3..552c63e898 100644--- a/app/src/lib/i18n/ja.ts+++ b/app/src/lib/i18n/ja.ts@@ -1481,6 +1481,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'メッセージの読み込みに失敗しました','chat.thinkingDots': '思考中...','chat.status.thinkingElapsed': '思考中 · {elapsed}',+ 'chat.status.compacting': 'これまでの会話を要約中…',+ 'chat.status.compactingElapsed': 'これまでの会話を要約中 · {elapsed}','chat.status.waitingApproval': '承認を待っています','chat.status.waitingReview': 'レビューを待っています','chat.status.waitingAnswer': '回答を待っています',diff --git a/app/src/lib/i18n/ko.ts b/app/src/lib/i18n/ko.tsindex ffbcd85798..790b79160b 100644--- a/app/src/lib/i18n/ko.ts+++ b/app/src/lib/i18n/ko.ts@@ -1278,6 +1278,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': '메시지를 불러오지 못했습니다','chat.thinkingDots': '생각 중...','chat.status.thinkingElapsed': '생각 중 · {elapsed}',+ 'chat.status.compacting': '이전 대화를 요약하는 중…',+ 'chat.status.compactingElapsed': '이전 대화를 요약하는 중 · {elapsed}','chat.status.waitingApproval': '승인을 기다리는 중','chat.status.waitingReview': '검토를 기다리는 중','chat.status.waitingAnswer': '답변을 기다리는 중',diff --git a/app/src/lib/i18n/pl.ts b/app/src/lib/i18n/pl.tsindex 76cc901c21..84e0ce5643 100644--- a/app/src/lib/i18n/pl.ts+++ b/app/src/lib/i18n/pl.ts@@ -1310,6 +1310,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'Nie udało się wczytać wiadomości','chat.thinkingDots': 'Myślę...','chat.status.thinkingElapsed': 'Myślę · {elapsed}',+ 'chat.status.compacting': 'Podsumowuję wcześniejszą rozmowę…',+ 'chat.status.compactingElapsed': 'Podsumowuję wcześniejszą rozmowę · {elapsed}','chat.status.waitingApproval': 'Czeka na Twoją zgodę','chat.status.waitingReview': 'Czeka na Twoją ocenę','chat.status.waitingAnswer': 'Czeka na Twoją odpowiedź',diff --git a/app/src/lib/i18n/pt.ts b/app/src/lib/i18n/pt.tsindex 3f58e7beaa..1502f956ee 100644--- a/app/src/lib/i18n/pt.ts+++ b/app/src/lib/i18n/pt.ts@@ -1317,6 +1317,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'Falha ao carregar mensagens','chat.thinkingDots': 'Pensando...','chat.status.thinkingElapsed': 'Pensando · {elapsed}',+ 'chat.status.compacting': 'Resumindo a conversa anterior…',+ 'chat.status.compactingElapsed': 'Resumindo a conversa anterior · {elapsed}','chat.status.waitingApproval': 'Aguardando sua aprovação','chat.status.waitingReview': 'Aguardando sua revisão','chat.status.waitingAnswer': 'Aguardando sua resposta',diff --git a/app/src/lib/i18n/ru.ts b/app/src/lib/i18n/ru.tsindex ea925b7a4a..e18439dbc4 100644--- a/app/src/lib/i18n/ru.ts+++ b/app/src/lib/i18n/ru.ts@@ -1305,6 +1305,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': 'Не удалось загрузить сообщения','chat.thinkingDots': 'Думаю...','chat.status.thinkingElapsed': 'Думаю · {elapsed}',+ 'chat.status.compacting': 'Резюмирую предыдущий разговор…',+ 'chat.status.compactingElapsed': 'Резюмирую предыдущий разговор · {elapsed}','chat.status.waitingApproval': 'Ожидает вашего одобрения','chat.status.waitingReview': 'Ожидает вашей проверки','chat.status.waitingAnswer': 'Ожидает вашего ответа',diff --git a/app/src/lib/i18n/tr.ts b/app/src/lib/i18n/tr.tsindex 7a333124cd..0dc6df510f 100644--- a/app/src/lib/i18n/tr.ts+++ b/app/src/lib/i18n/tr.ts@@ -4208,6 +4208,8 @@ const messages: TranslationMap = {'memoryPage.import.progress': '{imported}/{total} öğe içe aktarıldı',// Chat status, history, and tool activity.'chat.status.thinkingElapsed': 'Düşünüyor · {elapsed}',+ 'chat.status.compacting': 'Önceki konuşma özetleniyor…',+ 'chat.status.compactingElapsed': 'Önceki konuşma özetleniyor · {elapsed}','chat.status.waitingApproval': 'Onayınız bekleniyor','chat.status.waitingReview': 'İncelemeniz bekleniyor','chat.status.waitingAnswer': 'Yanıtınız bekleniyor',diff --git a/app/src/lib/i18n/zh-CN.ts b/app/src/lib/i18n/zh-CN.tsindex c72b7850bf..0f201405aa 100644--- a/app/src/lib/i18n/zh-CN.ts+++ b/app/src/lib/i18n/zh-CN.ts@@ -1212,6 +1212,8 @@ const messages: TranslationMap = {'chat.failedToLoadMessages': '加载消息失败','chat.thinkingDots': '思考中...','chat.status.thinkingElapsed': '思考中 · {elapsed}',+ 'chat.status.compacting': '正在总结之前的对话…',+ 'chat.status.compactingElapsed': '正在总结之前的对话 · {elapsed}','chat.status.waitingApproval': '等待你的批准','chat.status.waitingReview': '等待你的审阅','chat.status.waitingAnswer': '等待你的回答',diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsxindex 0f3df67f70..09b0775229 100644--- a/app/src/providers/ChatRuntimeProvider.tsx+++ b/app/src/providers/ChatRuntimeProvider.tsx@@ -19,6 +19,7 @@ import {type ChatApprovalDecidedEvent,type ChatApprovalRequestEvent,type ChatCancelledEvent,+ type ChatContextCompactingEvent,type ChatDoneEvent,type ChatErrorEvent,type ChatEventListeners,@@ -852,6 +853,25 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {}));},+ onContextCompacting: (event: ChatContextCompactingEvent) => {+ rtLog('context_compacting', { thread: event.thread_id, request: event.request_id });+ // A parallel branch's compaction is its own; the thread's status+ // line describes the primary turn.+ if (store.getState().chatRuntime.parallelRequestThreads[event.request_id] !== undefined) {+ return;+ }+ const prev = store.getState().chatRuntime.inferenceStatusByThread[event.thread_id];+ dispatch(+ setInferenceStatusForThread({+ threadId: event.thread_id,+ status: {+ phase: 'compacting',+ iteration: event.round,+ maxIterations: prev?.maxIterations ?? 0,+ },+ })+ );+ },onToolCall: (event: ChatToolCallEvent) => {const prev = store.getState().chatRuntime.inferenceStatusByThread[event.thread_id];dispatch(diff --git a/app/src/services/__tests__/chatService.test.ts b/app/src/services/__tests__/chatService.test.tsindex 831225c636..7e75fd3410 100644--- a/app/src/services/__tests__/chatService.test.ts+++ b/app/src/services/__tests__/chatService.test.ts@@ -117,6 +117,19 @@ describe('chatService.subscribeChatEvents', () => {// listener interface unchanged. Without this coverage the parent// thread's live subagent block silently goes blank if a future// refactor renames a socket event.+ it('forwards context_compacting to its listener', () => {+ const socket = createMockSocket();+ bindMockSocket(socket);+ const onContextCompacting = vi.fn();++ subscribeChatEvents({ onContextCompacting });++ expect(socket.on.mock.calls.map(call => call[0])).toEqual(['context_compacting']);+ const event = { thread_id: 't', request_id: 'r', round: 1 };+ socket.emit('context_compacting', event);+ expect(onContextCompacting).toHaveBeenCalledWith(event);+ });+it('subscribes and forwards live subagent events under canonical names', () => {const socket = createMockSocket();bindMockSocket(socket);diff --git a/app/src/services/chatService.ts b/app/src/services/chatService.tsindex a1490ed903..1b4d97e82e 100644--- a/app/src/services/chatService.ts+++ b/app/src/services/chatService.ts@@ -608,6 +608,17 @@ export interface ChatIterationStartEvent {message: string;}+/**+ * Emitted when the turn starts summarizing earlier conversation to fit the+ * context window. The next `iteration_start` ends it.+ */+export interface ChatContextCompactingEvent {+ thread_id: string;+ request_id: string;+ /** The iteration whose model call waits on the summary. */+ round: number;+}+/** Emitted when a sub-agent is spawned during tool execution. */export interface ChatSubagentSpawnedEvent {thread_id: string;@@ -870,6 +881,7 @@ export interface ChatEventListeners {onInferenceStart?: (event: ChatInferenceStartEvent) => void;onInferenceHeartbeat?: (event: ChatInferenceHeartbeatEvent) => void;onIterationStart?: (event: ChatIterationStartEvent) => void;+ onContextCompacting?: (event: ChatContextCompactingEvent) => void;onToolCall?: (event: ChatToolCallEvent) => void;onToolResult?: (event: ChatToolResultEvent) => void;onSubagentSpawned?: (event: ChatSubagentSpawnedEventV2) => void;@@ -922,6 +934,7 @@ export function subscribeChatEvents(listeners: ChatEventListeners): () => void {inferenceStart: 'inference_start',inferenceHeartbeat: 'inference_heartbeat',iterationStart: 'iteration_start',+ contextCompacting: 'context_compacting',toolCall: 'tool_call',toolResult: 'tool_result',subagentSpawned: 'subagent_spawned',@@ -996,6 +1009,22 @@ export function subscribeChatEvents(listeners: ChatEventListeners): () => void {handlers.push([EVENTS.iterationStart, cb]);}+ if (listeners.onContextCompacting) {+ const cb = (payload: unknown) => {+ const e = payload as ChatContextCompactingEvent;+ chatLog(+ '%s thread_id=%s request_id=%s round=%d',+ EVENTS.contextCompacting,+ e.thread_id,+ e.request_id,+ e.round+ );+ listeners.onContextCompacting?.(e);+ };+ socket.on(EVENTS.contextCompacting, cb);+ handlers.push([EVENTS.contextCompacting, cb]);+ }+if (listeners.onToolCall) {const cb = (payload: unknown) => {const e = payload as ChatToolCallEvent;diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.tsindex dcf385a32b..ca4b043d0e 100644--- a/app/src/store/chatRuntimeSlice.ts+++ b/app/src/store/chatRuntimeSlice.ts@@ -88,7 +88,8 @@ export function selectSubagentChildrenByParentCallId(/** Live progress of the running turn, as the socket handlers maintain it. */export interface InferenceStatus {- phase: 'thinking' | 'tool_use' | 'subagent';+ /** `compacting`: summarizing earlier conversation before the next model call. */+ phase: 'thinking' | 'compacting' | 'tool_use' | 'subagent';iteration: number;maxIterations: number;activeTool?: string;diff --git a/crates/openhuman-core/src/agent/tinyagents/context_wiring.rs b/crates/openhuman-core/src/agent/tinyagents/context_wiring.rsindex 2ee8e89f85..7689dc0eb0 100644--- a/crates/openhuman-core/src/agent/tinyagents/context_wiring.rs+++ b/crates/openhuman-core/src/agent/tinyagents/context_wiring.rs@@ -6,6 +6,7 @@use std::sync::Arc;+use async_trait::async_trait;use tinyagents_harness::middleware::{compression_policy, legacy_max_input_tokens, microcompact_for_window, split_input_allowance,ArtifactIndexTocMiddleware, CapturedOutcomes, ContextCompressionMiddleware, ContextLadder,@@ -13,9 +14,10 @@ use tinyagents_harness::middleware::{};use tinyagents_harness::runtime::AgentHarness;use tinyagents_harness::summarization::{- FaultTolerantCachingSummarizer, ModelSummarizer, SummarizationPolicy, TaskStateSummarizer,- DEFAULT_TASK_STATE_CHUNK_TOKENS,+ FaultTolerantCachingSummarizer, ModelSummarizer, SummarizationPolicy, Summarizer,+ SummaryRecord, SummaryRequest, TaskStateSummarizer, DEFAULT_TASK_STATE_CHUNK_TOKENS,};+use tinyinference_llm::message::Message;use crate::agent::tinyagents::host::OpenHumanRunContext;use crate::agent::tinyagents::memory_summarizer::MemoryRecallSummarizer;@@ -31,6 +33,51 @@ const TASK_STATE_KEEP_RECENT_TOKENS: u64 = 20_000;const ARTIFACT_INDEX_STORE: &str =crate::agent::harness::tool_result_artifacts::TINYAGENTS_TOOL_RESULT_ARTIFACT_STORE;+/// Called when the turn starts summarizing earlier conversation.+pub(super) type CompactionNotice = Arc<dyn Fn() + Send + Sync>;++/// A summarizer that reports each summarization before it runs, so the client+/// can say what a turn is doing while a long compaction holds its next model+/// call. It sits under the cache, so a cached summary is not reported.+struct AnnouncingSummarizer {+ inner: Box<dyn Summarizer>,+ notice: CompactionNotice,+}++#[async_trait]+impl Summarizer for AnnouncingSummarizer {+ async fn summarize(+ &self,+ messages: &[Message],+ ) -> tinyagents_harness::error::Result<SummaryRecord> {+ (self.notice)();+ self.inner.summarize(messages).await+ }++ async fn summarize_request(+ &self,+ request: &SummaryRequest,+ ) -> tinyagents_harness::error::Result<SummaryRecord> {+ (self.notice)();+ self.inner.summarize_request(request).await+ }++ async fn merge(+ &self,+ summaries: &[SummaryRecord],+ ) -> tinyagents_harness::error::Result<SummaryRecord> {+ self.inner.merge(summaries).await+ }+}++/// `inner`, reporting each summarization to `notice` when there is one.+fn announced(inner: Box<dyn Summarizer>, notice: Option<CompactionNotice>) -> Box<dyn Summarizer> {+ match notice {+ Some(notice) => Box::new(AnnouncingSummarizer { inner, notice }),+ None => inner,+ }+}+/// Read side of the tool-outcome capture sink, for the wrap-up's restoration.pub(super) struct OutcomeSinkSource(pub(super) ToolOutcomeSink);@@ -60,6 +107,7 @@ pub(super) fn install_context_ladder(wrap_up_at_cap: bool,tool_outcome_sink: &ToolOutcomeSink,memory_turn: Option<Arc<crate::memory::lifecycle::hooks::MemoryTurn>>,+ compaction_notice: Option<CompactionNotice>,) -> (Option<Arc<ContextCompressionMiddleware>>,Option<Arc<FinalCallWrapUpMiddleware>>,@@ -76,6 +124,7 @@ pub(super) fn install_context_ladder(summarizer_model,model,memory_turn,+ compaction_notice,))});// One allowance split between the contents list and wrap-up restoration.@@ -126,6 +175,7 @@ fn compression_middleware(summarizer_model: TurnChatModel,model: &str,memory_turn: Option<Arc<crate::memory::lifecycle::hooks::MemoryTurn>>,+ compaction_notice: Option<CompactionNotice>,) -> ContextCompressionMiddleware {let window = context_window.filter(|w| *w > 0);match strategy {@@ -138,8 +188,12 @@ fn compression_middleware(});tracing::info!(model, keep_recent_tokens = keep_recent, max_chunk_tokens = chunk, context_window = ?window, "[context_compression] strategy=task_state");let summarizer = FaultTolerantCachingSummarizer::new(- Box::new(- TaskStateSummarizer::new(summarizer_model, model).with_max_chunk_tokens(chunk),+ announced(+ Box::new(+ TaskStateSummarizer::new(summarizer_model, model)+ .with_max_chunk_tokens(chunk),+ ),+ compaction_notice,),&policy,);@@ -152,7 +206,10 @@ fn compression_middleware(crate::config::CompactionStrategy::Summary => {tracing::info!(model, "[context_compression] strategy=summary");let summarizer = FaultTolerantCachingSummarizer::new(- Box::new(ModelSummarizer::new(summarizer_model, model)),+ announced(+ Box::new(ModelSummarizer::new(summarizer_model, model)),+ compaction_notice,+ ),&policy,);ContextCompressionMiddleware::with_summarizer(diff --git a/crates/openhuman-core/src/agent/tinyagents/context_wiring_tests.rs b/crates/openhuman-core/src/agent/tinyagents/context_wiring_tests.rsindex 44f05b5174..533148f39d 100644--- a/crates/openhuman-core/src/agent/tinyagents/context_wiring_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/context_wiring_tests.rs@@ -21,3 +21,54 @@ fn outcome_source_returns_captured_content_by_call_id() {fn budget_notice_thresholds_stay_at_half_and_eighty_percent() {assert_eq!(BUDGET_NOTICE_THRESHOLDS, [0.5, 0.8]);}++/// Records each call it gets, then fails: the tests read the order only.+struct RecordingSummarizer(Arc<std::sync::Mutex<Vec<&'static str>>>);++#[async_trait]+impl Summarizer for RecordingSummarizer {+ async fn summarize(&self, _: &[Message]) -> tinyagents_harness::error::Result<SummaryRecord> {+ self.0.lock().unwrap().push("summarize");+ Err(tinyagents_harness::error::TinyAgentsError::Model(+ "stub".into(),+ ))+ }++ async fn merge(&self, _: &[SummaryRecord]) -> tinyagents_harness::error::Result<SummaryRecord> {+ self.0.lock().unwrap().push("merge");+ Err(tinyagents_harness::error::TinyAgentsError::Model(+ "stub".into(),+ ))+ }+}++fn recording() -> (+ Arc<std::sync::Mutex<Vec<&'static str>>>,+ Box<dyn Summarizer>,+) {+ let calls = Arc::new(std::sync::Mutex::new(Vec::new()));+ let notice_calls = calls.clone();+ let notice: CompactionNotice = Arc::new(move || notice_calls.lock().unwrap().push("notice"));+ let summarizer = announced(Box::new(RecordingSummarizer(calls.clone())), Some(notice));+ (calls, summarizer)+}++#[tokio::test]+async fn a_summarization_is_announced_before_it_runs() {+ let (calls, summarizer) = recording();+ let _ = summarizer.summarize(&[]).await;+ let _ = summarizer+ .summarize_request(&SummaryRequest::new(Vec::new()))+ .await;+ assert_eq!(+ *calls.lock().unwrap(),+ ["notice", "summarize", "notice", "summarize"]+ );+}++#[tokio::test]+async fn merging_summaries_is_not_announced_again() {+ let (calls, summarizer) = recording();+ let _ = summarizer.merge(&[]).await;+ assert_eq!(*calls.lock().unwrap(), ["merge"]);+}diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rsindex c67bb0fbf7..6180be2c52 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs@@ -318,6 +318,14 @@ impl OpenhumanEventBridge {}}+ /// Tell the client the turn is summarizing earlier conversation. Only a+ /// top-level turn reports it: a subagent's compaction is not the turn's.+ pub(crate) fn announce_compaction(&self) {+ if self.scope.is_none() {+ self.send(AgentProgress::ContextCompacting);+ }+ }+pub(super) fn iteration(&self) -> u32 {self.cursor.load(Ordering::SeqCst)}diff --git a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rsindex 5998a425c2..d113168b98 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs@@ -141,7 +141,11 @@ async fn the_top_level_run_announces_the_turn_once_and_first() {});}assert_eq!(kinds.first(), Some(&"turn"), "{kinds:?}");- assert_eq!(kinds.iter().filter(|k| **k == "turn").count(), 1, "{kinds:?}");+ assert_eq!(+ kinds.iter().filter(|k| **k == "turn").count(),+ 1,+ "{kinds:?}"+ );}#[tokio::test]@@ -743,3 +747,34 @@ async fn bridge_forwards_tool_progress_with_a_message() {)]);}++#[tokio::test]+async fn only_a_top_level_turn_announces_its_compaction() {+ let (tx, mut rx) = tokio::sync::mpsc::channel(8);+ OpenhumanEventBridge::new(Some(tx), "mock-model", 10).announce_compaction();+ assert!(matches!(+ rx.try_recv(),+ Ok(AgentProgress::ContextCompacting)+ ));++ let (tx, mut rx) = tokio::sync::mpsc::channel(8);+ OpenhumanEventBridge::with_scope(+ Some(tx),+ "mock-model",+ "custom",+ 10,+ Some(SubagentScope {+ agent_id: "researcher".into(),+ task_id: "t1".into(),+ extended_policy: false,+ }),+ Arc::default(),+ Arc::default(),+ Arc::default(),+ Arc::default(),+ Vec::new(),+ crate::core::runtime::DispatchCtx::unbound(),+ )+ .announce_compaction();+ assert!(rx.try_recv().is_err());+}diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rsindex 0c9bf28448..20a7a57fd9 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs@@ -575,6 +575,10 @@ async fn drive_turn(.map(|parent| {crate::storage::sessions::stores_or_ephemeral(&parent.workspace_dir).kv}),+ compaction_notice: Some({+ let bridge = bridge.clone();+ Arc::new(move || bridge.announce_compaction())+ }),},);if let Some(scope) = run_context.response_shape.clone() {diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rsindex f55bb7d318..0730b4d88b 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs@@ -96,6 +96,9 @@ pub(super) struct TurnMiddlewareInputs {/// plan-order middleware read it. `None` for a turn with no workspace or/// without the `todo` tool.pub(super) todo_store: Option<Arc<dyn tinyagents_harness::store::Store>>,+ /// Called when the turn starts summarizing earlier conversation, so the+ /// client can show it. `None` for a turn nobody watches.+ pub(super) compaction_notice: Option<super::context_wiring::CompactionNotice>,}/// The handles the run loop reads after the drive returns.@@ -147,6 +150,7 @@ pub(super) fn install_turn_middleware(provider_usage_carry,tool_outcome_sink,todo_store,+ compaction_notice,} = inputs;let super::host::HarnessHostPolicy {stop_hooks,@@ -451,6 +455,7 @@ pub(super) fn install_turn_middleware(pause_at_cap && subagent_scope.is_none(),&tool_outcome_sink,memory_turn,+ compaction_notice,);let is_subagent = subagent_scope.is_some();let agent_id = tool_policy.as_ref().map(|p| p.agent_definition_id.as_str());diff --git a/crates/openhuman-core/src/progress.rs b/crates/openhuman-core/src/progress.rsindex 9ed06a59a6..bae59ecf24 100644--- a/crates/openhuman-core/src/progress.rs+++ b/crates/openhuman-core/src/progress.rs@@ -27,6 +27,11 @@ pub enum AgentProgress {max_iterations: u32,},+ /// The turn is summarizing earlier conversation to fit the context window+ /// before its next model call. That call starts with the next+ /// [`Self::IterationStarted`].+ ContextCompacting,+/// The LLM responded and the agent is about to execute a tool.ToolCallStarted {/// Provider-assigned (or synthesised) tool call id that tiesdiff --git a/crates/openhuman-core/src/skills/run_log.rs b/crates/openhuman-core/src/skills/run_log.rsindex 6fcb68c4f0..5fa42dca53 100644--- a/crates/openhuman-core/src/skills/run_log.rs+++ b/crates/openhuman-core/src/skills/run_log.rs@@ -117,6 +117,7 @@ pub fn format_event(ev: &AgentProgress) -> Option<String> {iteration,max_iterations,} => format!("· iteration {iteration}/{max_iterations}"),+ AgentProgress::ContextCompacting => "· summarizing earlier conversation".to_string(),AgentProgress::ToolCallStarted {tool_name,arguments,diff --git a/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs b/crates/openhuman-core/src/threads/turn_state/mirror/observe.rsindex fd2f27e8af..42ef67973b 100644--- a/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs+++ b/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs@@ -470,6 +470,12 @@ impl ObserveProgress for TurnStateMirror {// running, so a flush per beat would buy nothing.false}+ AgentProgress::ContextCompacting => {+ // Live-only (`context_compacting` on the socket): the snapshot's+ // phases come from tinyagents' `TurnPhase`, which has none for+ // it, and the next `IterationStarted` sets the phase anyway.+ false+ }}}}diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rsindex f6f63f689e..9403f3ee5a 100644--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs@@ -475,6 +475,20 @@ pub(crate) fn spawn_progress_bridge(},);}+ AgentProgress::ContextCompacting => {+ publish_seq_stamped(+ &dispatch_ctx,+ &mut emit_seq,+ WebChannelEvent {+ event: "context_compacting".to_string(),+ client_id: client_id.clone(),+ thread_id: thread_id.clone(),+ request_id: request_id.clone(),+ round: Some(round),+ ..Default::default()+ },+ );+ }AgentProgress::ToolCallStarted {call_id,tool_name,diff --git a/crates/openhuman-core/src/web_chat/turn_activity.rs b/crates/openhuman-core/src/web_chat/turn_activity.rsindex 2ebf0dbb03..4ff77b94cc 100644--- a/crates/openhuman-core/src/web_chat/turn_activity.rs+++ b/crates/openhuman-core/src/web_chat/turn_activity.rs@@ -125,6 +125,7 @@ fn step_of(event: &AgentProgress) -> Option<Cow<'static, str>> {Some(match event {AgentProgress::TurnStarted => "the turn started".into(),AgentProgress::IterationStarted { .. } => "a model call started".into(),+ AgentProgress::ContextCompacting => "it began summarizing earlier conversation".into(),AgentProgress::ModelCallCompleted {subagent_task_id: None,..