The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): room settings offer per-member Compress history for hidden member sessions
teknium15cabfa5d13db
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsxindex c624d766f64..a64c9d3e823 100644--- a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx+++ b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx@@ -72,11 +72,13 @@ import type { GroupChatRoom } from './group-chat'import { GroupClarifyCard, GroupImageControls, GroupMentionInput } from './group-chat-parts'import type { GroupRoomPrompt } from './group-chat-parts'import { GroupMemberPicker } from './group-chat-view-members'+import { compressGroupMemberHistory } from './group-compress'import { GroupHoldStatus } from './group-hold-status'import {botGroups,groupChatMemberBots,groupDisbandMetadataPlan,+ groupMemberKey,groupWorkspaceOwnerKey,liveGroupChatNames} from './group-membership'@@ -379,6 +381,7 @@ function GroupChatSettingsDialog({ group, members, open, onClose, onManageMemberconst current = (rooms[group] || {}).image || nullconst [name, setName] = useState(group)const [image, setImage] = useState(current)+ const [compressing, setCompressing] = useState<null | string>(null)useEffect(() => {if (open) {setName(group)@@ -387,6 +390,36 @@ function GroupChatSettingsDialog({ group, members, open, onClose, onManageMember// eslint-disable-next-line react-hooks/exhaustive-deps}, [open, group])+ // Per-member "Compress history" (#102291): the member's hidden plumbing+ // session is reachable from nowhere else, so the room that shows the+ // symptom (empty replies) owns the repair. One member at a time — the+ // gateway refuses a second compress while one holds the lock.+ const compressMember = async (member: GroupMember) => {+ const memberName = displayName(member, botRosterMeta(member, $botMeta.get()))+ setCompressing(groupMemberKey(member))+ host.notify({ kind: 'info', message: b.group.compressing(memberName) })++ try {+ const outcome = await compressGroupMemberHistory(group, member)++ if (outcome.compressed === 0 && outcome.pending === 0) {+ host.notify({ kind: 'info', message: b.group.compressNothing(memberName) })+ } else {+ host.notify({+ kind: 'success',+ message: b.group.compressDone(memberName, outcome.compressed + outcome.pending, outcome.lines.join('; '))+ })+ }+ } catch (error) {+ host.notify({+ kind: 'error',+ message: b.group.compressFailed(memberName, error instanceof Error ? error.message : String(error))+ })+ } finally {+ setCompressing(null)+ }+ }+const save = async () => {const finalName = await renameGroupChat(group, name, members)@@ -439,6 +472,31 @@ function GroupChatSettingsDialog({ group, members, open, onClose, onManageMembervalue={name}/></form>+ {(members || []).length > 0 ? (+ <ul className="flex flex-col gap-1" data-testid="group-settings-members">+ {(members || []).map(member => {+ const key = groupMemberKey(member)++ return (+ <li className="flex items-center justify-between gap-2 text-sm" key={key}>+ <span className="truncate">{displayName(member, botRosterMeta(member, $botMeta.get()))}</span>+ <Tip label={b.group.compressHistoryHint(member.name)}>+ <Button+ aria-label={`${b.group.compressHistory}: ${member.name}`}+ disabled={compressing !== null}+ onClick={() => void compressMember(member)}+ size="sm"+ variant="secondary"+ >+ <Codicon name={compressing === key ? 'loading' : 'fold'} spinning={compressing === key} />+ {b.group.compressHistory}+ </Button>+ </Tip>+ </li>+ )+ })}+ </ul>+ ) : null}{onManageMembers ? (<ButtonclassName="w-fit"diff --git a/apps/desktop/src/plugins/hermes-bots/group-compress.test.tsx b/apps/desktop/src/plugins/hermes-bots/group-compress.test.tsxnew file mode 100644index 00000000000..c9ce10bebc0--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/group-compress.test.tsx@@ -0,0 +1,148 @@+import { cleanup, fireEvent, render, waitFor } from '@testing-library/react'+import type { ReactNode } from 'react'+import { afterEach, beforeEach, expect, it, vi } from 'vitest'++import { createGroupGateway } from './group-test-utils'+import type { ScriptedGateway } from './group-test-utils'+import { translateBots } from './i18n-test-helper'++// #102291: room member sessions are hidden plumbing nothing else can compress.+// The room settings dialog owns a per-member "Compress history" that resumes+// every session the room holds for that member and runs session.compress on+// the LIVE runtime id — never minting a new session as a side effect.++const { host } = vi.hoisted(() => ({ host: {} as Record<string, unknown> }))+const state = { gateway: null as null | ScriptedGateway }++vi.mock('@hermes/plugin-sdk', async () => {+ const { pluginSdkMock } = await import('./group-test-utils')+ const base = await pluginSdkMock(host)+ const Passthrough = ({ children }: { children?: ReactNode }) => <>{children}</>++ const Button = ({+ children,+ disabled,+ onClick,+ 'aria-label': label+ }: {+ 'aria-label'?: string+ children?: ReactNode+ disabled?: boolean+ onClick?: () => void+ }) => (+ <button aria-label={label} disabled={disabled} onClick={onClick}>+ {children}+ </button>+ )++ return {+ ...base,+ Button,+ RowButton: Button,+ cn: (...values: unknown[]) => values.filter(Boolean).join(' '),+ Codicon: () => null,+ CopyButton: () => null,+ ConfirmDialog: () => null,+ Dialog: Passthrough,+ DialogContent: Passthrough,+ DialogDescription: Passthrough,+ DialogFooter: Passthrough,+ DialogHeader: Passthrough,+ DialogTitle: Passthrough,+ Input: () => null,+ Tip: Passthrough,+ relativeTime: () => 'now',+ useI18n: () => ({ t: { common: { cancel: 'Cancel', save: 'Save' } } }),+ usePluginI18n: () => translateBots+ }+})+vi.mock('./avatar', () => ({ avatarColor: () => '#888', botAppearance: () => ({}), BotFace: () => null }))+vi.mock('./group-chat-parts', () => ({+ GroupClarifyCard: () => null,+ GroupImageControls: () => null,+ GroupMentionInput: () => null+}))++beforeEach(() => {+ vi.resetModules()+ state.gateway = createGroupGateway()++ for (const key of Object.keys(host)) {+ delete host[key]+ }++ // The scripted gateway answers unknown methods with `{}`; give+ // session.compress the in-process gateway's real result shape.+ const inner = state.gateway.host.request as (method: string, params: Record<string, unknown>) => Promise<unknown>++ state.gateway.host.request = async (method: string, params: Record<string, unknown> = {}) => {+ if (method === 'session.compress') {+ state.gateway!.rpc.push({ method, params, refcountAfter: 0 })++ return { status: 'compressed', before_messages: 1588, after_messages: 134, summary: { headline: '1588 → 134' } }+ }++ return inner(method, params)+ }++ Object.assign(host, state.gateway.host)+})+afterEach(cleanup)++async function seedMemberSession(profile: string, title: string) {+ const request = state.gateway!.host.request as (method: string, params: Record<string, unknown>) => Promise<unknown>+ const created = (await request('session.create', { profile, title, hidden: true })) as { stored_session_id: string }+ state.gateway!.rpc.length = 0++ return created.stored_session_id+}++it('compressGroupMemberHistory resumes each stored session for the member and compresses the live runtime id', async () => {+ const { $groupChats } = await import('./group-chat')+ const { compressGroupMemberHistory } = await import('./group-compress')+ const mason = await seedMemberSession('mason', 'Group: room-1 · t1')+ const critic = await seedMemberSession('critic', 'Group: room-1 · t1')+ $groupChats.set({+ Build: {+ log: [],+ roomId: 'room-1',+ sessions: { 'thread:t1::mason': mason, 'thread:t1::critic': critic },+ watermarks: {}+ }+ })++ const outcome = await compressGroupMemberHistory('Build', { name: 'mason' } as never)++ expect(outcome).toMatchObject({ compressed: 1, pending: 0, skipped: 0, lines: ['1588 → 134'] })+ const methods = state.gateway!.rpc.map(call => call.method)+ expect(methods).toEqual(['session.resume', 'session.compress'])+ const [resume, compress] = state.gateway!.rpc+ expect(resume.params).toMatchObject({ session_id: mason, profile: 'mason', omit_messages: true })+ // The compress targets the runtime id the resume minted, not the stored id.+ expect(compress.params.session_id).toBe(state.gateway!.sessions.get(mason)!.runtime)+ expect(compress.params.session_id).not.toBe(mason)+ expect(methods).not.toContain('session.create')+})++it('the room settings dialog offers Compress history per member and reports the result', async () => {+ Element.prototype.scrollIntoView = vi.fn()+ const { $groupChats } = await import('./group-chat')+ const { GroupChatWorkspace } = await import('./group-chat-view')+ const mason = await seedMemberSession('mason', 'Group: room-1 · t1')+ $groupChats.set({ Build: { log: [], roomId: 'room-1', sessions: { 'thread:t1::mason': mason }, watermarks: {} } })+ const members = [{ name: 'mason' }, { name: 'critic' }] as never++ const { getByLabelText } = render(<GroupChatWorkspace group="Build" members={members} />)+ fireEvent.click(getByLabelText('Group settings for Build'))+ fireEvent.click(getByLabelText('Compress history: mason'))++ await waitFor(() => expect(state.gateway!.rpcFor('session.compress')).toHaveLength(1))+ const notify = state.gateway!.host.notify as ReturnType<typeof vi.fn>+ await waitFor(() =>+ expect(notify.mock.calls.map(([toast]) => (toast as { message: string }).message)).toContain(+ 'Compressed 1 room session for Mason — 1588 → 134'+ )+ )+ // Only mason's session was touched — critic never had one and none was created.+ expect(state.gateway!.rpcFor('session.create')).toHaveLength(0)+})diff --git a/apps/desktop/src/plugins/hermes-bots/group-compress.ts b/apps/desktop/src/plugins/hermes-bots/group-compress.tsnew file mode 100644index 00000000000..13a69818669--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/group-compress.ts@@ -0,0 +1,115 @@+/**+ * Manual compression of a room member's hidden plumbing sessions (#102291).+ *+ * Member sessions (`Group: <roomId> · <thread>`, hidden, room_plumbing) grow+ * with every room drive and are reachable from no other surface: they are+ * excluded from session lists, the focused-chat `/compress` never targets+ * them, and `-q` chat forwards slash text to the model. This is the room+ * settings' "Compress history" action: resume each session the room knows+ * for the member, then run the gateway's `session.compress` against the live+ * runtime id — the same RPC pair the reporter ran by hand over JSON-RPC.+ */++import { $groupChats } from './group-chat'+import { groupMemberKey, groupSessionMemberKey } from './group-membership'+import { requestForBot } from './routing'+import type { GroupMember } from './types'++/** Matches the focused-chat `/compress` budget: the gateway's compute-host+ * wait is legitimately this long, and the socket's 30 s default reports a+ * false timeout while the summary is still committing (#97948). */+const GROUP_SESSION_COMPRESS_TIMEOUT_MS = 660_000++interface GroupSessionCompressResult {+ after_messages?: number+ before_messages?: number+ compressed?: boolean+ message?: string+ status?: string+ summary?: { aborted?: boolean; headline?: string; note?: string }+}++export interface GroupMemberCompressOutcome {+ /** Sessions actually compressed. */+ compressed: number+ /** Human-readable headline per compressed session, e.g. "compressed 1588 → 134 messages". */+ lines: string[]+ /** Sessions the gateway still compresses in the background (`status: pending`). */+ pending: number+ /** Sessions the room knows but the gateway no longer has (4007) or that refused. */+ skipped: number+}++/** Every stored session id the room holds for this member: the thread-scoped+ * pointers plus the pre-thread pointer of a legacy room. The pre-thread title+ * is the last resort for a rehydrated room whose pointer was lost. */+function memberSessionTargets(group: string, member: GroupMember): string[] {+ const room = $groupChats.get()[group] || {}+ const memberKey = groupMemberKey(member)++ const stored = Object.entries(room.sessions || {})+ .filter(([key, value]) => typeof value === 'string' && groupSessionMemberKey(key) === memberKey)+ .map(([, value]) => value as string)++ return stored.length > 0 ? Array.from(new Set(stored)) : [`Group: ${room.roomId || group}`]+}++export async function compressGroupMemberHistory(+ group: string,+ member: GroupMember+): Promise<GroupMemberCompressOutcome> {+ const outcome: GroupMemberCompressOutcome = { compressed: 0, lines: [], pending: 0, skipped: 0 }++ for (const target of memberSessionTargets(group, member)) {+ let runtime: null | string = null++ try {+ const resumed = (await requestForBot(member, 'session.resume', {+ session_id: target,+ profile: member.name,+ omit_messages: true+ })) as { session_id?: string }++ runtime = resumed?.session_id || null+ } catch (error: any) {+ // 4007 = the gateway genuinely has no such session; anything else is a+ // real failure the caller should see.+ if (error?.code !== 4007) {+ throw error+ }+ }++ if (!runtime) {+ outcome.skipped += 1++ continue+ }++ const result = await requestForBot<GroupSessionCompressResult>(+ member,+ 'session.compress',+ { session_id: runtime },+ { timeoutMs: GROUP_SESSION_COMPRESS_TIMEOUT_MS }+ )++ if (result?.status === 'pending') {+ outcome.pending += 1+ } else if (result?.status === 'aborted' || result?.summary?.aborted || result?.compressed === false) {+ outcome.skipped += 1+ } else {+ outcome.compressed += 1++ const headline =+ result?.summary?.headline ||+ (typeof result?.before_messages === 'number' && typeof result?.after_messages === 'number'+ ? `${result.before_messages} → ${result.after_messages} messages`+ : '')++ if (headline) {+ outcome.lines.push(headline)+ }+ }+ }++ return outcome+}diff --git a/apps/desktop/src/plugins/hermes-bots/i18n.ts b/apps/desktop/src/plugins/hermes-bots/i18n.tsindex e92d3a32d7e..70ba32d6b70 100644--- a/apps/desktop/src/plugins/hermes-bots/i18n.ts+++ b/apps/desktop/src/plugins/hermes-bots/i18n.ts@@ -186,6 +186,12 @@ type BotsMessages = {settingsTitle: stringsettingsDesc: stringnameLabel: string+ compressHistory: string+ compressHistoryHint: (member: string) => string+ compressing: (member: string) => string+ compressDone: (member: string, compressed: number, detail: string) => string+ compressNothing: (member: string) => string+ compressFailed: (member: string, error: string) => stringsearchToAdd: stringsearchToAddPlaceholder: stringremoveFromSelection: string@@ -442,6 +448,13 @@ const en: BotsMessages = {settingsTitle: 'Group settings',settingsDesc: 'Rename the group or set a room picture. Members and history are kept.',nameLabel: 'Group name',+ compressHistory: 'Compress history',+ compressHistoryHint: (member: string) => `Compress ${member}'s hidden room history so the member stops failing with empty replies`,+ compressing: (member: string) => `Compressing ${member}'s room history…`,+ compressDone: (member: string, compressed: number, detail: string) =>+ `Compressed ${compressed} room session${compressed === 1 ? '' : 's'} for ${member}${detail ? ` — ${detail}` : ''}`,+ compressNothing: (member: string) => `Nothing to compress for ${member} — no room session yet`,+ compressFailed: (member: string, error: string) => `Could not compress ${member}'s room history: ${error}`,searchToAdd: 'Search bots to add',searchToAddPlaceholder: 'Search bots to add…',removeFromSelection: 'Remove from selection',@@ -690,6 +703,13 @@ const ja: BotsMessages = {settingsTitle: 'グループ設定',settingsDesc: 'グループ名の変更や部屋の画像の設定ができます。メンバーと履歴は保持されます。',nameLabel: 'グループ名',+ compressHistory: '履歴を圧縮',+ compressHistoryHint: (member: string) => `${member} の非表示のルーム履歴を圧縮し、空の応答で失敗しなくなるようにします`,+ compressing: (member: string) => `${member} のルーム履歴を圧縮中…`,+ compressDone: (member: string, compressed: number, detail: string) =>+ `${member} のルームセッション ${compressed} 件を圧縮しました${detail ? ` — ${detail}` : ''}`,+ compressNothing: (member: string) => `${member} に圧縮する履歴はありません — ルームセッションがまだありません`,+ compressFailed: (member: string, error: string) => `${member} のルーム履歴を圧縮できませんでした: ${error}`,searchToAdd: '追加するボットを検索',searchToAddPlaceholder: '追加するボットを検索…',removeFromSelection: '選択から外す',@@ -934,6 +954,13 @@ const zh: BotsMessages = {settingsTitle: '群组设置',settingsDesc: '重命名群组或设置房间图片。成员和历史都会保留。',nameLabel: '群组名称',+ compressHistory: '压缩历史',+ compressHistoryHint: (member: string) => `压缩 ${member} 隐藏的房间历史,避免该成员因空回复而失败`,+ compressing: (member: string) => `正在压缩 ${member} 的房间历史…`,+ compressDone: (member: string, compressed: number, detail: string) =>+ `已压缩 ${member} 的 ${compressed} 个房间会话${detail ? ` — ${detail}` : ''}`,+ compressNothing: (member: string) => `${member} 没有可压缩的历史 — 还没有房间会话`,+ compressFailed: (member: string, error: string) => `无法压缩 ${member} 的房间历史: ${error}`,searchToAdd: '搜索要添加的机器人',searchToAddPlaceholder: '搜索要添加的机器人…',removeFromSelection: '从选择中移除',@@ -1177,6 +1204,13 @@ const zhHant: BotsMessages = {settingsTitle: '群組設定',settingsDesc: '重新命名群組或設定房間圖片。成員和歷史都會保留。',nameLabel: '群組名稱',+ compressHistory: '壓縮歷史',+ compressHistoryHint: (member: string) => `壓縮 ${member} 隱藏的房間歷史,避免該成員因空回覆而失敗`,+ compressing: (member: string) => `正在壓縮 ${member} 的房間歷史…`,+ compressDone: (member: string, compressed: number, detail: string) =>+ `已壓縮 ${member} 的 ${compressed} 個房間會話${detail ? ` — ${detail}` : ''}`,+ compressNothing: (member: string) => `${member} 沒有可壓縮的歷史 — 還沒有房間會話`,+ compressFailed: (member: string, error: string) => `無法壓縮 ${member} 的房間歷史: ${error}`,searchToAdd: '搜尋要加入的機器人',searchToAddPlaceholder: '搜尋要加入的機器人…',removeFromSelection: '從選取中移除',diff --git a/apps/desktop/src/plugins/hermes-bots/routing.ts b/apps/desktop/src/plugins/hermes-bots/routing.tsindex 1f670a6007b..dd431b6c1c1 100644--- a/apps/desktop/src/plugins/hermes-bots/routing.ts+++ b/apps/desktop/src/plugins/hermes-bots/routing.ts@@ -202,6 +202,9 @@ export interface BotRequestOptions {* a cold backend spawn takes the pool's reserved slot; leave unset for* passive roster warming. Only source-scoped routes can carry it. */spawnPriority?: 'background' | 'foreground'+ /** Per-request wait for RPCs that legitimately outlive the socket's 30 s+ * default (session.compress runs an LLM summary); unset keeps the default. */+ timeoutMs?: number}export async function requestForBot<T = unknown>(@@ -223,8 +226,10 @@ export async function requestForBot<T = unknown>(// Keep the three-argument shape when no options were given so older// desktop shells (and the arity-pinning tests) see the same call.return await (options?.spawnPriority- ? host.requestProfile(route, method, routedParams, undefined, { spawnPriority: options.spawnPriority })- : host.requestProfile(route, method, routedParams))+ ? host.requestProfile(route, method, routedParams, options.timeoutMs, { spawnPriority: options.spawnPriority })+ : options?.timeoutMs === undefined+ ? host.requestProfile(route, method, routedParams)+ : host.requestProfile(route, method, routedParams, options.timeoutMs))} catch (error) {// React 19 formats query errors with `(error.name || '').trim()`. IPC /// JSON-RPC rejections are often plain objects whose `name` is a number,@@ -234,7 +239,9 @@ export async function requestForBot<T = unknown>(}try {- return await host.request(method, params)+ return await (options?.timeoutMs === undefined+ ? host.request(method, params)+ : host.request(method, params, options.timeoutMs))} catch (error) {throw asRpcError(error, `Gateway request ${method} failed`)}diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 921c6cd526f..9d345d61fc2 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -1517,15 +1517,17 @@ export const host = {},/** Gateway JSON-RPC — sessions, config, skills, cron, kanban, everything- * the app itself uses. Lazy: resolves the LIVE socket per call. */- request: async <T>(method: string, params: Record<string, unknown> = {}): Promise<T> => {+ * the app itself uses. Lazy: resolves the LIVE socket per call. `timeoutMs`+ * overrides the socket's 30 s default for RPCs that legitimately run longer+ * (session.compress); unset keeps the default. */+ request: async <T>(method: string, params: Record<string, unknown> = {}, timeoutMs?: number): Promise<T> => {const gateway = $gateway.get()if (!gateway) {throw new Error('Hermes gateway unavailable')}- return gateway.request<T>(method, params)+ return timeoutMs === undefined ? gateway.request<T>(method, params) : gateway.request<T>(method, params, timeoutMs)},/** The LIVE gateway instance for the active profile (null before the firstdiff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.mdindex 378a4622f48..25b02e1a753 100644--- a/website/docs/user-guide/bot-mode.md+++ b/website/docs/user-guide/bot-mode.md@@ -125,6 +125,7 @@ A group's identity is editable, at creation and after:- **New Group Chat** lets you set an optional **room picture** alongside the name — upload one from your device or generate one (when an image backend is configured), using the same pipeline as Bot avatars. The picture appears in the roster row (in place of the default group glyph) and leads the title in the room header.- The room header's **gear** button opens **Group settings**, where you can **rename** the group or set, replace, or remove its picture any time. A rename carries everything with it — the room log, each member's room session, memberships, and the picture — so no history is lost. Renaming to a name that's already taken is rejected rather than silently suffixed.+- **Group settings** also lists every member with a **Compress history** button. Each member keeps a hidden per-room session that grows with every turn; when it gets large enough the member starts answering with empty replies (`The model returned no response after processing tool results`). **Compress history** runs the same context compression as `/compress` against that hidden session — it is not reachable from the sidebar or the room composer — and reports how many messages were folded. Compress one member at a time; the room log itself is untouched.Groups are standalone rows in the same activity-ordered roster as Bot DMs. A Bot keeps one DM row even when it belongs to several groups, while every group gets its own room row with member count, latest-message preview, timestamp, and needs-you state.